1
1
# Copyright 2020 ACSONE SA/NV
2
+ # Copyright 2025 Jacques-Etienne Baudoux (BCIM) <[email protected] >
2
3
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3
4
4
5
import logging
@@ -202,11 +203,11 @@ def process_data(self, parsed_order_document):
202
203
self ._process_picking_done (lines [0 ].move_ids [0 ])
203
204
204
205
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 ()
210
211
211
212
def _process_rejected (self , stock_moves , parsed_order_document ):
212
213
parsed_order_document ["chatter_msg" ] = parsed_order_document .get (
@@ -216,7 +217,10 @@ def _process_rejected(self, stock_moves, parsed_order_document):
216
217
_ ("Delivery cancelled by the supplier." )
217
218
)
218
219
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 ()
220
224
221
225
def _process_accepted (self , stock_moves , parsed_order_document , forced_qty = False ):
222
226
parsed_order_document ["chatter_msg" ] = (
@@ -296,7 +300,10 @@ def _process_conditional(self, moves, parsed_order_document, line):
296
300
# cancel moves to cancel
297
301
if move_ids_to_cancel :
298
302
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 ()
300
307
# move backorder moves to a backorder
301
308
if move_ids_to_backorder :
302
309
moves_to_backorder = self .env ["stock.move" ].browse (move_ids_to_backorder )
0 commit comments