diff --git a/mrp_production_hierarchy/README.rst b/mrp_production_hierarchy/README.rst new file mode 100644 index 000000000..e4addbe67 --- /dev/null +++ b/mrp_production_hierarchy/README.rst @@ -0,0 +1,72 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +=========================== +Production Orders Hierarchy +=========================== + +This module allows to view the hierarchy of generated production orders +when several levels of bill of materials are involved. + +Usage +===== + +Create a new production order (Manufacture / Operations / Manufacturing Orders) +with a multi-levels nomenclatured product, and related products configured with +'Manufacture' and 'Make To Order' routes: + +.. figure:: mrp_production_hierarchy/static/description/mrp_production_hierarchy_1.png + +Once saved, click on the 'Hierarchy' button at right: + +.. figure:: mrp_production_hierarchy/static/description/mrp_production_hierarchy_2.png + +.. figure:: mrp_production_hierarchy/static/description/mrp_production_hierarchy_3.png + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/129/10.0 + +Known issues / Roadmap +====================== + +* Only new production orders will benefit from this feature, it is not compatible with existing 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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Sébastien Alix (https://osiell.com) + +Do not contact contributors directly about support or help with technical issues. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/mrp_production_hierarchy/__init__.py b/mrp_production_hierarchy/__init__.py new file mode 100644 index 000000000..a0fdc10fe --- /dev/null +++ b/mrp_production_hierarchy/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/mrp_production_hierarchy/__manifest__.py b/mrp_production_hierarchy/__manifest__.py new file mode 100644 index 000000000..6c87fe3a6 --- /dev/null +++ b/mrp_production_hierarchy/__manifest__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 ABF OSIELL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Production Orders Hierarchy", + "summary": "View the hierarchy of generated production orders", + "version": "10.0.1.0.0", + "category": "Manufacturing", + "website": "https://github.com/OCA/manufacture", + "author": "ABF OSIELL, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "mrp", + ], + "data": [ + "views/mrp_production.xml", + ], +} diff --git a/mrp_production_hierarchy/i18n/fr.po b/mrp_production_hierarchy/i18n/fr.po new file mode 100644 index 000000000..f890fc170 --- /dev/null +++ b/mrp_production_hierarchy/i18n/fr.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_hierarchy +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-05-18 13:30+0000\n" +"PO-Revision-Date: 2018-05-18 13:30+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_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_child_ids +msgid "Child orders" +msgstr "OF générés" + +#. module: mrp_production_hierarchy +#: code:addons/mrp_production_hierarchy/models/mrp_production.py:37 +#: model:ir.ui.view,arch_db:mrp_production_hierarchy.mrp_production_form_view +#, python-format +msgid "Hierarchy" +msgstr "Hiérarchie" + +#. module: mrp_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_parent_left +msgid "Left Parent" +msgstr "Parent gauche" + +#. module: mrp_production_hierarchy +#: model:ir.model,name:mrp_production_hierarchy.model_mrp_production +msgid "Manufacturing Order" +msgstr "Ordre de fabrication" + +#. module: mrp_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_parent_id +msgid "Parent order" +msgstr "OF d'origine" + +#. module: mrp_production_hierarchy +#: model:ir.model,name:mrp_production_hierarchy.model_procurement_order +msgid "Procurement" +msgstr "Approvisionnement" + +#. module: mrp_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_parent_right +msgid "Right Parent" +msgstr "Parent à droite" diff --git a/mrp_production_hierarchy/i18n/mrp_production_hierarchy.pot b/mrp_production_hierarchy/i18n/mrp_production_hierarchy.pot new file mode 100644 index 000000000..d801fc85f --- /dev/null +++ b/mrp_production_hierarchy/i18n/mrp_production_hierarchy.pot @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_hierarchy +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-05-18 13:30+0000\n" +"PO-Revision-Date: 2018-05-18 13:30+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_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_child_ids +msgid "Child orders" +msgstr "" + +#. module: mrp_production_hierarchy +#: code:addons/mrp_production_hierarchy/models/mrp_production.py:37 +#: model:ir.ui.view,arch_db:mrp_production_hierarchy.mrp_production_form_view +#, python-format +msgid "Hierarchy" +msgstr "" + +#. module: mrp_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_parent_left +msgid "Left Parent" +msgstr "" + +#. module: mrp_production_hierarchy +#: model:ir.model,name:mrp_production_hierarchy.model_mrp_production +msgid "Manufacturing Order" +msgstr "" + +#. module: mrp_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_parent_id +msgid "Parent order" +msgstr "" + +#. module: mrp_production_hierarchy +#: model:ir.model,name:mrp_production_hierarchy.model_procurement_order +msgid "Procurement" +msgstr "" + +#. module: mrp_production_hierarchy +#: model:ir.model.fields,field_description:mrp_production_hierarchy.field_mrp_production_parent_right +msgid "Right Parent" +msgstr "" + diff --git a/mrp_production_hierarchy/models/__init__.py b/mrp_production_hierarchy/models/__init__.py new file mode 100644 index 000000000..36d8d6c54 --- /dev/null +++ b/mrp_production_hierarchy/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +from . import mrp_production +from . import procurement_order diff --git a/mrp_production_hierarchy/models/mrp_production.py b/mrp_production_hierarchy/models/mrp_production.py new file mode 100644 index 000000000..a277f2e65 --- /dev/null +++ b/mrp_production_hierarchy/models/mrp_production.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 ABF OSIELL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models, _ + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + _parent_name = "parent_id" + _parent_store = True + _parent_order = 'name' + + parent_id = fields.Many2one( + 'mrp.production', u"Parent order", + index=True, ondelete='restrict') + child_ids = fields.One2many( + 'mrp.production', 'parent_id', u"Child orders") + parent_left = fields.Integer('Left Parent', index=True) + parent_right = fields.Integer('Right Parent', index=True) + + @api.multi + def _generate_moves(self): + """Overloaded to pass the created production order ID in the context. + It will be used by the 'procurement_order.make_mo()' overload to + set the parent relation between production orders. + """ + self = self.with_context(parent_mrp_production_id=self.id) + return super(MrpProduction, self)._generate_moves() + + @api.multi + def open_production_tree(self): + self.ensure_one() + if self.child_ids: + return { + 'domain': "[('parent_id', '=', %s)]" % self.id, + 'name': _(u"Hierarchy"), + 'view_type': 'tree', + 'view_mode': 'tree', + 'res_model': 'mrp.production', + 'view_id': self.env.ref( + 'mrp_production_hierarchy.' + 'mrp_production_tree_view_field_parent').id, + 'target': 'current', + 'type': 'ir.actions.act_window', + 'context': dict(self.env.context), + } + return False diff --git a/mrp_production_hierarchy/models/procurement_order.py b/mrp_production_hierarchy/models/procurement_order.py new file mode 100644 index 000000000..53418f121 --- /dev/null +++ b/mrp_production_hierarchy/models/procurement_order.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 ABF OSIELL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProcurementOrder(models.Model): + _inherit = 'procurement.order' + + @api.multi + def make_mo(self): + """Overload to set the parent production order ID to its childs.""" + res = super(ProcurementOrder, self).make_mo() + production_ids = res.values() + productions = self.env['mrp.production'].browse(production_ids) + for production in productions: + if self.env.context.get('parent_mrp_production_id'): + parent_id = self.env.context['parent_mrp_production_id'] + production.parent_id = parent_id + return res diff --git a/mrp_production_hierarchy/static/description/icon.png b/mrp_production_hierarchy/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_production_hierarchy/static/description/icon.png differ diff --git a/mrp_production_hierarchy/static/description/mrp_production_hierarchy_1.png b/mrp_production_hierarchy/static/description/mrp_production_hierarchy_1.png new file mode 100644 index 000000000..59b485a39 Binary files /dev/null and b/mrp_production_hierarchy/static/description/mrp_production_hierarchy_1.png differ diff --git a/mrp_production_hierarchy/static/description/mrp_production_hierarchy_2.png b/mrp_production_hierarchy/static/description/mrp_production_hierarchy_2.png new file mode 100644 index 000000000..ba755ff3e Binary files /dev/null and b/mrp_production_hierarchy/static/description/mrp_production_hierarchy_2.png differ diff --git a/mrp_production_hierarchy/static/description/mrp_production_hierarchy_3.png b/mrp_production_hierarchy/static/description/mrp_production_hierarchy_3.png new file mode 100644 index 000000000..ae45ac4f5 Binary files /dev/null and b/mrp_production_hierarchy/static/description/mrp_production_hierarchy_3.png differ diff --git a/mrp_production_hierarchy/tests/__init__.py b/mrp_production_hierarchy/tests/__init__.py new file mode 100644 index 000000000..b66615d8d --- /dev/null +++ b/mrp_production_hierarchy/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 ABF OSIELL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_mrp_production_hierarchy diff --git a/mrp_production_hierarchy/tests/test_mrp_production_hierarchy.py b/mrp_production_hierarchy/tests/test_mrp_production_hierarchy.py new file mode 100644 index 000000000..4ba76d107 --- /dev/null +++ b/mrp_production_hierarchy/tests/test_mrp_production_hierarchy.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 ABF OSIELL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.mrp.tests.common import TestMrpCommon + + +class TestMrpProductionHierarchy(TestMrpCommon): + + def setUp(self): + super(TestMrpProductionHierarchy, self).setUp() + self.bom_2.write({'type': 'normal'}) + route_manufacture = self.env.ref('mrp.route_warehouse0_manufacture') + route_mto = self.env.ref('stock.route_warehouse0_mto') + (self.bom_1 | self.bom_2 | self.bom_3).mapped('product_id').write( + {'route_ids': [(6, 0, [route_manufacture.id, route_mto.id])]}) + + def test_production_hierarchy(self): + man_order = self.env['mrp.production'].create({ + 'name': 'MO-Test', + 'product_id': self.product_6.id, + 'product_uom_id': self.product_6.uom_id.id, + 'product_qty': 2, + 'bom_id': self.bom_3.id, + }) + self.assertEqual(len(man_order.child_ids), 2) + for child in man_order.child_ids: + self.assertIn(child.product_id, [self.product_5, self.product_4]) + for child2 in child.child_ids: + self.assertIn(child2.product_id, [self.product_4]) diff --git a/mrp_production_hierarchy/views/mrp_production.xml b/mrp_production_hierarchy/views/mrp_production.xml new file mode 100644 index 000000000..bc913098b --- /dev/null +++ b/mrp_production_hierarchy/views/mrp_production.xml @@ -0,0 +1,32 @@ + + + + + mrp.production.form + mrp.production + + +
+ +
+
+
+ + + + mrp.production.tree + mrp.production + child_ids + primary + + + + + + + +