diff --git a/mrp_routing/README.rst b/mrp_routing/README.rst new file mode 100644 index 000000000..82d8d2cb6 --- /dev/null +++ b/mrp_routing/README.rst @@ -0,0 +1,107 @@ +=========== +MRP Routing +=========== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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/14.0/mrp_routing + :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_routing + :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 adds routing concept as predefined operations, +operations should work as templates of operations on BOMs + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +You can add Routings on Manufacture / Products / Routings + +#. Create new Route +#. Add Operations + Operations its a copy of current operations on BOM, + with field "On template change?", this is Sync as default, + in this mode every change on this template is propagated + on operations related with this template + +Configure BOM and and Operations Page you can select predefined route (there are two ways to configure with templates) + - You can select a predefined route, + and this action replace and populate with templates associate + - Or You can add operations and select operation + as template to help setting default data + +On both configurations you can set field "On template change?" that change behavior when template related perform changes on data + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Christopher Ormaza + +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-ChrisOForgeFlow| image:: https://github.com/ChrisOForgeFlow.png?size=40px + :target: https://github.com/ChrisOForgeFlow + :alt: ChrisOForgeFlow + +Current `maintainer `__: + +|maintainer-ChrisOForgeFlow| + +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_routing/__init__.py b/mrp_routing/__init__.py new file mode 100644 index 000000000..313fda46a --- /dev/null +++ b/mrp_routing/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2021 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/mrp_routing/__manifest__.py b/mrp_routing/__manifest__.py new file mode 100644 index 000000000..c32953388 --- /dev/null +++ b/mrp_routing/__manifest__.py @@ -0,0 +1,27 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "MRP Routing", + "version": "14.0.1.0.0", + "category": "Manufacturing", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "license": "AGPL-3", + "maintainers": ["ChrisOForgeFlow"], + "development_status": "Alpha", + "depends": [ + "mrp", + ], + "data": [ + "data/sequence_data.xml", + "security/ir.model.access.csv", + "views/mrp_bom_view.xml", + "views/mrp_routing_view.xml", + "views/mrp_routing_workcenter_view.xml", + "views/mrp_routing_workcenter_template_view.xml", + ], + "demo": [ + "demo/routing_data.xml", + ], + "installable": True, +} diff --git a/mrp_routing/data/sequence_data.xml b/mrp_routing/data/sequence_data.xml new file mode 100644 index 000000000..e2492e088 --- /dev/null +++ b/mrp_routing/data/sequence_data.xml @@ -0,0 +1,17 @@ + + + + + + Routing + mrp.routing + RO/ + 5 + 1 + 1 + + + + + + diff --git a/mrp_routing/demo/routing_data.xml b/mrp_routing/demo/routing_data.xml new file mode 100644 index 000000000..f9020a568 --- /dev/null +++ b/mrp_routing/demo/routing_data.xml @@ -0,0 +1,116 @@ + + + + + + + Manual Assembly + 60 + 5 + pdf + + + + + + Long time assembly + 180 + 15 + pdf + + + + + + Testing + 60 + 10 + pdf + + + + + + Packing + 30 + 5 + pdf + + + + + + 120 + 5 + Manual Assembly + pdf + + + + + + 120 + 10 + Assembly Line 1 + pdf + + + + + Primary Assembly + + + + + Secondary Assembly + + + + + Manual Component's Assembly + + + + + Assemble Furniture + + + + + diff --git a/mrp_routing/i18n/mrp_routing.pot b/mrp_routing/i18n/mrp_routing.pot new file mode 100644 index 000000000..e69de29bb diff --git a/mrp_routing/models/__init__.py b/mrp_routing/models/__init__.py new file mode 100644 index 000000000..fa547adcd --- /dev/null +++ b/mrp_routing/models/__init__.py @@ -0,0 +1,7 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import mrp_routing_workcenter_template +from . import mrp_routing +from . import mrp_bom +from . import mrp_routing_workcenter diff --git a/mrp_routing/models/mrp_bom.py b/mrp_routing/models/mrp_bom.py new file mode 100644 index 000000000..adb45db24 --- /dev/null +++ b/mrp_routing/models/mrp_bom.py @@ -0,0 +1,38 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + +from .mrp_routing_workcenter_template import FIELDS_TO_SYNC + + +class MrpBom(models.Model): + + _inherit = "mrp.bom" + + routing_id = fields.Many2one( + comodel_name="mrp.routing", + string="Predefined Operations", + check_company=True, + tracking=True, + ) + + @api.onchange("routing_id") + def onchange_routing_id(self): + opeartion_model = self.env["mrp.routing.workcenter"] + if self.routing_id and self.routing_id.operation_ids: + new_operations = opeartion_model.browse() + for template_operation in self.routing_id.operation_ids: + operation_data = template_operation.read( + FIELDS_TO_SYNC, load="_classic_write" + )[0] + operation_data.pop("id") + if "operation_ids" in operation_data: + operation_data.pop("operation_ids") + operation_data.update( + { + "template_id": template_operation.id, + "on_template_change": "sync", + } + ) + new_operations |= opeartion_model.new(operation_data) + self.operation_ids = new_operations diff --git a/mrp_routing/models/mrp_routing.py b/mrp_routing/models/mrp_routing.py new file mode 100644 index 000000000..3209d2f09 --- /dev/null +++ b/mrp_routing/models/mrp_routing.py @@ -0,0 +1,60 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, fields, models + + +class MrpRouting(models.Model): + + _name = "mrp.routing" + _description = "Manufacturing Routing" + + name = fields.Char("Routing", required=True) + active = fields.Boolean( + "Active", + default=True, + help="If the active field is set to False, " + "it will allow you to hide the routing without removing it.", + ) + code = fields.Char( + "Reference", copy=False, default=lambda self: _("New"), readonly=True + ) + note = fields.Text("Description") + operation_ids = fields.Many2many( + comodel_name="mrp.routing.workcenter.template", string="Operations" + ) + company_id = fields.Many2one( + "res.company", "Company", default=lambda self: self.env.company + ) + bom_ids = fields.One2many( + comodel_name="mrp.bom", + inverse_name="routing_id", + string="Boms", + required=False, + copy=False, + ) + + @api.model + def create(self, vals): + if "code" not in vals or vals["code"] == _("New"): + vals["code"] = self.env["ir.sequence"].next_by_code("mrp.routing") or _( + "New" + ) + return super(MrpRouting, self).create(vals) + + def write(self, values): + res = super(MrpRouting, self).write(values) + if "operation_ids" in values: + for rec in self: + for bom in rec.bom_ids: + operations_not_synced = ( + rec.operation_ids - bom.operation_ids.mapped("template_id") + ) + for operation in operations_not_synced: + operation.create_operation_from_template(bom) + operations_to_delete = bom.operation_ids.filtered( + lambda x: x.template_id.id not in rec.operation_ids.ids + ) + if operations_to_delete: + operations_to_delete.unlink() + return res diff --git a/mrp_routing/models/mrp_routing_workcenter.py b/mrp_routing/models/mrp_routing_workcenter.py new file mode 100644 index 000000000..ec28e0381 --- /dev/null +++ b/mrp_routing/models/mrp_routing_workcenter.py @@ -0,0 +1,35 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + +from .mrp_routing_workcenter_template import FIELDS_TO_SYNC + + +class MrpRoutingWorkcenter(models.Model): + + _inherit = "mrp.routing.workcenter" + + template_id = fields.Many2one( + comodel_name="mrp.routing.workcenter.template", + string="Template", + readonly=False, + ) + + on_template_change = fields.Selection( + string="On template change?", + selection=[ + ("nothing", "Do nothing"), + ("sync", "Sync"), + ], + required=False, + default="sync", + ) + + @api.onchange("template_id") + def onchange_template_id(self): + if self.template_id: + to_update_data = self.template_id.read( + FIELDS_TO_SYNC, load="_classic_wirte" + )[0] + to_update_data.pop("id") + self.update(to_update_data) diff --git a/mrp_routing/models/mrp_routing_workcenter_template.py b/mrp_routing/models/mrp_routing_workcenter_template.py new file mode 100644 index 000000000..9a60a9829 --- /dev/null +++ b/mrp_routing/models/mrp_routing_workcenter_template.py @@ -0,0 +1,132 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + +FIELDS_TO_SYNC = [ + "name", + "workcenter_id", + "sequence", + "worksheet_type", + "note", + "worksheet", + "worksheet_google_slide", + "time_mode", + "time_mode_batch", + "time_cycle_manual", + "on_template_change", +] + + +class MrpRoutingWorkcenterTemplate(models.Model): + + _name = "mrp.routing.workcenter.template" + _description = "Template Work Center Usage" + _order = "sequence, id" + _check_company_auto = True + + name = fields.Char("Operation", required=True) + workcenter_id = fields.Many2one( + "mrp.workcenter", "Work Center", required=True, check_company=True + ) + sequence = fields.Integer( + "Sequence", + default=100, + help="Gives the sequence order when displaying a list of routing Work Centers.", + ) + company_id = fields.Many2one( + "res.company", "Company", default=lambda self: self.env.company + ) + worksheet_type = fields.Selection( + [("pdf", "PDF"), ("google_slide", "Google Slide"), ("text", "Text")], + string="Work Sheet", + default="text", + help="Defines if you want to use a PDF " "or a Google Slide as work sheet.", + ) + note = fields.Text("Description", help="Text worksheet description") + worksheet = fields.Binary("PDF") + worksheet_google_slide = fields.Char( + "Google Slide", + help="Paste the url of your Google Slide. " + "Make sure the access to the document is public.", + ) + time_mode = fields.Selection( + [ + ("auto", "Compute based on tracked time"), + ("manual", "Set duration manually"), + ], + string="Duration Computation", + default="manual", + ) + time_mode_batch = fields.Integer("Based on", default=10) + time_cycle_manual = fields.Float( + "Manual Duration", + default=60, + help="Time in minutes:" + "- In manual mode, time used" + "- In automatic mode, " + "supposed first time when there aren't any work orders yet", + ) + operation_ids = fields.One2many( + comodel_name="mrp.routing.workcenter", + inverse_name="template_id", + string="Operations", + required=False, + copy=False, + ) + on_template_change = fields.Selection( + string="On template change?", + selection=[ + ("nothing", "Do nothing"), + ("sync", "Sync"), + ], + required=False, + default="sync", + ) + routing_ids = fields.Many2many(comodel_name="mrp.routing", string="Routings") + + def create_operation_from_template(self, bom): + operation_model = self.env["mrp.routing.workcenter"] + for operation in self: + operation_data = operation.read(FIELDS_TO_SYNC, load="_classic_write")[0] + operation_data.update( + { + "bom_id": bom.id, + "template_id": operation.id, + "on_template_change": "sync", + } + ) + operation_model.create(operation_data) + + @api.model_create_multi + def create(self, values): + recs = super(MrpRoutingWorkcenterTemplate, self).create(values) + for rec in self: + for bom in rec.mapped("routing_ids.bom_ids"): + rec.create_operation_from_template(bom) + return recs + + def unlink(self): + for rec in self: + synced_records = rec.operation_ids.filtered( + lambda x: x.on_template_change == "sync" + ) + if synced_records: + synced_records.unlink() + return super(MrpRoutingWorkcenterTemplate, self).unlink() + + def write(self, values): + res = super(MrpRoutingWorkcenterTemplate, self).write(values) + current_field_changes = [] + for field_name in FIELDS_TO_SYNC: + if field_name in values.keys(): + current_field_changes.append(field_name) + if current_field_changes: + for rec in self.filtered(lambda x: x.operation_ids): + to_write_data = rec.read(current_field_changes)[0] + to_write = rec.operation_ids.filtered( + lambda x: x.on_template_change == "sync" + ) + if to_write: + to_write.write(to_write_data) + return res diff --git a/mrp_routing/readme/CONTRIBUTORS.rst b/mrp_routing/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..b647a292e --- /dev/null +++ b/mrp_routing/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Christopher Ormaza diff --git a/mrp_routing/readme/DESCRIPTION.rst b/mrp_routing/readme/DESCRIPTION.rst new file mode 100644 index 000000000..5b30fe42f --- /dev/null +++ b/mrp_routing/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module adds routing concept as predefined operations, +operations should work as templates of operations on BOMs diff --git a/mrp_routing/readme/USAGE.rst b/mrp_routing/readme/USAGE.rst new file mode 100644 index 000000000..8f8aace0a --- /dev/null +++ b/mrp_routing/readme/USAGE.rst @@ -0,0 +1,16 @@ +You can add Routings on Manufacture / Products / Routings + +#. Create new Route +#. Add Operations + Operations its a copy of current operations on BOM, + with field "On template change?", this is Sync as default, + in this mode every change on this template is propagated + on operations related with this template + +Configure BOM and and Operations Page you can select predefined route (there are two ways to configure with templates) + - You can select a predefined route, + and this action replace and populate with templates associate + - Or You can add operations and select operation + as template to help setting default data + +On both configurations you can set field "On template change?" that change behavior when template related perform changes on data diff --git a/mrp_routing/security/ir.model.access.csv b/mrp_routing/security/ir.model.access.csv new file mode 100644 index 000000000..e02b54c14 --- /dev/null +++ b/mrp_routing/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_mrp_routing,mrp.routing,model_mrp_routing,mrp.group_mrp_user,1,0,0,0 +access_mrp_routing_manager,mrp.routing.manager,model_mrp_routing,mrp.group_mrp_manager,1,1,1,1 +access_mrp_routing_workcenter_template,mrp.routing.workcenter,model_mrp_routing_workcenter_template,mrp.group_mrp_user,1,0,0,0 +access_mrp_routing_workcenter_template_manager,mrp.routing.workcenter.manager,model_mrp_routing_workcenter_template,mrp.group_mrp_manager,1,1,1,1 diff --git a/mrp_routing/static/description/icon.png b/mrp_routing/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_routing/static/description/icon.png differ diff --git a/mrp_routing/static/description/index.html b/mrp_routing/static/description/index.html new file mode 100644 index 000000000..d0e97590f --- /dev/null +++ b/mrp_routing/static/description/index.html @@ -0,0 +1,455 @@ + + + + + + +MRP Routing + + + +
+

MRP Routing

+ + +

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

+

This module adds routing concept as predefined operations, +operations should work as templates of operations on BOMs

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Usage

+

You can add Routings on Manufacture / Products / Routings

+
    +
  1. Create new Route
  2. +
  3. +
    Add Operations
    +
    Operations its a copy of current operations on BOM, +with field “On template change?”, this is Sync as default, +in this mode every change on this template is propagated +on operations related with this template
    +
    +
  4. +
+
+
Configure BOM and and Operations Page you can select predefined route (there are two ways to configure with templates)
+
    +
  • You can select a predefined route, +and this action replace and populate with templates associate
  • +
  • Or You can add operations and select operation +as template to help setting default data
  • +
+
+
+

On both configurations you can set field “On template change?” that change behavior when template related perform changes on data

+
+
+

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

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

+

ChrisOForgeFlow

+

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_routing/tests/__init__.py b/mrp_routing/tests/__init__.py new file mode 100644 index 000000000..f01dc2e11 --- /dev/null +++ b/mrp_routing/tests/__init__.py @@ -0,0 +1 @@ +from . import test_manufacturing_routing diff --git a/mrp_routing/tests/test_manufacturing_routing.py b/mrp_routing/tests/test_manufacturing_routing.py new file mode 100644 index 000000000..457fe0ea5 --- /dev/null +++ b/mrp_routing/tests/test_manufacturing_routing.py @@ -0,0 +1,295 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import SavepointCase + +from ..models.mrp_routing_workcenter_template import FIELDS_TO_SYNC + + +class TestRestrictLot(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"] + cls.routing_obj = cls.env["mrp.routing"] + cls.workcenter_obj = cls.env["mrp.workcenter"] + cls.routing_workcenter_obj = cls.env["mrp.routing.workcenter"] + cls.routing_workcenter_template_obj = cls.env["mrp.routing.workcenter.template"] + + # Create products: + cls.product_1 = cls.product_obj.create({"name": "TEST 01", "type": "product"}) + cls.product_2 = cls.product_obj.create({"name": "TEST 02", "type": "product"}) + cls.product_3 = cls.product_obj.create({"name": "TEST 03", "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"}) + # Create Bills of Materials: + cls.bom_1 = cls.bom_obj.create( + {"product_tmpl_id": cls.product_1.product_tmpl_id.id} + ) + cls.line_1_1 = cls.bom_line_obj.create( + { + "product_id": cls.component_1.id, + "bom_id": cls.bom_1.id, + "product_qty": 2.0, + } + ) + cls.line_1_2 = cls.bom_line_obj.create( + { + "product_id": cls.component_2.id, + "bom_id": cls.bom_1.id, + "product_qty": 5.0, + } + ) + cls.bom_2 = cls.bom_obj.create( + {"product_tmpl_id": cls.product_1.product_tmpl_id.id} + ) + cls.line_2_1 = cls.bom_line_obj.create( + { + "product_id": cls.component_1.id, + "bom_id": cls.bom_2.id, + "product_qty": 2.0, + } + ) + cls.line_2_2 = cls.bom_line_obj.create( + { + "product_id": cls.component_2.id, + "bom_id": cls.bom_2.id, + "product_qty": 5.0, + } + ) + cls.bom_3 = cls.bom_obj.create( + {"product_tmpl_id": cls.product_1.product_tmpl_id.id} + ) + cls.line_3_1 = cls.bom_line_obj.create( + { + "product_id": cls.component_1.id, + "bom_id": cls.bom_3.id, + "product_qty": 2.0, + } + ) + cls.line_3_2 = cls.bom_line_obj.create( + { + "product_id": cls.component_2.id, + "bom_id": cls.bom_3.id, + "product_qty": 5.0, + } + ) + # Create Routing + cls.workcenter_1 = cls.env.ref("mrp.mrp_workcenter_1") + cls.workcenter_2 = cls.env.ref("mrp.mrp_workcenter_2") + cls.workcenter_3 = cls.env.ref("mrp.mrp_workcenter_3") + cls.operation_template_1 = cls.routing_workcenter_template_obj.create( + { + "workcenter_id": cls.workcenter_1.id, + "name": "Operation 1", + "time_cycle_manual": 60, + "sequence": 5, + "worksheet_type": "text", + "on_template_change": "sync", + } + ) + cls.operation_template_2 = cls.routing_workcenter_template_obj.create( + { + "workcenter_id": cls.workcenter_2.id, + "name": "Operation 2", + "time_cycle_manual": 120, + "sequence": 10, + "worksheet_type": "text", + "on_template_change": "sync", + } + ) + cls.operation_template_3 = cls.routing_workcenter_template_obj.create( + { + "workcenter_id": cls.workcenter_3.id, + "name": "Operation 3", + "time_cycle_manual": 180, + "sequence": 15, + "worksheet_type": "text", + "on_template_change": "sync", + } + ) + cls.operation_template_4 = cls.routing_workcenter_template_obj.create( + { + "workcenter_id": cls.workcenter_2.id, + "name": "Operation 4", + "time_cycle_manual": 150, + "sequence": 15, + "worksheet_type": "text", + "on_template_change": "nothing", + } + ) + cls.routing_1 = cls.routing_obj.create( + { + "name": "Routing 1", + "operation_ids": [ + ( + 6, + 0, + [ + cls.operation_template_1.id, + cls.operation_template_2.id, + cls.operation_template_3.id, + cls.operation_template_4.id, + ], + ) + ], + } + ) + + def test_01_sync_onchange_predefined_operations(self): + self.bom_1.routing_id = self.routing_1.id + self.bom_1.onchange_routing_id() + self.assertEqual( + self.bom_1.operation_ids.mapped("template_id").ids, + self.routing_1.operation_ids.ids, + ) + for operation in self.bom_1.operation_ids: + for field_to_check in FIELDS_TO_SYNC: + # When is setted as predefined, + # all operations are in synced mode + if field_to_check == "on_template_change": + continue + self.assertEqual( + operation[field_to_check], operation.template_id[field_to_check] + ) + + def test_02_sync_templates_changes_by_bom(self): + self.bom_1.routing_id = self.routing_1.id + self.bom_1.onchange_routing_id() + self.bom_2.routing_id = self.routing_1.id + self.bom_2.onchange_routing_id() + self.operation_template_1.write( + { + "sequence": 30, + "time_cycle_manual": 100, + } + ) + for operation in self.routing_workcenter_obj.search( + [("template_id", "=", self.operation_template_1.id)] + ): + self.assertEqual(operation.sequence, self.operation_template_1.sequence) + self.assertEqual( + operation.time_cycle_manual, self.operation_template_1.time_cycle_manual + ) + # Operation 4 is setted that not sync on changes, + # but operations was created by predefined operations + self.operation_template_4.write( + { + "name": "New Operation Name", + "time_cycle_manual": 100, + } + ) + for operation in self.routing_workcenter_obj.search( + [("template_id", "=", self.operation_template_4.id)] + ): + self.assertEqual(operation.name, self.operation_template_4.name) + self.assertEqual( + operation.time_cycle_manual, self.operation_template_4.time_cycle_manual + ) + + # On delete all operations related should be deleted + self.assertEqual( + 2, + self.routing_workcenter_obj.search_count( + [("template_id", "=", self.operation_template_3.id)] + ), + ) + self.operation_template_3.unlink() + self.assertEqual( + 0, + self.routing_workcenter_obj.search_count( + [("template_id", "=", self.operation_template_3.id)] + ), + ) + + def test_03_sync_templates_changes_manual_creation(self): + operation_1 = self.routing_workcenter_obj.create( + { + "workcenter_id": self.workcenter_1.id, + "name": "Operation without name", + "time_cycle_manual": 150, + "sequence": 15, + "worksheet_type": "text", + "bom_id": self.bom_3.id, + } + ) + operation_1.write( + { + "template_id": self.operation_template_1, + } + ) + operation_1.onchange_template_id() + for field_to_check in FIELDS_TO_SYNC: + self.assertEqual( + operation_1[field_to_check], operation_1.template_id[field_to_check] + ) + operation_2 = self.routing_workcenter_obj.create( + { + "workcenter_id": self.workcenter_2.id, + "name": "Operation 4", + "time_cycle_manual": 20, + "sequence": 5, + "worksheet_type": "text", + "bom_id": self.bom_3.id, + } + ) + operation_2.write( + { + "template_id": self.operation_template_4, + } + ) + operation_2.onchange_template_id() + self.operation_template_4.write({"name": "New Name Operation 4"}) + self.assertNotEqual(operation_2.name, self.operation_template_4.name) + + def test_04_sync_templates_routing_changes(self): + self.bom_1.routing_id = self.routing_1.id + self.bom_1.onchange_routing_id() + self.bom_2.routing_id = self.routing_1.id + self.bom_2.onchange_routing_id() + self.routing_1.write( + { + "operation_ids": [ + ( + 6, + 0, + [ + self.operation_template_1.id, + self.operation_template_2.id, + ], + ) + ] + } + ) + self.assertNotIn( + self.operation_template_4.id, + self.bom_1.operation_ids.mapped("template_id").ids, + ) + self.assertNotIn( + self.operation_template_4.id, + self.bom_2.operation_ids.mapped("template_id").ids, + ) + self.routing_1.write( + { + "operation_ids": [ + ( + 6, + 0, + [ + self.operation_template_1.id, + self.operation_template_2.id, + self.operation_template_4.id, + ], + ) + ] + } + ) + self.assertIn( + self.operation_template_4.id, + self.bom_1.operation_ids.mapped("template_id").ids, + ) + self.assertIn( + self.operation_template_4.id, + self.bom_2.operation_ids.mapped("template_id").ids, + ) diff --git a/mrp_routing/views/mrp_bom_view.xml b/mrp_routing/views/mrp_bom_view.xml new file mode 100644 index 000000000..b57c8d636 --- /dev/null +++ b/mrp_routing/views/mrp_bom_view.xml @@ -0,0 +1,18 @@ + + + + + + mrp.bom.form.view + mrp.bom + + + + + + + + + diff --git a/mrp_routing/views/mrp_routing_view.xml b/mrp_routing/views/mrp_routing_view.xml new file mode 100644 index 000000000..ad754d6cb --- /dev/null +++ b/mrp_routing/views/mrp_routing_view.xml @@ -0,0 +1,139 @@ + + + + + + mrp.routing.form + mrp.routing + +
+ +
+
+ +
+

+ +

+
+ + + + + + + + + + + + + + + + + +
+
+
+
+ + + mrp.routing.tree + mrp.routing + + + + + + + + + + + + mrp.routing.kanban + mrp.routing + + + + + + +
+
+
+ +
+ +
+
+
+
+
+
+
+ + + mrp.routing.search + mrp.routing + + + + + + + + + + Routings + ir.actions.act_window + mrp.routing + tree,kanban,form + + + +

+ Create a new routing +

+ Routings define the successive operations that need to be + done to realize a Manufacturing Order. Each operation from + a Routing is done at a specific Work Center and has a specific duration. +

+
+
+ + + +
+
diff --git a/mrp_routing/views/mrp_routing_workcenter_template_view.xml b/mrp_routing/views/mrp_routing_workcenter_template_view.xml new file mode 100644 index 000000000..3b4888706 --- /dev/null +++ b/mrp_routing/views/mrp_routing_workcenter_template_view.xml @@ -0,0 +1,143 @@ + + + + + + mrp.routing.workcenter.template.tree + mrp.routing.workcenter.template + + + + + + + + + + + + mrp.routing.workcenter.template.form + mrp.routing.workcenter.template + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + mrp.routing.workcenter.template.search + mrp.routing.workcenter.template + + + + + + + + + + + + Template Operations + ir.actions.act_window + mrp.routing.workcenter.template + tree,form + + +

+ Create a new template operation +

+ Template Operation can be used to make template for operations related to bill of materials. +

+
+ [] +
+ + + + +
+
diff --git a/mrp_routing/views/mrp_routing_workcenter_view.xml b/mrp_routing/views/mrp_routing_workcenter_view.xml new file mode 100644 index 000000000..613454b9f --- /dev/null +++ b/mrp_routing/views/mrp_routing_workcenter_view.xml @@ -0,0 +1,43 @@ + + + + + + mrp.routing.workcenter.tree + mrp.routing.workcenter + + + + + + + + + + + + + + + + + + + + mrp.routing.workcenter.form + mrp.routing.workcenter + + + + + + + + + + + + diff --git a/setup/mrp_routing/odoo/addons/mrp_routing b/setup/mrp_routing/odoo/addons/mrp_routing new file mode 120000 index 000000000..a09be28a7 --- /dev/null +++ b/setup/mrp_routing/odoo/addons/mrp_routing @@ -0,0 +1 @@ +../../../../mrp_routing \ No newline at end of file diff --git a/setup/mrp_routing/setup.py b/setup/mrp_routing/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_routing/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)