-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] sale_order_line_cancel: support kits
- Loading branch information
1 parent
483041b
commit 736014a
Showing
5 changed files
with
64 additions
and
23 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,4 +1,5 @@ | ||
# © 2016 Sylvain Van Hoof | ||
# Copyright 2018 Sylvain Van Hoof (Okia SPRL) | ||
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
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,8 +1,9 @@ | ||
# Copyright 2018 Okia SPRL | ||
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# Copyright 2020 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
from odoo import _, api, fields, models | ||
from odoo.tools import float_compare | ||
|
||
|
||
|
@@ -34,7 +35,7 @@ def _compute_can_cancel_remaining_qty(self): | |
) | ||
== 1 | ||
and rec.state in ("sale", "done") | ||
and rec.move_ids | ||
and rec.qty_delivered_method == "stock_move" | ||
) | ||
|
||
@api.depends( | ||
|
@@ -44,10 +45,33 @@ def _compute_can_cancel_remaining_qty(self): | |
) | ||
def _compute_product_qty_remains_to_deliver(self): | ||
for line in self: | ||
remaining_to_deliver = ( | ||
line.product_uom_qty - line.qty_delivered - line.product_qty_canceled | ||
) | ||
line.product_qty_remains_to_deliver = remaining_to_deliver | ||
qty_remaining = line.qty_to_deliver - line.product_qty_canceled | ||
line.product_qty_remains_to_deliver = qty_remaining | ||
|
||
def _get_moves_to_cancel(self): | ||
return self.move_ids.filtered(lambda m: m.state not in ("done", "cancel")) | ||
|
||
def _check_moves_to_cancel(self, moves): | ||
"""override this method to add checks before cancel""" | ||
"""Override this method to add checks before cancel""" | ||
self.ensure_one() | ||
|
||
def _update_qty_canceled(self): | ||
"""Update SO line qty canceled only when all remaining moves are canceled""" | ||
for line in self: | ||
if line._get_moves_to_cancel(): | ||
continue | ||
line.product_qty_canceled = line.qty_to_deliver | ||
|
||
def cancel_remaining_qty(self): | ||
lines = self.filtered(lambda l: l.can_cancel_remaining_qty) | ||
for line in lines: | ||
moves_to_cancel = line._get_moves_to_cancel() | ||
line._check_moves_to_cancel(moves_to_cancel) | ||
moves_to_cancel._action_cancel() | ||
line.order_id.message_post( | ||
body=_( | ||
"<b>%(product)s</b>: The order line has been canceled", | ||
product=line.product_id.display_name, | ||
) | ||
) | ||
return True |
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,4 +1,5 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
@@ -13,8 +14,14 @@ def _action_cancel(self): | |
lambda m: m.sale_line_id and m.state not in ("done", "cancel") | ||
) | ||
res = super()._action_cancel() | ||
for rec in sale_moves: | ||
if rec.state != "cancel": | ||
continue | ||
rec.sale_line_id.product_qty_canceled = rec.product_uom_qty | ||
sale_lines = sale_moves.filtered(lambda m: m.state == "cancel").sale_line_id | ||
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 |
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