Maintainers
+Maintainers
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose diff --git a/quality_control_stock_oca/tests/test_quality_control_stock.py b/quality_control_stock_oca/tests/test_quality_control_stock.py index f790f546fa3..66a572fb53c 100644 --- a/quality_control_stock_oca/tests/test_quality_control_stock.py +++ b/quality_control_stock_oca/tests/test_quality_control_stock.py @@ -1,6 +1,7 @@ # Copyright 2015 Oihane Crucelaegui - AvanzOSC # Copyright 2018 Simone Rubino - Agile Business Group # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + from odoo.tests import Form, new_test_user from odoo.tools import mute_logger @@ -57,15 +58,25 @@ def setUpClass(cls): move_form.product_id = cls.product move_form.product_uom_qty = 2 cls.picking1 = picking_form.save() - cls.picking1.action_confirm() - cls.picking1.move_ids.move_line_ids.qty_done = 1 + + def picking_confirmation(self): + self.picking1.action_confirm() + self.picking1.move_ids.move_line_ids.qty_done = 1 @mute_logger("odoo.models.unlink") def test_inspection_create_for_product(self): + self.picking_confirmation() self.product.qc_triggers = [ - (0, 0, {"trigger": self.trigger.id, "test": self.test.id}) + ( + 0, + 0, + {"trigger": self.trigger.id, "test": self.test.id, "timing": "after"}, + ) ] self.picking1._action_done() + # Just so _compute_count_inspections() is triggered + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 1, "Only one inspection must be created" ) @@ -79,12 +90,71 @@ def test_inspection_create_for_product(self): inspection.onchange_object_id() self.assertEqual(inspection.qty, self.picking1.move_ids.product_uom_qty) + @mute_logger("odoo.models.unlink") + def test_inspection_create_for_product_with_before_timing(self): + self.product.qc_triggers = [ + ( + 0, + 0, + {"trigger": self.trigger.id, "test": self.test.id, "timing": "before"}, + ) + ] + self.picking_confirmation() + # Just so _compute_count_inspections() is triggered + # pylint: disable=W0104 + self.picking1.qc_inspections_ids + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + inspection = self.picking1.qc_inspections_ids[:1] + self.assertEqual(inspection.state, "ready") + self.assertEqual(inspection.qty, self.picking1.move_ids.product_uom_qty) + self.assertEqual( + inspection.test, self.test, "Wrong test picked when creating inspection." + ) + + @mute_logger("odoo.models.unlink") + def test_inspection_create_for_product_with_plan_ahead_timing(self): + self.product.qc_triggers = [ + ( + 0, + 0, + { + "trigger": self.trigger.id, + "test": self.test.id, + "timing": "plan_ahead", + }, + ) + ] + self.picking_confirmation() + # Just so _compute_count_inspections() is triggered + # pylint: disable=W0104 + self.picking1.qc_inspections_ids + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + inspection = self.picking1.qc_inspections_ids[:1] + self.assertEqual(inspection.state, "plan") + self.assertEqual(inspection.qty, self.picking1.move_ids.product_uom_qty) + self.assertEqual( + inspection.test, self.test, "Wrong test picked when creating inspection." + ) + self.picking1._action_done() + self.assertEqual(inspection.state, "ready") + @mute_logger("odoo.models.unlink") def test_inspection_create_for_template(self): + self.picking_confirmation() self.product.product_tmpl_id.qc_triggers = [ - (0, 0, {"trigger": self.trigger.id, "test": self.test.id}) + ( + 0, + 0, + {"trigger": self.trigger.id, "test": self.test.id, "timing": "after"}, + ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 1, "Only one inspection must be created" ) @@ -96,10 +166,17 @@ def test_inspection_create_for_template(self): @mute_logger("odoo.models.unlink") def test_inspection_create_for_category(self): + self.picking_confirmation() self.product.categ_id.qc_triggers = [ - (0, 0, {"trigger": self.trigger.id, "test": self.test.id}) + ( + 0, + 0, + {"trigger": self.trigger.id, "test": self.test.id, "timing": "after"}, + ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 1, "Only one inspection must be created" ) @@ -111,6 +188,7 @@ def test_inspection_create_for_category(self): @mute_logger("odoo.models.unlink") def test_inspection_create_for_product_partner(self): + self.picking_confirmation() self.product.qc_triggers = [ ( 0, @@ -123,6 +201,8 @@ def test_inspection_create_for_product_partner(self): ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 1, "Only one inspection must be created" ) @@ -134,6 +214,7 @@ def test_inspection_create_for_product_partner(self): @mute_logger("odoo.models.unlink") def test_inspection_create_for_template_partner(self): + self.picking_confirmation() self.product.product_tmpl_id.qc_triggers = [ ( 0, @@ -146,6 +227,8 @@ def test_inspection_create_for_template_partner(self): ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 1, "Only one inspection must be created" ) @@ -157,6 +240,7 @@ def test_inspection_create_for_template_partner(self): @mute_logger("odoo.models.unlink") def test_inspection_create_for_category_partner(self): + self.picking_confirmation() self.product.categ_id.qc_triggers = [ ( 0, @@ -169,6 +253,8 @@ def test_inspection_create_for_category_partner(self): ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 1, "Only one inspection must be created" ) @@ -180,6 +266,7 @@ def test_inspection_create_for_category_partner(self): @mute_logger("odoo.models.unlink") def test_inspection_create_for_product_wrong_partner(self): + self.picking_confirmation() self.product.qc_triggers = [ ( 0, @@ -192,12 +279,15 @@ def test_inspection_create_for_product_wrong_partner(self): ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 0, "No inspection must be created" ) @mute_logger("odoo.models.unlink") def test_inspection_create_for_template_wrong_partner(self): + self.picking_confirmation() self.product.product_tmpl_id.qc_triggers = [ ( 0, @@ -210,12 +300,15 @@ def test_inspection_create_for_template_wrong_partner(self): ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 0, "No inspection must be created" ) @mute_logger("odoo.models.unlink") def test_inspection_create_for_category_wrong_partner(self): + self.picking_confirmation() self.product.categ_id.qc_triggers = [ ( 0, @@ -228,12 +321,15 @@ def test_inspection_create_for_category_wrong_partner(self): ) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 0, "No inspection must be created" ) @mute_logger("odoo.models.unlink") def test_inspection_create_only_one(self): + self.picking_confirmation() self.product.qc_triggers = [ (0, 0, {"trigger": self.trigger.id, "test": self.test.id}) ] @@ -241,6 +337,8 @@ def test_inspection_create_only_one(self): (0, 0, {"trigger": self.trigger.id, "test": self.test.id}) ] self.picking1._action_done() + # pylint: disable=W0104 + self.picking1.qc_inspections_ids self.assertEqual( self.picking1.created_inspections, 1, "Only one inspection must be created" ) @@ -293,6 +391,7 @@ def test_qc_inspection_picking(self): self.assertEqual(self.inspection1.picking_id, self.picking1) def test_qc_inspection_stock_move(self): + self.picking_confirmation() self.inspection1.write( { "name": self.picking1.move_ids[:1]._name + "inspection",