From 5caf9891d1892eaf4e0ef394e2c60c7eac825bfb Mon Sep 17 00:00:00 2001 From: hveficent Date: Wed, 25 Apr 2018 14:57:10 +0200 Subject: [PATCH] [MIG] mrp_production_service: Migration to 11.0 --- mrp_production_service/README.rst | 13 +++--- mrp_production_service/__init__.py | 1 - mrp_production_service/__manifest__.py | 6 +-- mrp_production_service/models/__init__.py | 5 ++- .../models/mrp_production.py | 40 ++++++++++------- mrp_production_service/tests/__init__.py | 2 +- .../tests/test_mrp_production_service.py | 44 +++++++++++-------- oca_dependencies.txt | 1 + 8 files changed, 64 insertions(+), 48 deletions(-) diff --git a/mrp_production_service/README.rst b/mrp_production_service/README.rst index 42406e9cc..3a9d5719f 100644 --- a/mrp_production_service/README.rst +++ b/mrp_production_service/README.rst @@ -1,4 +1,4 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 @@ -6,10 +6,10 @@ MRP Production Service ====================== -This module allows to create procurement orders from manufacturing orders when -a services is included in the Bill of Materials. +Creates procurement orders from manufacturing orders, for services included +in the Bill of Materials. -This allows users to include additional services that has to be procured as +This allows users to include additional services that are to be procured as part of the manufacturing process. @@ -18,7 +18,7 @@ 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 + :target: https://runbot.odoo-community.org/runbot/129/8.0 Bug Tracker @@ -35,13 +35,12 @@ Credits Images ------ -* Odoo Community Association: `Icon `_. +* Odoo Community Association: `Icon `_. Contributors ------------ * Jordi Ballester Alomar -* Héctor Villarreal Ortega Maintainer diff --git a/mrp_production_service/__init__.py b/mrp_production_service/__init__.py index 08f93b3a4..5aec6acec 100644 --- a/mrp_production_service/__init__.py +++ b/mrp_production_service/__init__.py @@ -1,4 +1,3 @@ -# -*- 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). diff --git a/mrp_production_service/__manifest__.py b/mrp_production_service/__manifest__.py index 6629fe3c7..1fe8b4a10 100644 --- a/mrp_production_service/__manifest__.py +++ b/mrp_production_service/__manifest__.py @@ -1,4 +1,3 @@ -# -*- 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). @@ -6,12 +5,13 @@ "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", + "version": "11.0.1.0.0", "author": "Eficent," "Odoo Community Association (OCA)", "website": "https://www.odoo-community.org", "category": "Warehouse Management", - "depends": ["mrp"], + "depends": ["mrp", + "subcontracted_service"], "license": "AGPL-3", 'installable': True, 'application': False, diff --git a/mrp_production_service/models/__init__.py b/mrp_production_service/models/__init__.py index 804c239b4..0e616b53b 100644 --- a/mrp_production_service/models/__init__.py +++ b/mrp_production_service/models/__init__.py @@ -1,2 +1,5 @@ -# -*- 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 mrp_production diff --git a/mrp_production_service/models/mrp_production.py b/mrp_production_service/models/mrp_production.py index 3da70265a..b12502395 100644 --- a/mrp_production_service/models/mrp_production.py +++ b/mrp_production_service/models/mrp_production.py @@ -1,4 +1,3 @@ -# -*- 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). @@ -10,28 +9,36 @@ class MrpProduction(models.Model): _inherit = "mrp.production" @api.model - def _prepare_service_procurement(self, line, production): + def _prepare_service_procurement_values(self, 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 + 'company_id': production.company_id, + 'date_planned': production.date_planned_start, + 'warehouse_id': location.get_warehouse(), + 'group_id': production.procurement_group_id, } @api.model - def _create_service_procurement(self, line, production): - data = self._prepare_service_procurement(line, production) - return self.env['procurement.order'].create(data) + def _create_service_procurement(self, line): + data = self._prepare_service_procurement(line) + return self.env['procurement.rule'].create(data) + + @api.model + def _action_launch_procurement_rule(self, line, production): + values = self._prepare_service_procurement_values(production) + + name = '%s for %s' % (line.product_id.name, + production.name) + self.env['procurement.group'].sudo().run( + line.product_id, line.product_qty, + line.product_uom_id, + production.location_src_id, name, + name, values) + return True @api.multi def _generate_moves(self): - res = super(MrpProduction, self)._generate_moves() + res = super()._generate_moves() for production in self: factor = production.product_uom_id._compute_quantity( production.product_qty, @@ -42,5 +49,6 @@ class MrpProduction(models.Model): 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) + production._action_launch_procurement_rule(line[0], + production) return res diff --git a/mrp_production_service/tests/__init__.py b/mrp_production_service/tests/__init__.py index 6f21949d3..5e3bfccb9 100644 --- a/mrp_production_service/tests/__init__.py +++ b/mrp_production_service/tests/__init__.py @@ -1,2 +1,2 @@ -# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). 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 index 200c4b0b0..9a97a004d 100644 --- a/mrp_production_service/tests/test_mrp_production_service.py +++ b/mrp_production_service/tests/test_mrp_production_service.py @@ -1,4 +1,3 @@ -# -*- 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). @@ -9,14 +8,31 @@ 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 products + self.obj_warehouse = self.env['stock.warehouse'] + self.test_wh = self.obj_warehouse.create({ + 'name': 'Test WH', + 'code': 'T', + }) + self.supplier = self.env['res.partner'].create({ + 'name': 'Supplier', + 'supplier': True, + }) + self.product_model = self.env['product.product'] + self.p1 = self.product_model.create({ + 'name': '101', + 'type': 'product', + }) + self.service = self.product_model.create({ + 'name': 'Galvanize Service', + 'type': 'service', + 'seller_ids': [(0, 0, { + 'name': self.supplier.id, + 'price': 100.0, + })] + }) + self.service.property_subcontracted_service = True # Create bill of materials self.bom_model = self.env['mrp.bom'] self.bom = self.bom_model.create({ @@ -27,16 +43,6 @@ class TestMrpProductionService(TransactionCase): }) # 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, @@ -54,7 +60,7 @@ class TestMrpProductionService(TransactionCase): 'bom_id': self.bom.id }) - procurement = self.env['procurement.order'].search( + procurement = self.env['purchase.order.line'].search( [('product_id', 'in', self.bom.bom_line_ids.mapped('product_id.id'))]) diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 5d557e554..16abec0ad 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,3 +1,4 @@ # List the OCA project dependencies, one per line # Add a repository url and branch if you need a forked version product-attribute +purchase-workflow