From b7c92f3756e54fbe332632946950de4ea0f02a01 Mon Sep 17 00:00:00 2001 From: Mmequignon Date: Fri, 22 Dec 2023 13:05:00 +0100 Subject: [PATCH 1/4] Add sale_stock_mto_as_mts_orderpoint_product_variant --- .../__init__.py | 1 + .../__manifest__.py | 19 +++ .../models/__init__.py | 1 + .../models/product_product.py | 41 ++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../tests/__init__.py | 1 + .../tests/test_mto_as_mts_variant.py | 127 ++++++++++++++++++ 8 files changed, 193 insertions(+) create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/__init__.py create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/tests/__init__.py create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/__init__.py b/sale_stock_mto_as_mts_orderpoint_product_variant/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py b/sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py new file mode 100644 index 000000000000..1982f014e51d --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +{ + "name": "Sale Stock MTO as MTS Orderpoint Product Variant", + "version": "14.0.1.0.0", + "development_status": "Alpha", + "category": "Operations/Inventory/Delivery", + "website": "https://github.com/OCA/stock-logistics-workflow", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainers": ["mmequignon"], + "license": "AGPL-3", + "installable": True, + "auto_install": True, + "depends": [ + "sale_stock_mto_as_mts_orderpoint", + "stock_product_variant_mto", + ], +} diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py b/sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py new file mode 100644 index 000000000000..5c74c8c30f1e --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py @@ -0,0 +1 @@ +from . import product_product diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py b/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py new file mode 100644 index 000000000000..6b6393c1bada --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py @@ -0,0 +1,41 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import api, models + +class ProductProduct(models.Model): + _inherit = "product.product" + + def _variant_is_mto(self): + self.ensure_one() + return self.is_mto + + def _inverse_is_mto(self): + res = super()._inverse_is_mto() + self._archive_orderpoints_on_mto_removal() + return res + + @api.depends("product_tmpl_id.route_ids") + def _compute_is_mto(self): + # Archive orderpoints when variant becomes not mto + res = super()._compute_is_mto() + self._archive_orderpoints_on_mto_removal() + return res + + def _get_orderpoints_to_archive_domain(self): + # Orderpoints to archive are those where + warehouses = self.env["stock.warehouse"].search([]) + locations = warehouses._get_locations_for_mto_orderpoints() + return [ + ("product_id", "in", self.ids), + ("product_min_qty", "=", 0.0), + ("product_max_qty", "=", 0.0), + ("location_id", "in", locations.ids), + ("product_id.is_mto", "=", False), + ] + + def _archive_orderpoints_on_mto_removal(self): + domain = self._get_orderpoints_to_archive_domain() + ops = self.env["stock.warehouse.orderpoint"].search(domain) + if ops: + ops.write({"active": False}) diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..bca4ee0cadbc --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Matthieu Méquignon diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..d0cd73dff80a --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the `sale_stock_mto_as_mts_orderpoint` module, +in order to handle the orderpoints at variant level. diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/tests/__init__.py b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/__init__.py new file mode 100644 index 000000000000..57eae7c9fe21 --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mto_as_mts_variant diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py new file mode 100644 index 000000000000..1dc1eed9d9be --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py @@ -0,0 +1,127 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.tests import Form +from odoo.addons.stock_product_variant_mto.tests.common import TestMTOVariantCommon + + +class TestMtoAsMtsVariant(TestMTOVariantCommon): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env.ref("base.res_partner_2") + cls.vendor_partner = cls.env.ref("base.res_partner_12") + cls.env["product.supplierinfo"].create( + [ + { + "name": cls.vendor_partner.id, + "product_tmpl_id": variant.product_tmpl_id.id, + "product_id": variant.id, + "min_qty": 1.0, + "price": 1.0, + } + for variant in cls.variants_pen + ] + ) + cls.warehouse = cls.env.ref("stock.warehouse0") + + @classmethod + def setUpClassProduct(cls): + super().setUpClassProduct() + cls.buy_route = cls.env.ref("purchase_stock.route_warehouse0_buy") + cls.template_pen.write( + {"route_ids": [(6, 0, [cls.buy_route.id, cls.mto_route.id])]} + ) + + @classmethod + def _create_sale_order(cls, products): + sale_form = Form(cls.env["sale.order"]) + sale_form.partner_id = cls.partner + sale_form.warehouse_id = cls.warehouse + for product in products: + with sale_form.order_line.new() as line_form: + line_form.product_id = product + line_form.product_uom_qty = 1 + return sale_form.save() + + def _get_orderpoint_for_products(self, products, archived=False): + orderpoint = self.env["stock.warehouse.orderpoint"] + if archived: + orderpoint = orderpoint.with_context(active_test=False) + return orderpoint.search( + [("product_id", "in", products.ids)] + ) + + def test_mto_as_mts_orderpoint(self): + template_pen = self.template_pen + black_pen = self.black_pen + blue_pen = self.blue_pen + red_pen = self.red_pen + green_pen = self.green_pen + order = self._create_sale_order(black_pen) + orderpoint = self._get_orderpoint_for_products(black_pen) + self.assertFalse(orderpoint) + order.action_confirm() + orderpoint = self._get_orderpoint_for_products(black_pen) + self.assertEqual( + orderpoint.location_id, + self.warehouse._get_locations_for_mto_orderpoints(), + ) + self.assertAlmostEqual(orderpoint.product_min_qty, 0.0) + self.assertAlmostEqual(orderpoint.product_max_qty, 0.0) + # Setting the black pen to mto should drop its orderpoint + self.toggle_is_mto(black_pen) + orderpoint = self._get_orderpoint_for_products(black_pen) + self.assertFalse(orderpoint) + # Creating and confirming an order for variants should create + # an orderpoint for all variants but the black pen + order = self._create_sale_order(self.variants_pen) + order.action_confirm() + # black pen orderpoint is archived + self.assertFalse(self._get_orderpoint_for_products(black_pen)) + self.assertTrue(self._get_orderpoint_for_products(black_pen, archived=True)) + other_pens = red_pen | green_pen | blue_pen + self.assertEqual( + len(self._get_orderpoint_for_products(other_pens)), 3 + ) + + def test_mtp_as_mts_orderpoint_product_no_mto(self): + template_pen = self.template_pen + black_pen = self.black_pen + variants_pen = self.variants_pen + # set everything to not mto + template_pen.route_ids = False + self.toggle_is_mto(variants_pen) + # then check that no orderpoint is created + order = self._create_sale_order(black_pen) + orderpoint = self.env["stock.warehouse.orderpoint"].search( + [("product_id", "=", black_pen.id)] + ) + self.assertFalse(orderpoint) + order.action_confirm() + orderpoint = self.env["stock.warehouse.orderpoint"].search( + [("product_id", "=", black_pen.id)] + ) + self.assertFalse(orderpoint) + + def test_cancel_sale_order_orderpoint(self): + order = self._create_sale_order(self.variants_pen) + order.action_confirm() + order.action_cancel() + order.action_draft() + order.action_confirm() + self.assertEqual(order.state, "sale") + + def test_confirm_mto_as_mts_sudo_needed(self): + """Check access right needed to confirm sale. + + A sale manager user with no right on inventory will raise an access + right error on confirmation. + This is the why of the sudo in `sale_stock_mto_as_mts_orderpoint` + """ + user = self.env.ref("base.user_demo") + sale_group = self.env.ref("sales_team.group_sale_manager") + sale_group.users = [(4, user.id)] + order = self._create_sale_order(self.variants_pen) + order.with_user(user).action_confirm() From 492da0a39f08f532a43fb1c38a92903d1640db6c Mon Sep 17 00:00:00 2001 From: chaule97 Date: Thu, 2 Jan 2025 15:43:36 +0700 Subject: [PATCH 2/4] [IMP] sale_stock_mto_as_mts_orderpoint_product_variant: pre-commit auto fixes --- .../README.rst | 90 ++++ .../models/product_product.py | 1 + .../pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 1 + .../readme/CONTRIBUTORS.rst | 1 - .../readme/DESCRIPTION.md | 2 + .../readme/DESCRIPTION.rst | 2 - .../static/description/index.html | 432 ++++++++++++++++++ .../tests/test_mto_as_mts_variant.py | 10 +- 9 files changed, 532 insertions(+), 10 deletions(-) create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/README.rst create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/pyproject.toml create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md delete mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.md delete mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/README.rst b/sale_stock_mto_as_mts_orderpoint_product_variant/README.rst new file mode 100644 index 000000000000..722d1af13928 --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/README.rst @@ -0,0 +1,90 @@ +================================================ +Sale Stock MTO as MTS Orderpoint Product Variant +================================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9879bf3665b9faafa4cb090cc082b78509790ccc4f13c033051a6179517dace6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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%2Fstock--logistics--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-workflow/tree/18.0/sale_stock_mto_as_mts_orderpoint_product_variant + :alt: OCA/stock-logistics-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-sale_stock_mto_as_mts_orderpoint_product_variant + :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/stock-logistics-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the sale_stock_mto_as_mts_orderpoint module, in +order to handle the orderpoints at variant level. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**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 +------- + +* Camptocamp + +Contributors +------------ + +- Matthieu Méquignon + +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. + +.. |maintainer-mmequignon| image:: https://github.com/mmequignon.png?size=40px + :target: https://github.com/mmequignon + :alt: mmequignon + +Current `maintainer `__: + +|maintainer-mmequignon| + +This module is part of the `OCA/stock-logistics-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_mto_as_mts_orderpoint_product_variant/models/product_product.py b/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py index 6b6393c1bada..cdbfab740ef1 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py @@ -3,6 +3,7 @@ from odoo import api, models + class ProductProduct(models.Model): _inherit = "product.product" diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/pyproject.toml b/sale_stock_mto_as_mts_orderpoint_product_variant/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..8098474f3c6b --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Matthieu Méquignon \<\> diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst deleted file mode 100644 index bca4ee0cadbc..000000000000 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1 +0,0 @@ -* Matthieu Méquignon diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.md b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.md new file mode 100644 index 000000000000..b2aac0994734 --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module extends the sale_stock_mto_as_mts_orderpoint module, in +order to handle the orderpoints at variant level. diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst deleted file mode 100644 index d0cd73dff80a..000000000000 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/DESCRIPTION.rst +++ /dev/null @@ -1,2 +0,0 @@ -This module extends the `sale_stock_mto_as_mts_orderpoint` module, -in order to handle the orderpoints at variant level. diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html b/sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html new file mode 100644 index 000000000000..5dc2402ebb84 --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +Sale Stock MTO as MTS Orderpoint Product Variant + + + +
+

Sale Stock MTO as MTS Orderpoint Product Variant

+ + +

Alpha License: AGPL-3 OCA/stock-logistics-workflow Translate me on Weblate Try me on Runboat

+

This module extends the sale_stock_mto_as_mts_orderpoint module, in +order to handle the orderpoints at variant level.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

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

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

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.

+

Current maintainer:

+

mmequignon

+

This module is part of the OCA/stock-logistics-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_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py index 1dc1eed9d9be..bf0e96bb06f4 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py @@ -2,11 +2,11 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from odoo.tests import Form + from odoo.addons.stock_product_variant_mto.tests.common import TestMTOVariantCommon class TestMtoAsMtsVariant(TestMTOVariantCommon): - @classmethod def setUpClass(cls): super().setUpClass() @@ -49,9 +49,7 @@ def _get_orderpoint_for_products(self, products, archived=False): orderpoint = self.env["stock.warehouse.orderpoint"] if archived: orderpoint = orderpoint.with_context(active_test=False) - return orderpoint.search( - [("product_id", "in", products.ids)] - ) + return orderpoint.search([("product_id", "in", products.ids)]) def test_mto_as_mts_orderpoint(self): template_pen = self.template_pen @@ -82,9 +80,7 @@ def test_mto_as_mts_orderpoint(self): self.assertFalse(self._get_orderpoint_for_products(black_pen)) self.assertTrue(self._get_orderpoint_for_products(black_pen, archived=True)) other_pens = red_pen | green_pen | blue_pen - self.assertEqual( - len(self._get_orderpoint_for_products(other_pens)), 3 - ) + self.assertEqual(len(self._get_orderpoint_for_products(other_pens)), 3) def test_mtp_as_mts_orderpoint_product_no_mto(self): template_pen = self.template_pen From 1f275afac29cf15045b8d71851ffe29eec90b745 Mon Sep 17 00:00:00 2001 From: chaule97 Date: Thu, 9 Jan 2025 16:04:35 +0700 Subject: [PATCH 3/4] [MIG] sale_stock_mto_as_mts_orderpoint_product_variant: Migration to 18.0 --- .../README.rst | 9 +++++++++ .../__manifest__.py | 2 +- .../models/__init__.py | 1 + .../models/product_product.py | 7 +++---- .../models/sale_order_line.py | 15 +++++++++++++++ .../readme/CONTRIBUTORS.md | 1 + .../readme/CREDITS.md | 3 +++ .../static/description/index.html | 14 ++++++++++++-- .../tests/test_mto_as_mts_variant.py | 19 ++++++++++--------- 9 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/models/sale_order_line.py create mode 100644 sale_stock_mto_as_mts_orderpoint_product_variant/readme/CREDITS.md diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/README.rst b/sale_stock_mto_as_mts_orderpoint_product_variant/README.rst index 722d1af13928..d703cb19c500 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/README.rst +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/README.rst @@ -63,6 +63,15 @@ Contributors ------------ - Matthieu Méquignon +- Chau Le + +Other credits +------------- + +The development and migration of this module has been financially +supported by: + +- Camptocamp Maintainers ----------- diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py b/sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py index 1982f014e51d..3f5b0a884191 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Sale Stock MTO as MTS Orderpoint Product Variant", - "version": "14.0.1.0.0", + "version": "18.0.1.0.0", "development_status": "Alpha", "category": "Operations/Inventory/Delivery", "website": "https://github.com/OCA/stock-logistics-workflow", diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py b/sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py index 5c74c8c30f1e..da7ab3f20251 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/models/__init__.py @@ -1 +1,2 @@ from . import product_product +from . import sale_order_line diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py b/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py index cdbfab740ef1..f2fcc0ccdace 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/models/product_product.py @@ -1,22 +1,21 @@ # Copyright 2023 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) -from odoo import api, models +from odoo import fields, models class ProductProduct(models.Model): _inherit = "product.product" + is_mto = fields.Boolean(inverse="_inverse_is_mto") + def _variant_is_mto(self): self.ensure_one() return self.is_mto def _inverse_is_mto(self): - res = super()._inverse_is_mto() self._archive_orderpoints_on_mto_removal() - return res - @api.depends("product_tmpl_id.route_ids") def _compute_is_mto(self): # Archive orderpoints when variant becomes not mto res = super()._compute_is_mto() diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/models/sale_order_line.py b/sale_stock_mto_as_mts_orderpoint_product_variant/models/sale_order_line.py new file mode 100644 index 000000000000..56e3285bb16a --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/models/sale_order_line.py @@ -0,0 +1,15 @@ +# Copyright 2025 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _get_mto_orderpoint(self, product_id): + orderpoint = super()._get_mto_orderpoint(product_id) + + if not product_id.is_mto: + orderpoint.write({"active": False}) + + return orderpoint diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md index 8098474f3c6b..385ebdb109ad 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CONTRIBUTORS.md @@ -1 +1,2 @@ - Matthieu Méquignon \<\> +- Chau Le \<\> diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CREDITS.md b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CREDITS.md new file mode 100644 index 000000000000..c2d2a1e6b83c --- /dev/null +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/readme/CREDITS.md @@ -0,0 +1,3 @@ +The development and migration of this module has been financially supported by: + +- Camptocamp diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html b/sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html index 5dc2402ebb84..3feee21e594f 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/static/description/index.html @@ -385,7 +385,8 @@

Sale Stock MTO as MTS Orderpoint Product Variant

  • Credits
  • @@ -410,10 +411,19 @@

    Authors

    Contributors

    + +
    +

    Other credits

    +

    The development and migration of this module has been financially +supported by:

    +
      +
    • Camptocamp
    -

    Maintainers

    +

    Maintainers

    This module is maintained by the OCA.

    Odoo Community Association diff --git a/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py index bf0e96bb06f4..1476d86be447 100644 --- a/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py +++ b/sale_stock_mto_as_mts_orderpoint_product_variant/tests/test_mto_as_mts_variant.py @@ -15,7 +15,7 @@ def setUpClass(cls): cls.env["product.supplierinfo"].create( [ { - "name": cls.vendor_partner.id, + "partner_id": cls.vendor_partner.id, "product_tmpl_id": variant.product_tmpl_id.id, "product_id": variant.id, "min_qty": 1.0, @@ -25,9 +25,10 @@ def setUpClass(cls): ] ) cls.warehouse = cls.env.ref("stock.warehouse0") + cls.warehouse.mto_as_mts = True @classmethod - def setUpClassProduct(cls): + def setUpClassProduct(cls): # pylint: disable=missing-return super().setUpClassProduct() cls.buy_route = cls.env.ref("purchase_stock.route_warehouse0_buy") cls.template_pen.write( @@ -46,13 +47,13 @@ def _create_sale_order(cls, products): return sale_form.save() def _get_orderpoint_for_products(self, products, archived=False): - orderpoint = self.env["stock.warehouse.orderpoint"] - if archived: - orderpoint = orderpoint.with_context(active_test=False) - return orderpoint.search([("product_id", "in", products.ids)]) + return ( + self.env["stock.warehouse.orderpoint"] + .with_context(active_test=not archived) + .search([("product_id", "in", products.ids)]) + ) def test_mto_as_mts_orderpoint(self): - template_pen = self.template_pen black_pen = self.black_pen blue_pen = self.blue_pen red_pen = self.red_pen @@ -88,7 +89,7 @@ def test_mtp_as_mts_orderpoint_product_no_mto(self): variants_pen = self.variants_pen # set everything to not mto template_pen.route_ids = False - self.toggle_is_mto(variants_pen) + variants_pen.write({"is_mto": False}) # then check that no orderpoint is created order = self._create_sale_order(black_pen) orderpoint = self.env["stock.warehouse.orderpoint"].search( @@ -104,7 +105,7 @@ def test_mtp_as_mts_orderpoint_product_no_mto(self): def test_cancel_sale_order_orderpoint(self): order = self._create_sale_order(self.variants_pen) order.action_confirm() - order.action_cancel() + order.with_context(disable_cancel_warning=True).action_cancel() order.action_draft() order.action_confirm() self.assertEqual(order.state, "sale") From 71bbb6ee3677daac40ac0d8f4b5965d1d4344eea Mon Sep 17 00:00:00 2001 From: chaule97 Date: Thu, 9 Jan 2025 16:11:32 +0700 Subject: [PATCH 4/4] [DON'T MERGE] Add test-requirements.txt --- test-requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test-requirements.txt diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000000..28b12ea12325 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +odoo-addon-sale_stock_mto_as_mts_orderpoint @ git+https://github.com/chaule97/stock-logistics-workflow.git@refs/pull/2/head#subdirectory=sale_stock_mto_as_mts_orderpoint +odoo-addon-stock_product_variant_mto @ git+https://github.com/chaule97/stock-logistics-workflow.git@refs/pull/1/head#subdirectory=stock_product_variant_mto