-
-
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.
[ADD] sale_stock_prebook_cancel_line: Glue addon
This addon is a technical module that ensures that the computation of the cancelled quantity on a sale order line is correct even when a prebooking is involved. Cancelled prebooked quantities must not be taken into account in the computation of the cancelled quantity on the sale order line.
- Loading branch information
Showing
14 changed files
with
132 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Sale Stock Prebook Cancel Line", | ||
"summary": """Takes into account prebook pickings into the computation | ||
of cancelled qty on the sale order lines""", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/sale-workflow", | ||
"depends": [ | ||
"sale_stock_prebook", | ||
"sale_order_line_cancel", | ||
], | ||
"auto_install": True, | ||
"data": [], | ||
"demo": [], | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import sale_order_line | ||
from . import stock_move |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
def _check_moves_to_cancel(self, moves): | ||
self.ensure_one() | ||
if self.move_ids.filtered("used_for_sale_reservation"): | ||
raise UserError( | ||
_( | ||
"You cannot cancel a line with prebooked moves. " | ||
"Please cancel the related prebooked moves first." | ||
) | ||
) |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class StockMove(models.Model): | ||
|
||
_inherit = "stock.move" | ||
|
||
def _is_move_to_take_into_account_for_qty_canceled(self): | ||
self.ensure_one() | ||
res = super()._is_move_to_take_into_account_for_qty_canceled() | ||
return res and not self.used_for_sale_reservation |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
- Laurent Mignon <[email protected]> (https://www.acsone.eu) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The development of this module has been financially supported by: | ||
|
||
- ALCYON Belux |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
This addon is a technical module that ensures that the computation of the cancelled quantity on a sale order line is correct even when a prebooking is involved. Cancelled prebooked quantities must not be taken into account in the computation of the cancelled quantity on the sale order line. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_sale_stock_prebook_cancel_line |
62 changes: 62 additions & 0 deletions
62
sale_stock_prebook_cancel_line/tests/test_sale_stock_prebook_cancel_line.py
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import Command | ||
|
||
from odoo.addons.sale_order_line_cancel.tests.common import TestSaleOrderLineCancelBase | ||
|
||
|
||
class TestSaleStockPrebookCancelLine(TestSaleOrderLineCancelBase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.draft_order = cls.env["sale.order"].create( | ||
{ | ||
"partner_id": cls.partner.id, | ||
"warehouse_id": cls.warehouse.id, | ||
"order_line": [ | ||
Command.create( | ||
{ | ||
"name": cls.product_1.name, | ||
"product_id": cls.product_1.id, | ||
"product_uom_qty": 10, | ||
"product_uom": cls.product_1.uom_id.id, | ||
"price_unit": 1, | ||
} | ||
) | ||
], | ||
} | ||
) | ||
|
||
def test_cancel_prebook_line_no_qty_cancelled(self): | ||
"""If we cancel a prebook move line, the qty cancelled should be 0 on the | ||
sale order line | ||
""" | ||
self.draft_order.reserve_stock() | ||
picking_reservations = self.draft_order._get_reservation_pickings() | ||
self.assertEqual(len(picking_reservations), 1) | ||
picking_reservations.move_ids._action_cancel() | ||
self.assertEqual(picking_reservations.move_ids.state, "cancel") | ||
self.assertEqual(self.draft_order.order_line.product_qty_canceled, 0) | ||
|
||
def test_cancel_prebook_picking_no_qty_cancelled(self): | ||
"""If we cancel a prebook move line, the qty cancelled should be 0 on the | ||
sale order line | ||
""" | ||
self.draft_order.reserve_stock() | ||
picking_reservations = self.draft_order._get_reservation_pickings() | ||
self.assertEqual(len(picking_reservations), 1) | ||
picking_reservations.action_cancel() | ||
self.assertEqual(picking_reservations.state, "cancel") | ||
self.assertEqual(self.draft_order.order_line.product_qty_canceled, 0) | ||
|
||
def test_cancel_prebook_no_qty_cancelled(self): | ||
"""If we cancel a prebook move line, the qty cancelled should be 0 on the | ||
sale order line | ||
""" | ||
self.draft_order.reserve_stock() | ||
picking_reservations = self.draft_order._get_reservation_pickings() | ||
self.assertEqual(len(picking_reservations), 1) | ||
self.draft_order.release_reservation() | ||
self.assertFalse(picking_reservations.exists()) | ||
self.assertEqual(self.draft_order.order_line.product_qty_canceled, 0) |
1 change: 1 addition & 0 deletions
1
setup/sale_stock_prebook_cancel_line/odoo/addons/sale_stock_prebook_cancel_line
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../sale_stock_prebook_cancel_line |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=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 +1,3 @@ | ||
odoo_test_helper | ||
odoo-addon-sale-stock-prebook @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3481/head#subdirectory=setup/sale_stock_prebook | ||
odoo-addon-sale-order-line-cancel @ git+https://github.com/OCA/sale-workflow.git@refs/pull/2357/head#subdirectory=setup/sale_order_line_cancel |