diff --git a/mrp_production_service/README.rst b/mrp_production_service/README.rst new file mode 100644 index 000000000..42406e9cc --- /dev/null +++ b/mrp_production_service/README.rst @@ -0,0 +1,60 @@ +.. 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 + +====================== +MRP Production Service +====================== + +This module allows to create procurement orders from manufacturing orders when +a services is included in the Bill of Materials. + +This allows users to include additional services that has to be procured as +part of the manufacturing process. + + +Usage +===== + +.. 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 + + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar +* Héctor Villarreal Ortega + + +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_service/__init__.py b/mrp_production_service/__init__.py new file mode 100644 index 000000000..08f93b3a4 --- /dev/null +++ b/mrp_production_service/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/mrp_production_service/__manifest__.py b/mrp_production_service/__manifest__.py new file mode 100644 index 000000000..6629fe3c7 --- /dev/null +++ b/mrp_production_service/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "MRP Production Service", + "summary": "Creates procurement orders from manufacturing orders, for " + "services included in the Bill of Materials", + "version": "10.0.1.0.0", + "author": "Eficent," + "Odoo Community Association (OCA)", + "website": "https://www.odoo-community.org", + "category": "Warehouse Management", + "depends": ["mrp"], + "license": "AGPL-3", + 'installable': True, + 'application': False, +} diff --git a/mrp_production_service/models/__init__.py b/mrp_production_service/models/__init__.py new file mode 100644 index 000000000..804c239b4 --- /dev/null +++ b/mrp_production_service/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import mrp_production diff --git a/mrp_production_service/models/mrp_production.py b/mrp_production_service/models/mrp_production.py new file mode 100644 index 000000000..3da70265a --- /dev/null +++ b/mrp_production_service/models/mrp_production.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + @api.model + def _prepare_service_procurement(self, line, production): + location = production.location_src_id + return { + 'name': '%s for %s' % (line.product_id.name, production.name), + 'origin': production.origin, + 'company_id': production.company_id.id, + 'date_planned_start': production.date_planned_start, + 'product_id': line.product_id.id, + 'product_qty': line.product_qty, + 'product_uom': line.product_uom_id.id, + 'location_id': location.id, + 'warehouse_id': location.get_warehouse().id + } + + @api.model + def _create_service_procurement(self, line, production): + data = self._prepare_service_procurement(line, production) + return self.env['procurement.order'].create(data) + + @api.multi + def _generate_moves(self): + res = super(MrpProduction, self)._generate_moves() + for production in self: + factor = production.product_uom_id._compute_quantity( + production.product_qty, + production.bom_id.product_uom_id + ) / production.bom_id.product_qty + boms, lines = production.bom_id.explode( + production.product_id, factor, + picking_type=production.bom_id.picking_type_id) + for line in lines: + if line[0].product_id.type == 'service': + self._create_service_procurement(line[0], production) + return res diff --git a/mrp_production_service/static/description/icon.png b/mrp_production_service/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_production_service/static/description/icon.png differ diff --git a/mrp_production_service/tests/__init__.py b/mrp_production_service/tests/__init__.py new file mode 100644 index 000000000..6f21949d3 --- /dev/null +++ b/mrp_production_service/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import test_mrp_production_service \ No newline at end of file diff --git a/mrp_production_service/tests/test_mrp_production_service.py b/mrp_production_service/tests/test_mrp_production_service.py new file mode 100644 index 000000000..200c4b0b0 --- /dev/null +++ b/mrp_production_service/tests/test_mrp_production_service.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestMrpProductionService(TransactionCase): + def setUp(self): + super(TestMrpProductionService, self).setUp() + # Create products + product_model = self.env['product.product'] + self.p1 = product_model.create({'name': '101'}) + self.p2 = product_model.create({'name': '201P'}) + self.p3 = product_model.create({'name': '202P'}) + self.service = product_model.create({'name': 'Assembly Service', + 'type': 'service'}) + + # Create bill of materials + self.bom_model = self.env['mrp.bom'] + self.bom = self.bom_model.create({ + 'product_tmpl_id': self.p1.product_tmpl_id.id, + 'product_id': self.p1.id, + 'product_qty': 1, + 'type': 'normal', + }) + # Create bom lines + self.bom_line_model = self.env['mrp.bom.line'] + self.bom_line_model.create({ + 'bom_id': self.bom.id, + 'product_id': self.p2.id, + 'product_qty': 1, + }) + self.bom_line_model.create({ + 'bom_id': self.bom.id, + 'product_id': self.p3.id, + 'product_qty': 1, + }) + self.bom_line_model.create({ + 'bom_id': self.bom.id, + 'product_id': self.service.id, + 'product_qty': 1, + }) + + def test_produce_bom_with_service(self): + """Explode bill of material and look for a procurement of a service.""" + self.mrp_production_model = self.env['mrp.production'] + + self.env['mrp.production'].create({ + 'product_id': self.p1.id, + 'product_qty': 1.0, + 'product_uom_id': self.p1.uom_id.id, + 'bom_id': self.bom.id + }) + + procurement = self.env['procurement.order'].search( + [('product_id', 'in', + self.bom.bom_line_ids.mapped('product_id.id'))]) + + self.assertEqual(len(procurement), 1) + self.assertEqual(procurement.product_id.type, 'service')