Skip to content

Commit 68846e5

Browse files
committed
despatch_advice_import: fix processing
- Fix cancellation of backorder moves with stock_picking_restrict_cancel_printed module - Always skip backorder wizard when validating the picking - Don't call validate when all moves are canceled
1 parent 856623c commit 68846e5

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

despatch_advice_import/__manifest__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"version": "16.0.1.2.0",
99
"website": "https://github.com/OCA/edi",
1010
"license": "AGPL-3",
11-
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
11+
"author": "ACSONE SA/NV,BCIM,Odoo Community Association (OCA)",
12+
"maintainers": ["jbaudoux"],
1213
"depends": ["purchase", "purchase_stock", "base_business_document_import"],
1314
"data": ["security/ir.model.access.csv", "wizard/despatch_advice_import.xml"],
1415
"demo": [],

despatch_advice_import/wizard/despatch_advice_import.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2020 ACSONE SA/NV
2+
# Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected]>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
34

45
import logging
@@ -202,11 +203,11 @@ def process_data(self, parsed_order_document):
202203
self._process_picking_done(lines[0].move_ids[0])
203204

204205
def _process_picking_done(self, move):
205-
if all([line.quantity_done != 0 for line in move.picking_id.move_ids]):
206-
move.picking_id.button_validate()
207-
else:
208-
picking = move.picking_id
209-
picking.with_context(skip_backorder=True).button_validate()
206+
picking = move.picking_id
207+
if all(line.state == "cancel" for line in picking.move_ids):
208+
return True
209+
# skip backorder wizard
210+
picking.with_context(skip_backorder=True).button_validate()
210211

211212
def _process_rejected(self, stock_moves, parsed_order_document):
212213
parsed_order_document["chatter_msg"] = parsed_order_document.get(
@@ -216,7 +217,10 @@ def _process_rejected(self, stock_moves, parsed_order_document):
216217
_("Delivery cancelled by the supplier.")
217218
)
218219

219-
stock_moves._action_cancel()
220+
# Loose dependency with stock_picking_restrict_cancel_printed module
221+
# that checks we are canceling the backorder to allow move cancellation.
222+
# Mimic odoo setting this cancel_backorder context variable in this case.
223+
stock_moves.with_context(cancel_backorder=True)._action_cancel()
220224

221225
def _process_accepted(self, stock_moves, parsed_order_document, forced_qty=False):
222226
parsed_order_document["chatter_msg"] = (
@@ -296,7 +300,10 @@ def _process_conditional(self, moves, parsed_order_document, line):
296300
# cancel moves to cancel
297301
if move_ids_to_cancel:
298302
moves_to_cancel = self.env["stock.move"].browse(move_ids_to_cancel)
299-
moves_to_cancel._action_cancel()
303+
# Loose dependency with stock_picking_restrict_cancel_printed module
304+
# that checks we are canceling the backorder to allow move cancellation.
305+
# Mimic odoo setting this cancel_backorder context variable in this case.
306+
moves_to_cancel.with_context(cancel_backorder=True)._action_cancel()
300307
# move backorder moves to a backorder
301308
if move_ids_to_backorder:
302309
moves_to_backorder = self.env["stock.move"].browse(move_ids_to_backorder)

0 commit comments

Comments
 (0)