From 0bd03b6f55e94f37ad49060843585d2ec1fe0a0a Mon Sep 17 00:00:00 2001 From: hveficent Date: Fri, 11 May 2018 10:11:38 +0200 Subject: [PATCH] [11.0][FIX] mrp_production_service: Qty fix --- mrp_production_service/__manifest__.py | 2 +- .../models/mrp_production.py | 36 +++++++++---------- .../tests/test_mrp_production_service.py | 15 ++++---- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/mrp_production_service/__manifest__.py b/mrp_production_service/__manifest__.py index 1fe8b4a10..b11a8d3a3 100644 --- a/mrp_production_service/__manifest__.py +++ b/mrp_production_service/__manifest__.py @@ -5,7 +5,7 @@ "name": "MRP Production Service", "summary": "Creates procurement orders from manufacturing orders, for " "services included in the Bill of Materials", - "version": "11.0.1.0.0", + "version": "11.0.1.0.1", "author": "Eficent," "Odoo Community Association (OCA)", "website": "https://www.odoo-community.org", diff --git a/mrp_production_service/models/mrp_production.py b/mrp_production_service/models/mrp_production.py index b12502395..01d5b1af5 100644 --- a/mrp_production_service/models/mrp_production.py +++ b/mrp_production_service/models/mrp_production.py @@ -8,31 +8,27 @@ from odoo import api, models class MrpProduction(models.Model): _inherit = "mrp.production" - @api.model - def _prepare_service_procurement_values(self, production): - location = production.location_src_id + @api.multi + def _prepare_service_procurement_values(self): + self.ensure_one() + location = self.location_src_id return { - 'company_id': production.company_id, - 'date_planned': production.date_planned_start, + 'company_id': self.company_id, + 'date_planned': self.date_planned_start, 'warehouse_id': location.get_warehouse(), - 'group_id': production.procurement_group_id, + 'group_id': self.procurement_group_id, } @api.model - def _create_service_procurement(self, line): - data = self._prepare_service_procurement(line) - return self.env['procurement.rule'].create(data) + def _action_launch_procurement_rule(self, bom_line, dict): + values = self._prepare_service_procurement_values() - @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) + name = '%s for %s' % (bom_line.product_id.name, + self.name) self.env['procurement.group'].sudo().run( - line.product_id, line.product_qty, - line.product_uom_id, - production.location_src_id, name, + bom_line.product_id, dict['qty'], + bom_line.product_uom_id, + self.location_src_id, name, name, values) return True @@ -49,6 +45,6 @@ class MrpProduction(models.Model): picking_type=production.bom_id.picking_type_id) for line in lines: if line[0].product_id.type == 'service': - production._action_launch_procurement_rule(line[0], - production) + production._action_launch_procurement_rule( + line[0], line[1]) return res diff --git a/mrp_production_service/tests/test_mrp_production_service.py b/mrp_production_service/tests/test_mrp_production_service.py index 9a97a004d..f6f40a66c 100644 --- a/mrp_production_service/tests/test_mrp_production_service.py +++ b/mrp_production_service/tests/test_mrp_production_service.py @@ -46,23 +46,24 @@ class TestMrpProductionService(TransactionCase): self.bom_line_model.create({ 'bom_id': self.bom.id, 'product_id': self.service.id, - 'product_qty': 1, + 'product_qty': 2, }) - def test_produce_bom_with_service(self): - """Explode bill of material and look for a procurement of a service.""" + def test_bom_production_service(self): + """Explode bill of material and look for a production service.""" self.mrp_production_model = self.env['mrp.production'] self.env['mrp.production'].create({ 'product_id': self.p1.id, - 'product_qty': 1.0, + 'product_qty': 3.0, 'product_uom_id': self.p1.uom_id.id, 'bom_id': self.bom.id }) - procurement = self.env['purchase.order.line'].search( + production_service = self.env['purchase.order.line'].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') + self.assertEqual(len(production_service), 1) + self.assertEqual(production_service.product_id.type, 'service') + self.assertEqual(production_service.product_qty, 6.0)