From 8ab5c08fd13ca324a428262b9aa6f317f153fdb7 Mon Sep 17 00:00:00 2001 From: Yoshi Tashiro Date: Fri, 16 Feb 2024 03:46:35 +0000 Subject: [PATCH] [4207][ADD] mrp_mto_owner --- .github/workflows/test.yml | 4 +- mrp_mto_owner/README.rst | 71 +++ mrp_mto_owner/__init__.py | 1 + mrp_mto_owner/__manifest__.py | 12 + mrp_mto_owner/models/__init__.py | 1 + mrp_mto_owner/models/stock_rule.py | 36 ++ mrp_mto_owner/readme/DESCRIPTION.rst | 1 + mrp_mto_owner/static/description/index.html | 414 ++++++++++++++++++ mrp_mto_owner/tests/__init__.py | 1 + mrp_mto_owner/tests/test_mrp_mto_owner.py | 70 +++ setup/mrp_mto_owner/odoo/addons/mrp_mto_owner | 1 + setup/mrp_mto_owner/setup.py | 6 + 12 files changed, 616 insertions(+), 2 deletions(-) create mode 100644 mrp_mto_owner/README.rst create mode 100644 mrp_mto_owner/__init__.py create mode 100644 mrp_mto_owner/__manifest__.py create mode 100644 mrp_mto_owner/models/__init__.py create mode 100644 mrp_mto_owner/models/stock_rule.py create mode 100644 mrp_mto_owner/readme/DESCRIPTION.rst create mode 100644 mrp_mto_owner/static/description/index.html create mode 100644 mrp_mto_owner/tests/__init__.py create mode 100644 mrp_mto_owner/tests/test_mrp_mto_owner.py create mode 120000 setup/mrp_mto_owner/odoo/addons/mrp_mto_owner create mode 100644 setup/mrp_mto_owner/setup.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 220616f7..da9e3e07 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,11 +37,11 @@ jobs: include: - container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest # sales_team_security: incompatible with auditlog (for some reason) - include: "stock_owner_restriction,mrp_stock_owner_restriction,purchase_order_owner,mrp_subcontracting_owner,sales_team_security" + include: "stock_owner_restriction,mrp_stock_owner_restriction,mrp_mto_owner,purchase_order_owner,mrp_subcontracting_owner,sales_team_security" name: test with OCB makepot: "false" - container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest - exclude: "stock_owner_restriction,mrp_stock_owner_restriction,purchase_order_owner,mrp_subcontracting_owner,sales_team_security" + exclude: "stock_owner_restriction,mrp_stock_owner_restriction,mrp_mto_owner,purchase_order_owner,mrp_subcontracting_owner,sales_team_security" name: test with OCB makepot: "false" services: diff --git a/mrp_mto_owner/README.rst b/mrp_mto_owner/README.rst new file mode 100644 index 00000000..b5a62548 --- /dev/null +++ b/mrp_mto_owner/README.rst @@ -0,0 +1,71 @@ +============= +Mrp MTO Owner +============= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:036c5cefeec5cb41b9c81c023c7253fc71755e3852d823e3f6ab518eae246fe4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/16.0/mrp_mto_owner + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_mto_owner + :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/manufacture&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module transfers the owner_id from the source MO to a newly created MO that is generated based on the stock rule. + +**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 +~~~~~~~ + +* Quartile Limited + +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/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_mto_owner/__init__.py b/mrp_mto_owner/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/mrp_mto_owner/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_mto_owner/__manifest__.py b/mrp_mto_owner/__manifest__.py new file mode 100644 index 00000000..b7cd88ce --- /dev/null +++ b/mrp_mto_owner/__manifest__.py @@ -0,0 +1,12 @@ +# Copyright 2024 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Mrp MTO Owner", + "version": "16.0.1.0.0", + "author": "Quartile Limited, Odoo Community Association (OCA)", + "category": "Manufacturing", + "website": "https://github.com/OCA/manufacture", + "depends": ["mrp_stock_owner_restriction"], + "license": "AGPL-3", + "installable": True, +} diff --git a/mrp_mto_owner/models/__init__.py b/mrp_mto_owner/models/__init__.py new file mode 100644 index 00000000..55eae172 --- /dev/null +++ b/mrp_mto_owner/models/__init__.py @@ -0,0 +1 @@ +from . import stock_rule diff --git a/mrp_mto_owner/models/stock_rule.py b/mrp_mto_owner/models/stock_rule.py new file mode 100644 index 00000000..a98e512a --- /dev/null +++ b/mrp_mto_owner/models/stock_rule.py @@ -0,0 +1,36 @@ +# Copyright 2024 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _prepare_mo_vals( + self, + product_id, + product_qty, + product_uom, + location_dest_id, + name, + origin, + company_id, + values, + bom, + ): + vals = super(StockRule, self)._prepare_mo_vals( + product_id, + product_qty, + product_uom, + location_dest_id, + name, + origin, + company_id, + values, + bom, + ) + move_dest_ids = values.get("move_dest_ids") + if move_dest_ids: + vals["owner_id"] = move_dest_ids[0].raw_material_production_id.owner_id.id + return vals diff --git a/mrp_mto_owner/readme/DESCRIPTION.rst b/mrp_mto_owner/readme/DESCRIPTION.rst new file mode 100644 index 00000000..a4f6c95d --- /dev/null +++ b/mrp_mto_owner/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module transfers the owner_id from the source MO to a newly created MO that is generated based on the stock rule. diff --git a/mrp_mto_owner/static/description/index.html b/mrp_mto_owner/static/description/index.html new file mode 100644 index 00000000..a4efa077 --- /dev/null +++ b/mrp_mto_owner/static/description/index.html @@ -0,0 +1,414 @@ + + + + + + +Mrp MTO Owner + + + +
+

Mrp MTO Owner

+ + +

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

+

This module transfers the owner_id from the source MO to a newly created MO that is generated based on the stock rule.

+

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

+
    +
  • Quartile Limited
  • +
+
+
+

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/manufacture project on GitHub.

+

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

+
+
+
+ + diff --git a/mrp_mto_owner/tests/__init__.py b/mrp_mto_owner/tests/__init__.py new file mode 100644 index 00000000..4753b9ec --- /dev/null +++ b/mrp_mto_owner/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_mto_owner diff --git a/mrp_mto_owner/tests/test_mrp_mto_owner.py b/mrp_mto_owner/tests/test_mrp_mto_owner.py new file mode 100644 index 00000000..be9facc2 --- /dev/null +++ b/mrp_mto_owner/tests/test_mrp_mto_owner.py @@ -0,0 +1,70 @@ +# Copyright 2024 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestMrpMtoOwner(TransactionCase): + @classmethod + def setUpClass(cls): + super(TestMrpMtoOwner, cls).setUpClass() + # Get the MTO route and activate it if necessary + mto_route = cls.env.ref("stock.route_warehouse0_mto") + manufacture_route = cls.env.ref("mrp.route_warehouse0_manufacture") + if not mto_route.active: + mto_route.write({"active": True}) + cls.product1 = cls.env["product.product"].create( + { + "name": "Product 1", + "type": "product", + "route_ids": [(6, 0, [mto_route.id, manufacture_route.id])], + } + ) + cls.product2 = cls.env["product.product"].create( + { + "name": "Product 2", + "type": "product", + "route_ids": [(6, 0, [mto_route.id, manufacture_route.id])], + } + ) + cls.product3 = cls.env["product.product"].create( + {"name": "Product 3", "type": "product"} + ) + # Create BOMs for each product + cls.bom1 = cls.env["mrp.bom"].create( + { + "product_id": cls.product1.id, + "product_tmpl_id": cls.product1.product_tmpl_id.id, + "bom_line_ids": [ + (0, 0, {"product_id": cls.product2.id, "product_qty": 1}) + ], + } + ) + cls.bom2 = cls.env["mrp.bom"].create( + { + "product_id": cls.product2.id, + "product_tmpl_id": cls.product2.product_tmpl_id.id, + "bom_line_ids": [ + (0, 0, {"product_id": cls.product3.id, "product_qty": 1}) + ], + } + ) + + def test_mo_owner_id(self): + owner = self.env["res.partner"].search([], limit=1) + mo = self.env["mrp.production"].create( + { + "product_id": self.product1.id, + "product_qty": 1, + "bom_id": self.bom1.id, + "product_uom_id": self.product1.uom_id.id, + "owner_id": owner.id, + } + ) + # Confirm MO to trigger child MO creation + mo.action_confirm() + # Find the child MO for the second product + child_mo = mo._get_children() + # Test if the owner_id of MO and child MO are the same + self.assertEqual(mo.owner_id, owner) + self.assertEqual(mo.owner_id, child_mo.owner_id, "Owner IDs do not match") diff --git a/setup/mrp_mto_owner/odoo/addons/mrp_mto_owner b/setup/mrp_mto_owner/odoo/addons/mrp_mto_owner new file mode 120000 index 00000000..9ce04e09 --- /dev/null +++ b/setup/mrp_mto_owner/odoo/addons/mrp_mto_owner @@ -0,0 +1 @@ +../../../../mrp_mto_owner \ No newline at end of file diff --git a/setup/mrp_mto_owner/setup.py b/setup/mrp_mto_owner/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/mrp_mto_owner/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)