diff --git a/mrp_workorder_sequence/README.rst b/mrp_workorder_sequence/README.rst new file mode 100644 index 000000000..6c7334d4c --- /dev/null +++ b/mrp_workorder_sequence/README.rst @@ -0,0 +1,93 @@ +======================= +MRP Work Order Sequence +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:88247a769791bc679d8530f09e56de26281610e2d493d1b663be3c3470b67c53 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/mrp_workorder_sequence + :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_workorder_sequence + :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| + +Provide a new field sequence on production orders's work orders, that provides +clear information on the process order of those. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to any production order with a routing set and check its work orders. + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Lois Rilo +* Pimolnat Suntian +* Christopher Ormaza +* Akim Juillerat + +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-LoisRForgeFlow| image:: https://github.com/LoisRForgeFlow.png?size=40px + :target: https://github.com/LoisRForgeFlow + :alt: LoisRForgeFlow + +Current `maintainer `__: + +|maintainer-LoisRForgeFlow| + +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_workorder_sequence/__init__.py b/mrp_workorder_sequence/__init__.py new file mode 100644 index 000000000..bb1838349 --- /dev/null +++ b/mrp_workorder_sequence/__init__.py @@ -0,0 +1,4 @@ +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import models +from .hooks import post_init_hook diff --git a/mrp_workorder_sequence/__manifest__.py b/mrp_workorder_sequence/__manifest__.py new file mode 100644 index 000000000..b229069c3 --- /dev/null +++ b/mrp_workorder_sequence/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "MRP Work Order Sequence", + "summary": "adds sequence to production work orders.", + "version": "16.0.0.1.0", + "category": "Manufacturing", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "development_status": "Beta", + "maintainers": ["LoisRForgeFlow"], + "website": "https://github.com/OCA/manufacture", + "license": "LGPL-3", + "depends": ["mrp"], + "data": ["views/mrp_workorder_view.xml"], + "installable": True, + "post_init_hook": "post_init_hook", +} diff --git a/mrp_workorder_sequence/hooks.py b/mrp_workorder_sequence/hooks.py new file mode 100644 index 000000000..c080cb29f --- /dev/null +++ b/mrp_workorder_sequence/hooks.py @@ -0,0 +1,19 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + + +def post_init_hook(cr, registry): + cr.execute( + """ + UPDATE mrp_workorder + SET sequence = n.sequence + FROM ( + SELECT + id, + ROW_NUMBER() OVER (PARTITION BY production_id) AS sequence + FROM mrp_workorder + ORDER BY production_id, id + ) AS n + WHERE mrp_workorder.id = n.id + """ + ) diff --git a/mrp_workorder_sequence/i18n/it.po b/mrp_workorder_sequence/i18n/it.po new file mode 100644 index 000000000..99a454638 --- /dev/null +++ b/mrp_workorder_sequence/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_workorder_sequence +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-05-15 19:35+0000\n" +"Last-Translator: Francesco Foresti \n" +"Language-Team: none\n" +"Language: it\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" +"X-Generator: Weblate 4.14.1\n" + +#. module: mrp_workorder_sequence +#: model:ir.model,name:mrp_workorder_sequence.model_mrp_production +msgid "Production Order" +msgstr "Ordine di produzione" + +#. module: mrp_workorder_sequence +#: model:ir.model.fields,field_description:mrp_workorder_sequence.field_mrp_workorder__sequence +msgid "Sequence" +msgstr "Sequenza" + +#. module: mrp_workorder_sequence +#: model:ir.model,name:mrp_workorder_sequence.model_mrp_workorder +msgid "Work Order" +msgstr "Ordine di lavoro" diff --git a/mrp_workorder_sequence/i18n/mrp_workorder_sequence.pot b/mrp_workorder_sequence/i18n/mrp_workorder_sequence.pot new file mode 100644 index 000000000..0d7810c68 --- /dev/null +++ b/mrp_workorder_sequence/i18n/mrp_workorder_sequence.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_workorder_sequence +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_workorder_sequence +#: model:ir.model,name:mrp_workorder_sequence.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: mrp_workorder_sequence +#: model:ir.model.fields,field_description:mrp_workorder_sequence.field_mrp_workorder__sequence +msgid "Sequence" +msgstr "" + +#. module: mrp_workorder_sequence +#: model:ir.model,name:mrp_workorder_sequence.model_mrp_workorder +msgid "Work Order" +msgstr "" diff --git a/mrp_workorder_sequence/models/__init__.py b/mrp_workorder_sequence/models/__init__.py new file mode 100644 index 000000000..5a0ba17ab --- /dev/null +++ b/mrp_workorder_sequence/models/__init__.py @@ -0,0 +1,2 @@ +from . import mrp_production +from . import mrp_workorder diff --git a/mrp_workorder_sequence/models/mrp_production.py b/mrp_workorder_sequence/models/mrp_production.py new file mode 100644 index 000000000..c2531fe65 --- /dev/null +++ b/mrp_workorder_sequence/models/mrp_production.py @@ -0,0 +1,23 @@ +# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + def _reset_work_order_sequence(self): + for rec in self: + for current_seq, work in enumerate(rec.workorder_ids, 1): + work.sequence = current_seq + + def _create_workorder(self): + # Bypass sequence assignation on create and make sure there is no gap + # using _reset_work_order_sequence + res = super( + MrpProduction, + self.with_context(_bypass_sequence_assignation_on_create=True), + )._create_workorder() + self._reset_work_order_sequence() + return res diff --git a/mrp_workorder_sequence/models/mrp_workorder.py b/mrp_workorder_sequence/models/mrp_workorder.py new file mode 100644 index 000000000..03e7c8036 --- /dev/null +++ b/mrp_workorder_sequence/models/mrp_workorder.py @@ -0,0 +1,42 @@ +# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class MrpWorkOrder(models.Model): + _inherit = "mrp.workorder" + _order = "production_id, sequence, id" + + sequence = fields.Integer() + + def _assign_sequence_on_create(self, values_list): + """Assign sequence number for manually added operations""" + new_wos_production_ids_without_seq = { + vals["production_id"] for vals in values_list if not vals.get("sequence") + } + if new_wos_production_ids_without_seq: + max_seq_by_production = self.read_group( + [("production_id", "in", list(new_wos_production_ids_without_seq))], + ["sequence:max", "production_id"], + ["production_id"], + ) + max_seq_by_prod_id = { + res["production_id"][0]: res["sequence"] + for res in max_seq_by_production + } + for values in values_list: + prod_id = values["production_id"] + values_seq = values.get("sequence") + max_seq = max_seq_by_prod_id.setdefault(prod_id, 0) + if values_seq and values_seq > max_seq: + max_seq_by_prod_id[prod_id] = values_seq + continue + max_seq_by_prod_id[prod_id] += 1 + values["sequence"] = max_seq_by_prod_id[prod_id] + + @api.model_create_multi + def create(self, values_list): + if not self.env.context.get("_bypass_sequence_assignation_on_create"): + self._assign_sequence_on_create(values_list) + return super().create(values_list) diff --git a/mrp_workorder_sequence/readme/CONTRIBUTORS.rst b/mrp_workorder_sequence/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..60325ea80 --- /dev/null +++ b/mrp_workorder_sequence/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Lois Rilo +* Pimolnat Suntian +* Christopher Ormaza +* Akim Juillerat diff --git a/mrp_workorder_sequence/readme/DESCRIPTION.rst b/mrp_workorder_sequence/readme/DESCRIPTION.rst new file mode 100644 index 000000000..38ab09bc0 --- /dev/null +++ b/mrp_workorder_sequence/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Provide a new field sequence on production orders's work orders, that provides +clear information on the process order of those. diff --git a/mrp_workorder_sequence/readme/USAGE.rst b/mrp_workorder_sequence/readme/USAGE.rst new file mode 100644 index 000000000..5067d94df --- /dev/null +++ b/mrp_workorder_sequence/readme/USAGE.rst @@ -0,0 +1 @@ +Go to any production order with a routing set and check its work orders. diff --git a/mrp_workorder_sequence/static/description/icon.png b/mrp_workorder_sequence/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_workorder_sequence/static/description/icon.png differ diff --git a/mrp_workorder_sequence/static/description/index.html b/mrp_workorder_sequence/static/description/index.html new file mode 100644 index 000000000..a0a747c76 --- /dev/null +++ b/mrp_workorder_sequence/static/description/index.html @@ -0,0 +1,432 @@ + + + + + + +MRP Work Order Sequence + + + +
+

MRP Work Order Sequence

+ + +

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

+

Provide a new field sequence on production orders’s work orders, that provides +clear information on the process order of those.

+

Table of contents

+ +
+

Usage

+

Go to any production order with a routing set and check its work orders.

+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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:

+

LoisRForgeFlow

+

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_workorder_sequence/tests/__init__.py b/mrp_workorder_sequence/tests/__init__.py new file mode 100644 index 000000000..01629ad73 --- /dev/null +++ b/mrp_workorder_sequence/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_workorder_sequence diff --git a/mrp_workorder_sequence/tests/test_mrp_workorder_sequence.py b/mrp_workorder_sequence/tests/test_mrp_workorder_sequence.py new file mode 100644 index 000000000..f9b12d98b --- /dev/null +++ b/mrp_workorder_sequence/tests/test_mrp_workorder_sequence.py @@ -0,0 +1,207 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import Command, fields +from odoo.tests import Form + +from odoo.addons.mrp.tests.common import TestMrpCommon + + +class TestMrpWorkorderSequence(TestMrpCommon): + def setUp(self): + super().setUp() + self._create_bom() + self.env["res.config.settings"].create( + { + "group_mrp_routings": True, + } + ).execute() + + def _create_bom(self): + return self.env["mrp.bom"].create( + { + "product_tmpl_id": self.product_7_template.id, + "product_uom_id": self.uom_unit.id, + "product_qty": 4.0, + "type": "normal", + "operation_ids": [ + Command.create( + { + "name": "Cutting Machine", + "workcenter_id": self.workcenter_1.id, + "time_cycle": 12, + "sequence": 1, + } + ), + Command.create( + { + "name": "Weld Machine", + "workcenter_id": self.workcenter_1.id, + "time_cycle": 18, + "sequence": 2, + "bom_product_template_attribute_value_ids": [ + Command.link(self.product_7_attr1_v1.id) + ], + } + ), + Command.create( + { + "name": "Taking a coffee", + "workcenter_id": self.workcenter_1.id, + "time_cycle": 5, + "sequence": 3, + "bom_product_template_attribute_value_ids": [ + Command.link(self.product_7_attr1_v2.id) + ], + } + ), + ], + "byproduct_ids": [ + Command.create( + { + "product_id": self.product_1.id, + "product_uom_id": self.product_1.uom_id.id, + "product_qty": 1, + } + ), + Command.create( + { + "product_id": self.product_2.id, + "product_uom_id": self.product_2.uom_id.id, + "product_qty": 1, + "bom_product_template_attribute_value_ids": [ + Command.link(self.product_7_attr1_v1.id) + ], + } + ), + Command.create( + { + "product_id": self.product_3.id, + "product_uom_id": self.product_3.uom_id.id, + "product_qty": 1, + "bom_product_template_attribute_value_ids": [ + Command.link(self.product_7_attr1_v2.id) + ], + } + ), + ], + "bom_line_ids": [ + Command.create( + { + "product_id": self.product_2.id, + "product_qty": 2, + } + ), + Command.create( + { + "product_id": self.product_3.id, + "product_qty": 2, + "bom_product_template_attribute_value_ids": [ + Command.link(self.product_7_attr1_v1.id) + ], + } + ), + Command.create( + { + "product_id": self.product_4.id, + "product_qty": 2, + "bom_product_template_attribute_value_ids": [ + Command.link(self.product_7_attr1_v2.id) + ], + } + ), + ], + } + ) + + def _create_order(self, product): + mrp_order_form = Form(self.env["mrp.production"]) + mrp_order_form.product_id = product + return mrp_order_form.save() + + def test_mrp_workorder_sequence_new_production(self): + mrp_order = self._create_order(self.product_7_1) + self.assertEqual(len(mrp_order.workorder_ids), 2) + for seq, workorder in enumerate(mrp_order.workorder_ids, 1): + self.assertEqual(workorder.sequence, seq) + + def test_mrp_workorder_sequence_new_production_new_workorder(self): + mrp_order = self._create_order(self.product_7_1) + self.assertEqual(len(mrp_order.workorder_ids), 2) + max_sequence = max(mrp_order.workorder_ids.mapped("sequence")) + mrp_order_form = Form(mrp_order) + with mrp_order_form.workorder_ids.new() as wo_form: + wo_form.name = "Extra operation" + wo_form.workcenter_id = self.workcenter_1 + mrp_order = mrp_order_form.save() + self.assertEqual(len(mrp_order.workorder_ids), 3) + last_wo = fields.first(mrp_order.workorder_ids.sorted(reverse=True)) + self.assertEqual(last_wo.sequence, max_sequence + 1) + + def test_mrp_workorder_create_multi(self): + """ + Test automatic sequence assignation through create override + + * WO 1: - each added operations without sequence defined + get the next sequence after existing WOs + * WO 2: - first added operation without sequence + get the next sequence after existing WOs + - second added operation with sequence defined stays unchanged + * WO 3: - first added operation with sequence defined stays unchanged + - second added operation without sequence defined + get the next sequence from previous operation created + """ + first_mrp_order = self._create_order(self.product_7_1) + second_mrp_order = self._create_order(self.product_7_1) + third_mrp_order = self._create_order(self.product_7_1) + create_values = [ + { + "name": "Extra WO 1.1", + "production_id": first_mrp_order.id, + "workcenter_id": self.workcenter_1.id, + "product_uom_id": self.product_7_1.uom_id.id, + }, + { + "name": "Extra WO 1.2", + "production_id": first_mrp_order.id, + "workcenter_id": self.workcenter_1.id, + "product_uom_id": self.product_7_1.uom_id.id, + }, + { + "name": "Extra WO 2.1", + "production_id": second_mrp_order.id, + "workcenter_id": self.workcenter_1.id, + "product_uom_id": self.product_7_1.uom_id.id, + }, + { + "name": "Extra WO 2.2", + "production_id": second_mrp_order.id, + "workcenter_id": self.workcenter_1.id, + "product_uom_id": self.product_7_1.uom_id.id, + "sequence": 6, + }, + { + "name": "Extra WO 3.1", + "production_id": third_mrp_order.id, + "workcenter_id": self.workcenter_1.id, + "sequence": 4, + "product_uom_id": self.product_7_1.uom_id.id, + }, + { + "name": "Extra WO 3.2", + "production_id": third_mrp_order.id, + "workcenter_id": self.workcenter_1.id, + "product_uom_id": self.product_7_1.uom_id.id, + }, + ] + created_wos = self.env["mrp.workorder"].create(create_values) + expected_res = { + "Extra WO 1.1": 3, + "Extra WO 1.2": 4, + "Extra WO 2.1": 3, + "Extra WO 2.2": 6, + "Extra WO 3.1": 4, + "Extra WO 3.2": 5, + } + for wo in created_wos: + self.assertEqual(wo.sequence, expected_res[wo.name]) diff --git a/mrp_workorder_sequence/views/mrp_workorder_view.xml b/mrp_workorder_sequence/views/mrp_workorder_view.xml new file mode 100644 index 000000000..2514a7493 --- /dev/null +++ b/mrp_workorder_sequence/views/mrp_workorder_view.xml @@ -0,0 +1,16 @@ + + + + mrp.workorder.tree + mrp.workorder + + + + + + + + diff --git a/setup/mrp_workorder_sequence/odoo/addons/mrp_workorder_sequence b/setup/mrp_workorder_sequence/odoo/addons/mrp_workorder_sequence new file mode 120000 index 000000000..413aae71c --- /dev/null +++ b/setup/mrp_workorder_sequence/odoo/addons/mrp_workorder_sequence @@ -0,0 +1 @@ +../../../../mrp_workorder_sequence \ No newline at end of file diff --git a/setup/mrp_workorder_sequence/setup.py b/setup/mrp_workorder_sequence/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_workorder_sequence/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)