forked from OCA/sale-workflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstock_move.py
More file actions
46 lines (38 loc) · 1.61 KB
/
stock_move.py
File metadata and controls
46 lines (38 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright 2023 ACSONE SA/NV
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# Copyright 2025 Michael Tietz (MT Software) <mtietz@mt-software.de>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class StockMove(models.Model):
_inherit = "stock.move"
def _action_cancel(self):
res = super()._action_cancel()
if self.env.context.get("ignore_sale_order_line_cancel", False):
return res
sale_lines = self._get_sale_lines_to_update_qty_canceled()
sale_lines._update_qty_canceled()
return res
def _action_done(self, cancel_backorder=False):
moves_todo = super()._action_done(cancel_backorder=cancel_backorder)
if cancel_backorder and moves_todo:
# _action_cancel is called before marking as done, so the hook on
# _action_cancel will not be triggered. Call it now
self.sale_line_id._update_qty_canceled()
return moves_todo
def _get_sale_lines_to_update_qty_canceled(self):
sale_lines = self.env["sale.order.line"]
for move in self:
if (
move.sale_line_id
and move._is_move_to_take_into_account_for_qty_canceled()
):
sale_lines |= move.sale_line_id
return sale_lines
def _is_move_to_take_into_account_for_qty_canceled(self):
self.ensure_one()
return (
self.state == "cancel"
and self.sale_line_id
and self.sale_line_id.state not in ["draft", "sent"]
and self.picking_type_id.code == "outgoing"
)