From b923601c38fbdf8a7c0c9574d57ecca3246f9262 Mon Sep 17 00:00:00 2001 From: lreficent Date: Mon, 18 Dec 2017 13:25:57 +0100 Subject: [PATCH] [9.0][IMP] mrp_production_unreserve: add tests --- .../models/mrp_production.py | 2 +- mrp_production_unreserve/tests/__init__.py | 4 + .../tests/test_mrp_production_unreserve.py | 76 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 mrp_production_unreserve/tests/__init__.py create mode 100644 mrp_production_unreserve/tests/test_mrp_production_unreserve.py diff --git a/mrp_production_unreserve/models/mrp_production.py b/mrp_production_unreserve/models/mrp_production.py index 5d1004b1c..65dfa95c1 100644 --- a/mrp_production_unreserve/models/mrp_production.py +++ b/mrp_production_unreserve/models/mrp_production.py @@ -10,7 +10,7 @@ class MrpProduction(models.Model): _inherit = "mrp.production" unreserve_visible = fields.Boolean( - string='Inventory Unreserve Visible', + string='MO Unreserve Visible', compute='_compute_unreserve_visible', help='Technical field to check when we can unreserve', ) diff --git a/mrp_production_unreserve/tests/__init__.py b/mrp_production_unreserve/tests/__init__.py new file mode 100644 index 000000000..f2b64ec5a --- /dev/null +++ b/mrp_production_unreserve/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_mrp_production_unreserve diff --git a/mrp_production_unreserve/tests/test_mrp_production_unreserve.py b/mrp_production_unreserve/tests/test_mrp_production_unreserve.py new file mode 100644 index 000000000..ef62d7365 --- /dev/null +++ b/mrp_production_unreserve/tests/test_mrp_production_unreserve.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import TransactionCase + + +class TestMrpProductionUnreserve(TransactionCase): + def setUp(self, *args, **kwargs): + super(TestMrpProductionUnreserve, self).setUp(*args, **kwargs) + self.production_model = self.env['mrp.production'] + self.bom_model = self.env['mrp.bom'] + self.product_model = self.env['product.product'] + self.quant_model = self.env['stock.quant'] + + # Create products, BoM and MO: + self.product = self.product_model.create({ + 'name': 'Test Product', + 'type': 'product', + }) + self.component_a = self.product_model.create({ + 'name': 'Component A', + 'type': 'product', + }) + self.component_b = self.product_model.create({ + 'name': 'Component B', + 'type': 'product', + }) + self.test_bom = self.bom_model.create({ + 'product_tmpl_id': self.product.product_tmpl_id.id, + 'product_qty': 1, + 'code': 'TEST', + 'bom_line_ids': [ + (0, 0, { + 'product_id': self.component_a.id, + 'product_qty': 2, + }), + (0, 0, { + 'product_id': self.component_b.id, + 'product_qty': 1, + }) + ], + }) + self.test_mo = self.production_model.create({ + 'product_id': self.product.id, + 'product_qty': 5.0, + 'product_uom': self.product.uom_id.id, + 'bom_id': self.test_bom.id, + }) + # Create Stock for components: + wh_main = self.browse_ref('stock.warehouse0') + stock_location_id = wh_main.lot_stock_id.id + self.quant_model.create({ + 'product_id': self.component_a.id, + 'location_id': stock_location_id, + 'qty': 10.0, + }) + self.quant_model.create({ + 'product_id': self.component_b.id, + 'location_id': stock_location_id, + 'qty': 5.0, + }) + + def test_mo_unreserve(self): + self.test_mo._compute_unreserve_visible() + self.assertFalse(self.test_mo.unreserve_visible) + self.assertFalse(self.test_mo.move_lines) + self.test_mo.action_confirm() + self.test_mo.action_assign() + for l in self.test_mo.move_lines: + self.assertEqual(l.state, 'assigned') + self.test_mo._compute_unreserve_visible() + self.assertTrue(self.test_mo.unreserve_visible) + self.test_mo.button_unreserve() + for l in self.test_mo.move_lines: + self.assertEqual(l.state, 'confirmed')