-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wms_connector: clean view, and simplify code, add cancel check
- Loading branch information
1 parent
e1be055
commit 5021f42
Showing
3 changed files
with
73 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,51 @@ | ||
# Copyright 2023 Akretion | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class StockPicking(models.Model): | ||
_inherit = ["synchronize.exportable.mixin", "stock.picking"] | ||
_name = "stock.picking" | ||
|
||
wms_connector_exported = fields.Boolean( | ||
String="Exported to WMS", | ||
compute="_compute_wms_exported", | ||
readonly=True, | ||
store=True, | ||
) | ||
is_wms_exportable = fields.Boolean( | ||
compute="_compute_is_wms_exportable", readonly=True, store=True | ||
) | ||
wms_sync_cancel_supported = fields.Boolean( | ||
compute="_compute_wms_sync_cancel_supported" | ||
) | ||
|
||
@api.depends("wms_export_attachment") | ||
def _compute_wms_exported(self): | ||
for rec in self: | ||
rec.wms_connector_exported = bool(rec.wms_export_attachment) | ||
def _compute_wms_sync_cancel_supported(self): | ||
self.wms_sync_cancel_supported = False | ||
|
||
@api.depends("picking_type_id.warehouse_id.active_wms_sync") | ||
@api.depends( | ||
"picking_type_id.warehouse_id.active_wms_sync", | ||
"picking_type_id.code", | ||
) | ||
def _compute_is_wms_exportable(self): | ||
for rec in self: | ||
rec.is_wms_exportable = rec.picking_type_id.warehouse_id.active_wms_sync | ||
|
||
def action_show_export(self): | ||
self.ensure_one() | ||
return { | ||
"name": "WMS export", | ||
"type": "ir.actions.act_window", | ||
"res_model": "attachment.queue", | ||
"view_mode": "form", | ||
"res_id": self.wms_export_attachment.id, | ||
} | ||
rec.is_wms_exportable = ( | ||
rec.picking_type_id.warehouse_id.active_wms_sync | ||
and rec.picking_type_id.code in ("incoming", "outgoing") | ||
) | ||
|
||
def action_force_cancel_wms(self): | ||
self.env.user.has_group("stock.group_stock_manager") | ||
return self.with_context(skip_wms_cancel_check=True).action_cancel() | ||
|
||
def action_cancel(self): | ||
for record in self: | ||
if ( | ||
not self._context.get("skip_wms_cancel_check") | ||
and record.wms_export_date | ||
and not record.wms_sync_cancel_supported | ||
): | ||
raise UserError( | ||
_( | ||
"The picking %s can not be deleted as it have been sent " | ||
"to the WMS, ask your manager to force the cancellation" | ||
) | ||
% record.name | ||
) | ||
return super().action_cancel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters