diff --git a/mrp_stock_owner_restriction/README.rst b/mrp_stock_owner_restriction/README.rst new file mode 100644 index 00000000000..51180a4f267 --- /dev/null +++ b/mrp_stock_owner_restriction/README.rst @@ -0,0 +1,79 @@ +=========================== +MRP Stock Owner Restriction +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:00dc2315a91f43ef42e2ae6f4d5657da81307bbe2f4856dd21bc1f3d48c7ee86 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_stock_owner_restriction + :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_stock_owner_restriction + :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 adapts the functionality of stock_owner_restriction in the manufacturing +order. + +**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 + +Contributors +~~~~~~~~~~~~ + +* `Quartile `_: + + * Yoshi Tashiro + +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_stock_owner_restriction/__init__.py b/mrp_stock_owner_restriction/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/mrp_stock_owner_restriction/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_stock_owner_restriction/__manifest__.py b/mrp_stock_owner_restriction/__manifest__.py new file mode 100644 index 00000000000..f9a3ecc2297 --- /dev/null +++ b/mrp_stock_owner_restriction/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "MRP Stock Owner Restriction", + "version": "16.0.1.0.0", + "category": "Manufacturing", + "website": "https://github.com/OCA/manufacture", + "author": "Quartile Limited, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["mrp", "stock_owner_restriction"], + "data": ["views/mrp_production_views.xml"], + "installable": True, +} diff --git a/mrp_stock_owner_restriction/i18n/ja.po b/mrp_stock_owner_restriction/i18n/ja.po new file mode 100644 index 00000000000..bcdbfc42091 --- /dev/null +++ b/mrp_stock_owner_restriction/i18n/ja.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_stock_owner_restriction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-04-12 07:13+0000\n" +"PO-Revision-Date: 2023-04-12 07:13+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_stock_owner_restriction +#: model:ir.model.fields,field_description:mrp_stock_owner_restriction.field_mrp_production__owner_id +msgid "Assign Owner" +msgstr "オーナー割当" + +#. module: mrp_stock_owner_restriction +#: model:ir.model.fields,field_description:mrp_stock_owner_restriction.field_mrp_production__owner_restriction +msgid "Owner Restriction" +msgstr "オーナー制限" + +#. module: mrp_stock_owner_restriction +#: model:ir.model.fields,help:mrp_stock_owner_restriction.field_mrp_production__owner_id +msgid "Produced products will be assigned to this owner." +msgstr "生産された製品は、このオーナーに割り当てられます。" + +#. module: mrp_stock_owner_restriction +#: model:ir.model,name:mrp_stock_owner_restriction.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "製品の移動(在庫移動ライン)" + +#. module: mrp_stock_owner_restriction +#: model:ir.model,name:mrp_stock_owner_restriction.model_mrp_production +msgid "Production Order" +msgstr "製造オーダ" + +#. module: mrp_stock_owner_restriction +#: model:ir.model,name:mrp_stock_owner_restriction.model_stock_move +msgid "Stock Move" +msgstr "在庫移動" diff --git a/mrp_stock_owner_restriction/models/__init__.py b/mrp_stock_owner_restriction/models/__init__.py new file mode 100644 index 00000000000..a228c032172 --- /dev/null +++ b/mrp_stock_owner_restriction/models/__init__.py @@ -0,0 +1,4 @@ +from . import mrp_production +from . import mrp_unbuild +from . import stock_move_line +from . import stock_move diff --git a/mrp_stock_owner_restriction/models/mrp_production.py b/mrp_stock_owner_restriction/models/mrp_production.py new file mode 100644 index 00000000000..5664f814a5b --- /dev/null +++ b/mrp_stock_owner_restriction/models/mrp_production.py @@ -0,0 +1,26 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + owner_id = fields.Many2one( + "res.partner", + "Assign Owner", + readonly=True, + states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]}, + check_company=True, + help="Produced products will be assigned to this owner.", + ) + owner_restriction = fields.Selection(related="picking_type_id.owner_restriction") + + def write(self, vals): + if "owner_id" in vals: + for production in self: + owner_restriction = self.picking_type_id.owner_restriction + if owner_restriction in ("unassigned_owner", "picking_partner"): + production.move_line_raw_ids.unlink() + return super().write(vals) diff --git a/mrp_stock_owner_restriction/models/mrp_unbuild.py b/mrp_stock_owner_restriction/models/mrp_unbuild.py new file mode 100644 index 00000000000..d896717b082 --- /dev/null +++ b/mrp_stock_owner_restriction/models/mrp_unbuild.py @@ -0,0 +1,26 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class MrpUnbuild(models.Model): + _inherit = "mrp.unbuild" + + # FIXME handle unbuild cases without MO + # owner_id = fields.Many2one( + # "res.partner", + # "Assign Owner", + # readonly=True, + # states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]}, + # check_company=True, + # help="Produced products will be assigned to this owner.", + # ) + # owner_restriction = fields.Selection(related="picking_type_id.owner_restriction") + + def action_validate(self): + owner_restriction = self.mo_id.picking_type_id.owner_restriction + owner = self.mo_id.owner_id + if owner and owner_restriction in ("unassigned_owner", "picking_partner"): + self = self.with_context(force_restricted_owner_id=owner) + return super().action_validate() diff --git a/mrp_stock_owner_restriction/models/stock_move.py b/mrp_stock_owner_restriction/models/stock_move.py new file mode 100644 index 00000000000..f664b5287a5 --- /dev/null +++ b/mrp_stock_owner_restriction/models/stock_move.py @@ -0,0 +1,42 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + # Just to add a trigger + @api.depends("production_id.owner_id") + def _compute_restrict_partner_id(self): + return super()._compute_restrict_partner_id() + + def _get_mo_to_unbuild(self): + self.ensure_one() + return self.consume_unbuild_id.mo_id or self.unbuild_id.mo_id + + def _get_owner_for_assign(self): + self.ensure_one() + if self.raw_material_production_id: + return self.raw_material_production_id.owner_id + # Manufactured product should not consider the owner for assignment, or the + # result might be messed up (e.g. tries to move stock from the internal location + # instead of the production location). + if self.production_id: + return False + # For chained origin moves for production component moves. + production = self.move_dest_ids.raw_material_production_id + if production: + return production.owner_id + mo_to_unbuild = self._get_mo_to_unbuild() + if mo_to_unbuild: + return mo_to_unbuild.owner_id + return super()._get_owner_for_assign() + + def _get_owner_restriction(self): + self.ensure_one() + mo_to_unbuild = self._get_mo_to_unbuild() + if mo_to_unbuild: + return mo_to_unbuild.picking_type_id.owner_restriction + return super()._get_owner_restriction() diff --git a/mrp_stock_owner_restriction/models/stock_move_line.py b/mrp_stock_owner_restriction/models/stock_move_line.py new file mode 100644 index 00000000000..5cad5a0bb95 --- /dev/null +++ b/mrp_stock_owner_restriction/models/stock_move_line.py @@ -0,0 +1,18 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + def _action_done(self): + for line in self: + owner = line.move_id.production_id.owner_id or self.env.context.get( + "force_restricted_owner_id", None + ) + if owner: + line.move_id.write({"restrict_partner_id": owner.id}) + line.write({"owner_id": owner.id}) + return super()._action_done() diff --git a/mrp_stock_owner_restriction/readme/CONTRIBUTORS.rst b/mrp_stock_owner_restriction/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..bf1f45a0d89 --- /dev/null +++ b/mrp_stock_owner_restriction/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Quartile `_: + + * Yoshi Tashiro diff --git a/mrp_stock_owner_restriction/readme/DESCRIPTION.rst b/mrp_stock_owner_restriction/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..c9c8783f2d5 --- /dev/null +++ b/mrp_stock_owner_restriction/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module adapts the functionality of stock_owner_restriction in the manufacturing +order. diff --git a/mrp_stock_owner_restriction/static/description/index.html b/mrp_stock_owner_restriction/static/description/index.html new file mode 100644 index 00000000000..3053167226c --- /dev/null +++ b/mrp_stock_owner_restriction/static/description/index.html @@ -0,0 +1,428 @@ + + + + + + +MRP Stock Owner Restriction + + + +
+

MRP Stock Owner Restriction

+ + +

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

+

This module adapts the functionality of stock_owner_restriction in the manufacturing +order.

+

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
  • +
+
+
+

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.

+

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_stock_owner_restriction/tests/__init__.py b/mrp_stock_owner_restriction/tests/__init__.py new file mode 100644 index 00000000000..4ac01db27fb --- /dev/null +++ b/mrp_stock_owner_restriction/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_stock_owner_restriction diff --git a/mrp_stock_owner_restriction/tests/test_mrp_stock_owner_restriction.py b/mrp_stock_owner_restriction/tests/test_mrp_stock_owner_restriction.py new file mode 100644 index 00000000000..03e7969720f --- /dev/null +++ b/mrp_stock_owner_restriction/tests/test_mrp_stock_owner_restriction.py @@ -0,0 +1,93 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestMrpStockOwnerRestriction(TransactionCase): + def setUp(self): + super(TestMrpStockOwnerRestriction, self).setUp() + self.company = self.env.ref("base.main_company") + self.manufacture_route = self.env.ref("mrp.route_warehouse0_manufacture") + + self.finished_product = self.env["product.product"].create( + {"name": "test product", "type": "product"} + ) + self.component = self.env["product.product"].create( + {"name": "test component", "type": "product"} + ) + self.bom = self.env["mrp.bom"].create( + { + "product_id": self.finished_product.id, + "product_tmpl_id": self.finished_product.product_tmpl_id.id, + "product_uom_id": self.finished_product.uom_id.id, + "product_qty": 1.0, + "type": "normal", + } + ) + self.env["mrp.bom.line"].create( + {"bom_id": self.bom.id, "product_id": self.component.id, "product_qty": 1} + ) + self.owner = self.env["res.partner"].create({"name": "Owner test"}) + self.finished_product.route_ids = [(6, 0, self.manufacture_route.ids)] + self.picking_type = self.env["stock.picking.type"].search( + [ + ("code", "=", "mrp_operation"), + ("warehouse_id.company_id", "=", self.company.id), + ], + limit=1, + ) + self.picking_type.write({"owner_restriction": "picking_partner"}) + quant_vals = { + "product_id": self.component.id, + "location_id": self.picking_type.default_location_src_id.id, + "quantity": 250.00, + } + # Create quants without owner + self.env["stock.quant"].create(quant_vals) + # Create quants with owner + self.env["stock.quant"].create(dict(quant_vals, owner_id=self.owner.id)) + + def test_mrp_quant_assign_owner(self): + self.assertEqual(self.component.qty_available, 250) + self.component.invalidate_model(["qty_available"]) + self.assertEqual( + self.component.with_context(skip_restricted_owner=True).qty_available, 500 + ) + mo = self.env["mrp.production"].create( + { + "product_id": self.finished_product.id, + "bom_id": self.bom.id, + "product_qty": 250, + "picking_type_id": self.picking_type.id, + "owner_id": self.owner.id, + } + ) + mo.action_confirm() + action = mo.button_mark_done() + self.assertEqual(action.get("res_model"), "mrp.immediate.production") + wizard = Form( + self.env[action["res_model"]].with_context(**action["context"]) + ).save() + action = wizard.process() + + # Check produced product owner and qty_available + self.assertEqual(self.finished_product.qty_available, 0.00) + self.finished_product.invalidate_model(["qty_available"]) + self.assertEqual( + self.finished_product.with_context( + skip_restricted_owner=True + ).qty_available, + 250.00, + ) + quant = self.env["stock.quant"].search( + [("product_id", "=", self.finished_product.id)] + ) + self.assertEqual(quant.owner_id, self.owner) + + # Confirm that component inventory with owner has been consumed + self.assertEqual(self.component.qty_available, 250) + self.component.invalidate_model(["qty_available"]) + self.assertEqual( + self.component.with_context(skip_restricted_owner=True).qty_available, 250 + ) diff --git a/mrp_stock_owner_restriction/views/mrp_production_views.xml b/mrp_stock_owner_restriction/views/mrp_production_views.xml new file mode 100644 index 00000000000..db347c758a7 --- /dev/null +++ b/mrp_stock_owner_restriction/views/mrp_production_views.xml @@ -0,0 +1,13 @@ + + + + mrp.production.form + mrp.production + + + + + + + + diff --git a/setup/mrp_stock_owner_restriction/odoo/addons/mrp_stock_owner_restriction b/setup/mrp_stock_owner_restriction/odoo/addons/mrp_stock_owner_restriction new file mode 120000 index 00000000000..2c9ca23962d --- /dev/null +++ b/setup/mrp_stock_owner_restriction/odoo/addons/mrp_stock_owner_restriction @@ -0,0 +1 @@ +../../../../mrp_stock_owner_restriction \ No newline at end of file diff --git a/setup/mrp_stock_owner_restriction/setup.py b/setup/mrp_stock_owner_restriction/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/mrp_stock_owner_restriction/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)