diff --git a/mrp_subcontracting_bom_dual_use/README.rst b/mrp_subcontracting_bom_dual_use/README.rst new file mode 100644 index 000000000..be3d6b17d --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/README.rst @@ -0,0 +1,91 @@ +=============================== +Mrp subcontracting bom dual use +=============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/14.0/mrp_subcontracting_bom_dual_use + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_subcontracting_bom_dual_use + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/129/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows subcontracting BOMs to be used for regular production orders as well. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Go to *Manufacturing > Products > Bill of materials* and create a new one with type = "Subcontracting". +#. Check "Allow in regular production". +#. Try to manufacture the product, and you will be able to use the previously created bill of materials. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza + +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-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +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_subcontracting_bom_dual_use/__init__.py b/mrp_subcontracting_bom_dual_use/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_subcontracting_bom_dual_use/__manifest__.py b/mrp_subcontracting_bom_dual_use/__manifest__.py new file mode 100644 index 000000000..a0c1e5425 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Mrp subcontracting bom dual use", + "version": "14.0.1.0.0", + "category": "Manufacturing", + "website": "https://github.com/OCA/manufacture", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["mrp_subcontracting"], + "installable": True, + "data": ["views/mrp_bom_view.xml"], + "maintainers": ["victoralmau"], +} diff --git a/mrp_subcontracting_bom_dual_use/i18n/es.po b/mrp_subcontracting_bom_dual_use/i18n/es.po new file mode 100644 index 000000000..30b27d188 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/i18n/es.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_subcontracting_bom_dual_use +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-08-16 15:24+0000\n" +"PO-Revision-Date: 2022-08-16 17:25+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.3\n" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom__allow_in_regular_production +msgid "Allow in regular production" +msgstr "Permitir en fabricaciones reguales" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model,name:mrp_subcontracting_bom_dual_use.model_mrp_bom +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production__bom_id +msgid "Bill of Material" +msgstr "Lista de materiales" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,help:mrp_subcontracting_bom_dual_use.field_mrp_production__bom_id +msgid "" +"Bill of Materials allow you to define the list of required components to " +"make a finished product." +msgstr "" +"La lista de materiales le permite definir la lista de componentes necesarios " +"para hacer un producto terminado." + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom__id +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production__id +msgid "ID" +msgstr "ID" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model,name:mrp_subcontracting_bom_dual_use.model_mrp_production +msgid "Production Order" +msgstr "Orden de producción" diff --git a/mrp_subcontracting_bom_dual_use/i18n/mrp_subcontracting_bom_dual_use.pot b/mrp_subcontracting_bom_dual_use/i18n/mrp_subcontracting_bom_dual_use.pot new file mode 100644 index 000000000..384b97ec9 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/i18n/mrp_subcontracting_bom_dual_use.pot @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_subcontracting_bom_dual_use +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-08-16 15:24+0000\n" +"PO-Revision-Date: 2022-08-16 15:24+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_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom__allow_in_regular_production +msgid "Allow in regular production" +msgstr "" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model,name:mrp_subcontracting_bom_dual_use.model_mrp_bom +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production__bom_id +msgid "Bill of Material" +msgstr "" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,help:mrp_subcontracting_bom_dual_use.field_mrp_production__bom_id +msgid "" +"Bill of Materials allow you to define the list of required components to " +"make a finished product." +msgstr "" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom__display_name +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom__id +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production__id +msgid "ID" +msgstr "" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_bom____last_update +#: model:ir.model.fields,field_description:mrp_subcontracting_bom_dual_use.field_mrp_production____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_subcontracting_bom_dual_use +#: model:ir.model,name:mrp_subcontracting_bom_dual_use.model_mrp_production +msgid "Production Order" +msgstr "" diff --git a/mrp_subcontracting_bom_dual_use/models/__init__.py b/mrp_subcontracting_bom_dual_use/models/__init__.py new file mode 100644 index 000000000..18499c583 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import mrp_bom +from . import mrp_production diff --git a/mrp_subcontracting_bom_dual_use/models/mrp_bom.py b/mrp_subcontracting_bom_dual_use/models/mrp_bom.py new file mode 100644 index 000000000..b4c8efbad --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/models/mrp_bom.py @@ -0,0 +1,39 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class MrpBom(models.Model): + _inherit = "mrp.bom" + + allow_in_regular_production = fields.Boolean(string="Allow in regular production") + + @api.model + def _bom_find_domain( + self, + product_tmpl=None, + product=None, + picking_type=None, + company_id=False, + bom_type=False, + ): + """We need to overwrite the domain to get subcontract boms""" + domain = super()._bom_find_domain( + product_tmpl=product_tmpl, + product=product, + picking_type=picking_type, + company_id=company_id, + bom_type=bom_type, + ) + if bom_type == "normal": + domain_old = ("type", "=", "normal") + domain_new = [ + "|", + domain_old, + "&", + ("type", "=", "subcontract"), + ("allow_in_regular_production", "=", True), + ] + index = domain.index(domain_old) + domain = domain[:index] + domain_new + domain[index + 1 :] + return domain diff --git a/mrp_subcontracting_bom_dual_use/models/mrp_production.py b/mrp_subcontracting_bom_dual_use/models/mrp_production.py new file mode 100644 index 000000000..4ebcd4fbe --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/models/mrp_production.py @@ -0,0 +1,27 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + # Overwrite the field domain for adding subcontracting BoMs with the check + bom_id = fields.Many2one( + domain="""[ + '&', + '|', + ('company_id', '=', False), + ('company_id', '=', company_id), + '&', + '|', + ('product_id','=',product_id), + '&', + ('product_tmpl_id.product_variant_ids','=',product_id), + ('product_id','=',False), + '|', + ('type', '=', 'normal'), + '&', ('type', '=', 'subcontract'), ('allow_in_regular_production', '=', True) + ]""", + ) diff --git a/mrp_subcontracting_bom_dual_use/readme/CONTRIBUTORS.rst b/mrp_subcontracting_bom_dual_use/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..5fb713053 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza diff --git a/mrp_subcontracting_bom_dual_use/readme/DESCRIPTION.rst b/mrp_subcontracting_bom_dual_use/readme/DESCRIPTION.rst new file mode 100644 index 000000000..6620a6d78 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows subcontracting BOMs to be used for regular production orders as well. diff --git a/mrp_subcontracting_bom_dual_use/readme/USAGE.rst b/mrp_subcontracting_bom_dual_use/readme/USAGE.rst new file mode 100644 index 000000000..43b936386 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/readme/USAGE.rst @@ -0,0 +1,3 @@ +#. Go to *Manufacturing > Products > Bill of materials* and create a new one with type = "Subcontracting". +#. Check "Allow in regular production". +#. Try to manufacture the product, and you will be able to use the previously created bill of materials. diff --git a/mrp_subcontracting_bom_dual_use/static/description/icon.png b/mrp_subcontracting_bom_dual_use/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_subcontracting_bom_dual_use/static/description/icon.png differ diff --git a/mrp_subcontracting_bom_dual_use/static/description/index.html b/mrp_subcontracting_bom_dual_use/static/description/index.html new file mode 100644 index 000000000..b195b1dab --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Mrp subcontracting bom dual use + + + +
+

Mrp subcontracting bom dual use

+ + +

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

+

This module allows subcontracting BOMs to be used for regular production orders as well.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Manufacturing > Products > Bill of materials and create a new one with type = “Subcontracting”.
  2. +
  3. Check “Allow in regular production”.
  4. +
  5. Try to manufacture the product, and you will be able to use the previously created bill of materials.
  6. +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Víctor Martínez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

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:

+

victoralmau

+

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_subcontracting_bom_dual_use/tests/__init__.py b/mrp_subcontracting_bom_dual_use/tests/__init__.py new file mode 100644 index 000000000..a595755fd --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_mrp_subcontracting_bom_dual_use diff --git a/mrp_subcontracting_bom_dual_use/tests/test_mrp_subcontracting_bom_dual_use.py b/mrp_subcontracting_bom_dual_use/tests/test_mrp_subcontracting_bom_dual_use.py new file mode 100644 index 000000000..dca8443a1 --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/tests/test_mrp_subcontracting_bom_dual_use.py @@ -0,0 +1,68 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests import Form, common + + +class TestMrpSubcontractingBomDualUse(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.manufacture_route = cls.env.ref("mrp.route_warehouse0_manufacture") + cls.partner = cls.env["res.partner"].create({"name": "Mr Odoo"}) + cls.product = cls.env["product.product"].create( + { + "name": "Test product", + "type": "product", + "route_ids": [(6, 0, [cls.manufacture_route.id])], + } + ) + cls.component_a = cls.env["product.product"].create({"name": "Test Comp A"}) + cls.mrp_production_model = cls.env["mrp.production"] + + def _create_bom(self, bom_type): + mrp_bom_form = Form(self.env["mrp.bom"]) + mrp_bom_form.product_tmpl_id = self.product.product_tmpl_id + mrp_bom_form.type = bom_type + if bom_type == "subcontract": + mrp_bom_form.subcontractor_ids.add(self.partner) + mrp_bom_form.allow_in_regular_production = True + mrp_bom_form.product_tmpl_id = self.product.product_tmpl_id + with mrp_bom_form.bom_line_ids.new() as line_form: + line_form.product_id = self.component_a + line_form.product_qty = 1 + + return mrp_bom_form.save() + + def test_mrp_production_misc_bom_normal(self): + """We create a BOM of normal type. We create a production order and assign + the product to check that the BOM is assigned correctly.""" + bom = self._create_bom("normal") + mrp_production_form = Form(self.mrp_production_model) + mrp_production_form.product_id = self.product + self.assertEqual(mrp_production_form.bom_id, bom) + self.assertTrue(mrp_production_form.move_raw_ids) + + def test_mrp_production_misc_bom_subcontract(self): + """We create a BOM of subcontract type. We create a production order and assign + the product to check that the BOM is assigned correctly.""" + bom = self._create_bom("subcontract") + mrp_production_form = Form(self.mrp_production_model) + mrp_production_form.product_id = self.product + self.assertEqual(mrp_production_form.bom_id, bom) + self.assertTrue(mrp_production_form.move_raw_ids) + + def _product_replenish(self, product, qty): + replenish_form = Form( + self.env["product.replenish"].with_context(default_product_id=product.id) + ) + replenish_form.quantity = qty + replenish = replenish_form.save() + replenish.launch_replenishment() + + def test_product_replenish(self): + """We create a bill of materials of subcontract type. We run replenish and + validate that the production order has been created with the correct BOM.""" + bom = self._create_bom("subcontract") + self._product_replenish(self.product, 1) + item = self.mrp_production_model.search([("product_id", "=", self.product.id)]) + self.assertEqual(item.bom_id, bom) diff --git a/mrp_subcontracting_bom_dual_use/views/mrp_bom_view.xml b/mrp_subcontracting_bom_dual_use/views/mrp_bom_view.xml new file mode 100644 index 000000000..815f0ca2c --- /dev/null +++ b/mrp_subcontracting_bom_dual_use/views/mrp_bom_view.xml @@ -0,0 +1,15 @@ + + + mrp.bom.form + mrp.bom + + + + + + + + diff --git a/setup/mrp_subcontracting_bom_dual_use/odoo/addons/mrp_subcontracting_bom_dual_use b/setup/mrp_subcontracting_bom_dual_use/odoo/addons/mrp_subcontracting_bom_dual_use new file mode 120000 index 000000000..88ca80b68 --- /dev/null +++ b/setup/mrp_subcontracting_bom_dual_use/odoo/addons/mrp_subcontracting_bom_dual_use @@ -0,0 +1 @@ +../../../../mrp_subcontracting_bom_dual_use \ No newline at end of file diff --git a/setup/mrp_subcontracting_bom_dual_use/setup.py b/setup/mrp_subcontracting_bom_dual_use/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_subcontracting_bom_dual_use/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)