diff --git a/mrp_bom_tracking/README.rst b/mrp_bom_tracking/README.rst new file mode 100644 index 000000000..7e10e1697 --- /dev/null +++ b/mrp_bom_tracking/README.rst @@ -0,0 +1,75 @@ +================ +MRP BoM Tracking +================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/12.0/mrp_bom_tracking + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-12-0/manufacture-12-0-mrp_bom_tracking + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds track visibility to some fields of mrp boms. Also, +it log notes for any change in the bom lines (components). + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Eficent + +Contributors +~~~~~~~~~~~~ + +* Miquel Raïch +* Lois Rilo + +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_bom_tracking/__init__.py b/mrp_bom_tracking/__init__.py new file mode 100644 index 000000000..2bc1433e7 --- /dev/null +++ b/mrp_bom_tracking/__init__.py @@ -0,0 +1,3 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import models diff --git a/mrp_bom_tracking/__manifest__.py b/mrp_bom_tracking/__manifest__.py new file mode 100644 index 000000000..7e3618d61 --- /dev/null +++ b/mrp_bom_tracking/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +{ + "name": "MRP BoM Tracking", + "version": "13.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "summary": "Logs any change to a BoM in the chatter", + "website": "https://github.com/OCA/manufacture", + "category": "Manufacturing", + "depends": ["mrp"], + "data": ["views/bom_template.xml"], + "license": "LGPL-3", + "installable": True, +} diff --git a/mrp_bom_tracking/i18n/de.po b/mrp_bom_tracking/i18n/de.po new file mode 100644 index 000000000..00db1f6de --- /dev/null +++ b/mrp_bom_tracking/i18n/de.po @@ -0,0 +1,104 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_tracking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template_2 +msgid ":\n" +" New component
" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template_2 +msgid ":\n" +" Removed component
" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_line_template +msgid "
\n" +" Product Unit of Measure:" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_line_template +msgid "The component quantities or UoMs have been updated." +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template_2 +msgid "The components have changed." +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model,name:mrp_bom_tracking.model_mrp_bom +msgid "Bill of Material" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model,name:mrp_bom_tracking.model_mrp_bom_line +msgid "Bill of Material Line" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__type +msgid "BoM Type" +msgstr "" + +#. module: mrp_bom_tracking +#: selection:mrp.bom,type:0 +msgid "Kit" +msgstr "" + +#. module: mrp_bom_tracking +#: selection:mrp.bom,type:0 +msgid "Manufacture this product" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__picking_type_id +msgid "Operation Type" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__product_tmpl_id +msgid "Product" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_line_template +msgid "Product Quantity:" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__product_qty +msgid "Quantity" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__code +msgid "Reference" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,help:mrp_bom_tracking.field_mrp_bom__picking_type_id +msgid "When a procurement has a ‘produce’ route with a operation type set, it will try to create a Manufacturing Order for that product using a BoM of the same operation type. That allows to define stock rules which trigger different manufacturing orders with different BoMs." +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template +msgid "component
" +msgstr "" diff --git a/mrp_bom_tracking/i18n/mrp_bom_tracking.pot b/mrp_bom_tracking/i18n/mrp_bom_tracking.pot new file mode 100644 index 000000000..03993d2b4 --- /dev/null +++ b/mrp_bom_tracking/i18n/mrp_bom_tracking.pot @@ -0,0 +1,104 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_tracking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \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_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template_2 +msgid ":\n" +" New component
" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template_2 +msgid ":\n" +" Removed component
" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_line_template +msgid "
\n" +" Product Unit of Measure:" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_line_template +msgid "The component quantities or UoMs have been updated." +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template_2 +msgid "The components have changed." +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model,name:mrp_bom_tracking.model_mrp_bom +msgid "Bill of Material" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model,name:mrp_bom_tracking.model_mrp_bom_line +msgid "Bill of Material Line" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__type +msgid "BoM Type" +msgstr "" + +#. module: mrp_bom_tracking +#: selection:mrp.bom,type:0 +msgid "Kit" +msgstr "" + +#. module: mrp_bom_tracking +#: selection:mrp.bom,type:0 +msgid "Manufacture this product" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__picking_type_id +msgid "Operation Type" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__product_tmpl_id +msgid "Product" +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_line_template +msgid "Product Quantity:" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__product_qty +msgid "Quantity" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,field_description:mrp_bom_tracking.field_mrp_bom__code +msgid "Reference" +msgstr "" + +#. module: mrp_bom_tracking +#: model:ir.model.fields,help:mrp_bom_tracking.field_mrp_bom__picking_type_id +msgid "When a procurement has a ‘produce’ route with a operation type set, it will try to create a Manufacturing Order for that product using a BoM of the same operation type. That allows to define stock rules which trigger different manufacturing orders with different BoMs." +msgstr "" + +#. module: mrp_bom_tracking +#: model_terms:ir.ui.view,arch_db:mrp_bom_tracking.track_bom_template +msgid "component
" +msgstr "" + diff --git a/mrp_bom_tracking/models/__init__.py b/mrp_bom_tracking/models/__init__.py new file mode 100644 index 000000000..0a5998e00 --- /dev/null +++ b/mrp_bom_tracking/models/__init__.py @@ -0,0 +1,3 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import mrp_bom diff --git a/mrp_bom_tracking/models/mrp_bom.py b/mrp_bom_tracking/models/mrp_bom.py new file mode 100644 index 000000000..11b08307b --- /dev/null +++ b/mrp_bom_tracking/models/mrp_bom.py @@ -0,0 +1,83 @@ +# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class MrpBom(models.Model): + _inherit = "mrp.bom" + + code = fields.Char(tracking=True) + product_id = fields.Many2one(tracking=True) + product_tmpl_id = fields.Many2one(tracking=True) + product_qty = fields.Float(tracking=True) + picking_type_id = fields.Many2one(tracking=True) + type = fields.Selection(tracking=True) + + def write(self, values): + bom_line_ids = {} + if "bom_line_ids" in values: + for bom in self: + del_lines = [] + for line in values["bom_line_ids"]: + if line[0] == 2: + del_lines.append(line[1]) + if del_lines: + bom.message_post_with_view( + "mrp_bom_tracking.track_bom_template", + values={ + "lines": self.env["mrp.bom.line"].browse(del_lines), + "mode": "Removed", + }, + subtype_id=self.env.ref("mail.mt_note").id, + ) + bom_line_ids[bom.id] = bom.bom_line_ids + res = super(MrpBom, self).write(values) + if "bom_line_ids" in values: + for bom in self: + new_lines = bom.bom_line_ids - bom_line_ids[bom.id] + if new_lines: + bom.message_post_with_view( + "mrp_bom_tracking.track_bom_template", + values={"lines": new_lines, "mode": "New"}, + subtype_id=self.env.ref("mail.mt_note").id, + ) + return res + + +class MrpBomLine(models.Model): + _inherit = "mrp.bom.line" + + def write(self, values): + if "product_id" in values: + for bom in self.mapped("bom_id"): + lines = self.filtered(lambda l: l.bom_id == bom) + product_id = values.get("product_id") + if product_id: + product_id = self.env["product.product"].browse(product_id) + product_id = product_id or lines.product_id + if lines: + bom.message_post_with_view( + "mrp_bom_tracking.track_bom_template_2", + values={"lines": lines, "product_id": product_id}, + subtype_id=self.env.ref("mail.mt_note").id, + ) + elif "product_qty" in values or "product_uom_id" in values: + for bom in self.mapped("bom_id"): + lines = self.filtered(lambda l: l.bom_id == bom) + if lines: + product_qty = values.get("product_qty") or lines.product_qty + product_uom_id = values.get("product_uom_id") + if product_uom_id: + product_uom_id = self.env["product.uom"].browse(product_uom_id) + product_uom_id = product_uom_id or lines.product_uom_id + bom.message_post_with_view( + "mrp_bom_tracking.track_bom_line_template", + values={ + "lines": lines, + "product_qty": product_qty, + "product_uom_id": product_uom_id, + }, + subtype_id=self.env.ref("mail.mt_note").id, + ) + return super(MrpBomLine, self).write(values) diff --git a/mrp_bom_tracking/readme/CONTRIBUTORS.rst b/mrp_bom_tracking/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..cd27f7adc --- /dev/null +++ b/mrp_bom_tracking/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Miquel Raïch +* Lois Rilo +* Joan Sisquella diff --git a/mrp_bom_tracking/readme/DESCRIPTION.rst b/mrp_bom_tracking/readme/DESCRIPTION.rst new file mode 100644 index 000000000..bee5ea567 --- /dev/null +++ b/mrp_bom_tracking/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module adds track visibility to some fields of mrp boms. Also, +it log notes for any change in the bom lines (components). diff --git a/mrp_bom_tracking/static/description/icon.png b/mrp_bom_tracking/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_bom_tracking/static/description/icon.png differ diff --git a/mrp_bom_tracking/static/description/index.html b/mrp_bom_tracking/static/description/index.html new file mode 100644 index 000000000..354d21500 --- /dev/null +++ b/mrp_bom_tracking/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +MRP BoM Tracking + + + +
+

MRP BoM Tracking

+ + +

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

+

This module adds track visibility to some fields of mrp boms. Also, +it log notes for any change in the bom lines (components).

+

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

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Eficent
  • +
+
+
+

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_bom_tracking/tests/__init__.py b/mrp_bom_tracking/tests/__init__.py new file mode 100644 index 000000000..00f486a4e --- /dev/null +++ b/mrp_bom_tracking/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_bom_tracking diff --git a/mrp_bom_tracking/tests/test_mrp_bom_tracking.py b/mrp_bom_tracking/tests/test_mrp_bom_tracking.py new file mode 100644 index 000000000..a1595e29f --- /dev/null +++ b/mrp_bom_tracking/tests/test_mrp_bom_tracking.py @@ -0,0 +1,46 @@ +# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com) +# - Lois Rilo +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests import common + + +class TestBomTracking(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.product_obj = cls.env["product.product"] + cls.bom_obj = cls.env["mrp.bom"] + cls.bom_line_obj = cls.env["mrp.bom.line"] + + # Create products: + cls.product_1 = cls.product_obj.create({"name": "TEST 01", "type": "product"}) + cls.component_1 = cls.product_obj.create({"name": "RM 01", "type": "product"}) + cls.component_2 = cls.product_obj.create({"name": "RM 02", "type": "product"}) + cls.component_2_alt = cls.product_obj.create( + {"name": "RM 02-B", "type": "product"} + ) + + # Create Bills of Materials: + cls.bom = cls.bom_obj.create( + {"product_tmpl_id": cls.product_1.product_tmpl_id.id} + ) + cls.line_1 = cls.bom_line_obj.create( + {"product_id": cls.component_1.id, "bom_id": cls.bom.id, "product_qty": 2.0} + ) + cls.line_2 = cls.bom_line_obj.create( + {"product_id": cls.component_2.id, "bom_id": cls.bom.id, "product_qty": 5.0} + ) + + def test_01_change_bom_line_qty(self): + before = self.bom.message_ids + self.line_1.product_qty = 3.0 + after = self.bom.message_ids + self.assertEqual(len(after - before), 1) + + def test_02_change_bom_line_product(self): + before = self.bom.message_ids + self.line_2.product_id = self.component_2_alt + after = self.bom.message_ids + self.assertEqual(len(after - before), 1) diff --git a/mrp_bom_tracking/views/bom_template.xml b/mrp_bom_tracking/views/bom_template.xml new file mode 100644 index 000000000..ae3cb803a --- /dev/null +++ b/mrp_bom_tracking/views/bom_template.xml @@ -0,0 +1,45 @@ + + + + + + + + + +