diff --git a/sale_stock_prebook_cancel_line/README.rst b/sale_stock_prebook_cancel_line/README.rst new file mode 100644 index 00000000000..85969d2610a --- /dev/null +++ b/sale_stock_prebook_cancel_line/README.rst @@ -0,0 +1,87 @@ +============================== +Sale Stock Prebook Cancel Line +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f65ec5c91a84d53bac32426f0b13e62ae3daff48702527b752a2150517e8d7fe + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/16.0/sale_stock_prebook_cancel_line + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_stock_prebook_cancel_line + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu) + +Other credits +------------- + +The development of this module has been financially supported by: + +- ALCYON Belux + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_stock_prebook_cancel_line/__init__.py b/sale_stock_prebook_cancel_line/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_stock_prebook_cancel_line/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_stock_prebook_cancel_line/__manifest__.py b/sale_stock_prebook_cancel_line/__manifest__.py new file mode 100644 index 00000000000..f593e98fd5c --- /dev/null +++ b/sale_stock_prebook_cancel_line/__manifest__.py @@ -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": [], +} diff --git a/sale_stock_prebook_cancel_line/models/__init__.py b/sale_stock_prebook_cancel_line/models/__init__.py new file mode 100644 index 00000000000..c7ec7126e6d --- /dev/null +++ b/sale_stock_prebook_cancel_line/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order_line +from . import stock_move diff --git a/sale_stock_prebook_cancel_line/models/sale_order_line.py b/sale_stock_prebook_cancel_line/models/sale_order_line.py new file mode 100644 index 00000000000..0089fc4fea5 --- /dev/null +++ b/sale_stock_prebook_cancel_line/models/sale_order_line.py @@ -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." + ) + ) diff --git a/sale_stock_prebook_cancel_line/models/stock_move.py b/sale_stock_prebook_cancel_line/models/stock_move.py new file mode 100644 index 00000000000..b93ac4bc0a0 --- /dev/null +++ b/sale_stock_prebook_cancel_line/models/stock_move.py @@ -0,0 +1,16 @@ +# 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() + return ( + not self.used_for_sale_reservation + and super()._is_move_to_take_into_account_for_qty_canceled() + ) diff --git a/sale_stock_prebook_cancel_line/readme/CONTRIBUTORS.md b/sale_stock_prebook_cancel_line/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..a15e3ef244f --- /dev/null +++ b/sale_stock_prebook_cancel_line/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/sale_stock_prebook_cancel_line/readme/CREDITS.md b/sale_stock_prebook_cancel_line/readme/CREDITS.md new file mode 100644 index 00000000000..84b071cb672 --- /dev/null +++ b/sale_stock_prebook_cancel_line/readme/CREDITS.md @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +- ALCYON Belux \ No newline at end of file diff --git a/sale_stock_prebook_cancel_line/readme/DESCRIPTION.md b/sale_stock_prebook_cancel_line/readme/DESCRIPTION.md new file mode 100644 index 00000000000..321da8900a9 --- /dev/null +++ b/sale_stock_prebook_cancel_line/readme/DESCRIPTION.md @@ -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. diff --git a/sale_stock_prebook_cancel_line/static/description/icon.png b/sale_stock_prebook_cancel_line/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_stock_prebook_cancel_line/static/description/icon.png differ diff --git a/sale_stock_prebook_cancel_line/static/description/index.html b/sale_stock_prebook_cancel_line/static/description/index.html new file mode 100644 index 00000000000..f7f680f497e --- /dev/null +++ b/sale_stock_prebook_cancel_line/static/description/index.html @@ -0,0 +1,435 @@ + + + + + +Sale Stock Prebook Cancel Line + + + +
+

Sale Stock Prebook Cancel Line

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

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.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+ +
+

Other credits

+

The development of this module has been financially supported by:

+
    +
  • ALCYON Belux
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/sale-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sale_stock_prebook_cancel_line/tests/__init__.py b/sale_stock_prebook_cancel_line/tests/__init__.py new file mode 100644 index 00000000000..76a6d9f6a12 --- /dev/null +++ b/sale_stock_prebook_cancel_line/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_stock_prebook_cancel_line diff --git a/sale_stock_prebook_cancel_line/tests/test_sale_stock_prebook_cancel_line.py b/sale_stock_prebook_cancel_line/tests/test_sale_stock_prebook_cancel_line.py new file mode 100644 index 00000000000..06fed210b30 --- /dev/null +++ b/sale_stock_prebook_cancel_line/tests/test_sale_stock_prebook_cancel_line.py @@ -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) diff --git a/setup/sale_stock_prebook_cancel_line/odoo/addons/sale_stock_prebook_cancel_line b/setup/sale_stock_prebook_cancel_line/odoo/addons/sale_stock_prebook_cancel_line new file mode 120000 index 00000000000..d3681bae639 --- /dev/null +++ b/setup/sale_stock_prebook_cancel_line/odoo/addons/sale_stock_prebook_cancel_line @@ -0,0 +1 @@ +../../../../sale_stock_prebook_cancel_line \ No newline at end of file diff --git a/setup/sale_stock_prebook_cancel_line/setup.py b/setup/sale_stock_prebook_cancel_line/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/sale_stock_prebook_cancel_line/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)