Skip to content

Commit

Permalink
despatch_advice_import: fix processing
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jbaudoux committed Jan 17, 2025
1 parent 856623c commit 68846e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion despatch_advice_import/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"version": "16.0.1.2.0",
"website": "https://github.com/OCA/edi",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"author": "ACSONE SA/NV,BCIM,Odoo Community Association (OCA)",
"maintainers": ["jbaudoux"],
"depends": ["purchase", "purchase_stock", "base_business_document_import"],
"data": ["security/ir.model.access.csv", "wizard/despatch_advice_import.xml"],
"demo": [],
Expand Down
21 changes: 14 additions & 7 deletions despatch_advice_import/wizard/despatch_advice_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2020 ACSONE SA/NV
# Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
Expand Down Expand Up @@ -202,11 +203,11 @@ def process_data(self, parsed_order_document):
self._process_picking_done(lines[0].move_ids[0])

def _process_picking_done(self, move):
if all([line.quantity_done != 0 for line in move.picking_id.move_ids]):
move.picking_id.button_validate()
else:
picking = move.picking_id
picking.with_context(skip_backorder=True).button_validate()
picking = move.picking_id
if all(line.state == "cancel" for line in picking.move_ids):
return True
# skip backorder wizard
picking.with_context(skip_backorder=True).button_validate()

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

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

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

0 comments on commit 68846e5

Please sign in to comment.