From 324c529f54c634a594592279e0b7d6a5b3a4a5e2 Mon Sep 17 00:00:00 2001 From: oihane Date: Wed, 11 May 2016 12:03:30 +0200 Subject: [PATCH] [IMP] quality_control_stock: if lot in reference, get its info quality_control_mrp: tests extended --- .../tests/test_quality_control_mrp.py | 15 +++++++++++++++ quality_control_stock/models/qc_inspection.py | 4 ++++ .../tests/test_quality_control_stock.py | 11 +++++++++++ 3 files changed, 30 insertions(+) diff --git a/quality_control_mrp/tests/test_quality_control_mrp.py b/quality_control_mrp/tests/test_quality_control_mrp.py index 7aefdabd9..ce5cc94f0 100644 --- a/quality_control_mrp/tests/test_quality_control_mrp.py +++ b/quality_control_mrp/tests/test_quality_control_mrp.py @@ -10,6 +10,7 @@ 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') @@ -20,6 +21,12 @@ class TestQualityControlMrp(TransactionCase): }) 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 +85,11 @@ class TestQualityControlMrp(TransactionCase): 'consume_produce') self.assertEqual(self.production1.created_inspections, 1, 'Only one inspection must be created') + + 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_stock/models/qc_inspection.py b/quality_control_stock/models/qc_inspection.py index 385adb92b..ba7382b6f 100644 --- a/quality_control_stock/models/qc_inspection.py +++ b/quality_control_stock/models/qc_inspection.py @@ -29,6 +29,8 @@ class QcInspection(models.Model): self.lot = self.object_id.lot_id elif self.object_id._name == 'stock.move': self.lot = self.object_id.lot_ids[:1] + elif self.object_id._name == 'stock.production.lot': + self.lot = self.object_id @api.one @api.depends('object_id') @@ -40,6 +42,8 @@ class QcInspection(models.Model): self.product = self.object_id.product_id elif self.object_id._name == 'stock.pack.operation': self.product = self.object_id.product_id + elif self.object_id._name == 'stock.production.lot': + self.product = self.object_id.product_id @api.onchange('object_id') def onchange_object_id(self): diff --git a/quality_control_stock/tests/test_quality_control_stock.py b/quality_control_stock/tests/test_quality_control_stock.py index ee8d8267b..bdb78bbc6 100644 --- a/quality_control_stock/tests/test_quality_control_stock.py +++ b/quality_control_stock/tests/test_quality_control_stock.py @@ -237,3 +237,14 @@ class TestQualityControl(TransactionCase): self.picking1.move_lines[:1].product_id) self.assertEquals(self.inspection1.qty, self.picking1.move_lines[:1].product_qty) + + def test_qc_inspection_lot(self): + self.inspection1.write({ + 'object_id': '%s,%d' % (self.lot._model, + self.lot.id), + }) + self.inspection1.onchange_object_id() + self.assertEquals(self.inspection1.lot, + self.lot) + self.assertEquals(self.inspection1.product, + self.lot.product_id)