diff --git a/quality_control_mrp/models/mrp_production.py b/quality_control_mrp/models/mrp_production.py index d7843c383..6f5ad7846 100644 --- a/quality_control_mrp/models/mrp_production.py +++ b/quality_control_mrp/models/mrp_production.py @@ -24,13 +24,15 @@ class MrpProduction(models.Model): @api.model def action_produce(self, production_id, production_qty, production_mode, wiz=False): + production = self.browse(production_id) + done_moves = production.move_created_ids2.filtered( + lambda r: r.state == 'done') res = super(MrpProduction, self).action_produce( production_id, production_qty, production_mode, wiz=wiz) if production_mode == 'consume_produce': inspection_model = self.env['qc.inspection'] - production = self.browse(production_id) for move in production.move_created_ids2.filtered( - lambda r: r.state == 'done'): + lambda r: r.state == 'done') - done_moves: qc_trigger = self.env.ref('quality_control_mrp.qc_trigger_mrp') trigger_lines = set() for model in ['qc.trigger.product_category_line', diff --git a/quality_control_mrp/tests/test_quality_control_mrp.py b/quality_control_mrp/tests/test_quality_control_mrp.py index ce5cc94f0..d59bc5f69 100644 --- a/quality_control_mrp/tests/test_quality_control_mrp.py +++ b/quality_control_mrp/tests/test_quality_control_mrp.py @@ -17,6 +17,7 @@ class TestQualityControlMrp(TransactionCase): self.trigger = self.env.ref('quality_control_mrp.qc_trigger_mrp') self.production1 = self.production_model.create({ 'product_id': self.product.id, + 'product_qty': 2.0, 'product_uom': self.product.uom_id.id, }) self.production1.action_confirm() @@ -86,6 +87,22 @@ class TestQualityControlMrp(TransactionCase): self.assertEqual(self.production1.created_inspections, 1, 'Only one inspection must be created') + def test_inspection_with_partial_fabrication(self): + self.product.qc_triggers = [( + 0, 0, { + 'trigger': self.trigger.id, + 'test': self.test.id, + } + )] + self.production1.action_produce( + self.production1.id, 1.0, 'consume_produce') + self.assertEqual(self.production1.created_inspections, 1, + 'Only one inspection must be created.') + self.production1.action_produce( + self.production1.id, 1.0, 'consume_produce') + self.assertEqual(self.production1.created_inspections, 2, + 'There must be only 2 inspections.') + def test_qc_inspection_mo(self): self.inspection1.write({ 'object_id': '%s,%d' % (self.production1._model,