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/models/qc_inspection.py b/quality_control_mrp/models/qc_inspection.py
index 200868ea9..dfc901b4b 100644
--- a/quality_control_mrp/models/qc_inspection.py
+++ b/quality_control_mrp/models/qc_inspection.py
@@ -8,15 +8,23 @@ from openerp import models, fields, api
class QcInspection(models.Model):
_inherit = 'qc.inspection'
- @api.one
@api.depends('object_id')
def get_production(self):
- self.production = False
- if self.object_id:
- if self.object_id._name == 'stock.move':
- self.production = self.object_id.production_id
- elif self.object_id._name == 'mrp.production':
- self.production = self.object_id
+ for inspection in self:
+ if inspection.object_id:
+ if inspection.object_id._name == 'stock.move':
+ inspection.production = inspection.object_id.production_id
+ elif inspection.object_id._name == 'mrp.production':
+ inspection.production = inspection.object_id
+
+ @api.depends('object_id')
+ def _get_product(self):
+ """Overriden for getting the product from a manufacturing order."""
+ for inspection in self:
+ super(QcInspection, inspection)._get_product()
+ if inspection.object_id and\
+ inspection.object_id._name == 'mrp.production':
+ inspection.product = inspection.object_id.product_id
production = fields.Many2one(
comodel_name="mrp.production", compute="get_production", store=True)
diff --git a/quality_control_mrp/tests/test_quality_control_mrp.py b/quality_control_mrp/tests/test_quality_control_mrp.py
index 7aefdabd9..d59bc5f69 100644
--- a/quality_control_mrp/tests/test_quality_control_mrp.py
+++ b/quality_control_mrp/tests/test_quality_control_mrp.py
@@ -10,16 +10,24 @@ class TestQualityControlMrp(TransactionCase):
def setUp(self):
super(TestQualityControlMrp, self).setUp()
self.production_model = self.env['mrp.production']
+ self.inspection_model = self.env['qc.inspection']
self.qc_trigger_model = self.env['qc.trigger']
self.product = self.env.ref('product.product_product_4')
self.test = self.env.ref('quality_control.qc_test_1')
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()
self.production1.action_assign()
+ inspection_lines = (
+ self.inspection_model._prepare_inspection_lines(self.test))
+ self.inspection1 = self.inspection_model.create({
+ 'name': 'Test Inspection',
+ 'inspection_lines': inspection_lines,
+ })
def test_inspection_create_for_product(self):
self.product.qc_triggers = [(
@@ -78,3 +86,27 @@ class TestQualityControlMrp(TransactionCase):
'consume_produce')
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,
+ self.production1.id),
+ })
+ self.assertEquals(self.inspection1.production,
+ self.production1)
diff --git a/quality_control_mrp/views/qc_inspection_view.xml b/quality_control_mrp/views/qc_inspection_view.xml
index d806b6a14..5bc886ef3 100644
--- a/quality_control_mrp/views/qc_inspection_view.xml
+++ b/quality_control_mrp/views/qc_inspection_view.xml
@@ -35,6 +35,9 @@
+
+
+