[11.0][FIX] mrp_production_service: Qty fix

This commit is contained in:
hveficent
2018-05-11 10:11:38 +02:00
committed by Jordi Ballester Alomar
parent 180174628f
commit 0bd03b6f55
3 changed files with 25 additions and 28 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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)