diff options
| -rw-r--r-- | addons/mrp_subcontracting/tests/common.py | 59 | ||||
| -rw-r--r-- | addons/mrp_subcontracting/tests/test_subcontracting.py | 58 |
2 files changed, 62 insertions, 55 deletions
diff --git a/addons/mrp_subcontracting/tests/common.py b/addons/mrp_subcontracting/tests/common.py new file mode 100644 index 00000000000..f72e2f4923a --- /dev/null +++ b/addons/mrp_subcontracting/tests/common.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests.common import Form, SavepointCase + +class TestMrpSubcontractingCommon(SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestMrpSubcontractingCommon, cls).setUpClass() + # 1: Create a subcontracting partner + main_partner = cls.env['res.partner'].create({'name': 'main_partner'}) + cls.subcontractor_partner1 = cls.env['res.partner'].create({ + 'name': 'subcontractor_partner', + 'parent_id': main_partner.id, + 'company_id': cls.env.ref('base.main_company').id, + }) + + # 2. Create a BOM of subcontracting type + cls.comp1 = cls.env['product.product'].create({ + 'name': 'Component1', + 'type': 'product', + 'categ_id': cls.env.ref('product.product_category_all').id, + }) + cls.comp2 = cls.env['product.product'].create({ + 'name': 'Component2', + 'type': 'product', + 'categ_id': cls.env.ref('product.product_category_all').id, + }) + cls.finished = cls.env['product.product'].create({ + 'name': 'finished', + 'type': 'product', + 'categ_id': cls.env.ref('product.product_category_all').id, + }) + bom_form = Form(cls.env['mrp.bom']) + bom_form.type = 'subcontract' + bom_form.product_tmpl_id = cls.finished.product_tmpl_id + with bom_form.bom_line_ids.new() as bom_line: + bom_line.product_id = cls.comp1 + bom_line.product_qty = 1 + with bom_form.bom_line_ids.new() as bom_line: + bom_line.product_id = cls.comp2 + bom_line.product_qty = 1 + cls.bom = bom_form.save() + + # Create a BoM for cls.comp2 + cls.comp2comp = cls.env['product.product'].create({ + 'name': 'component for Component2', + 'type': 'product', + 'categ_id': cls.env.ref('product.product_category_all').id, + }) + bom_form = Form(cls.env['mrp.bom']) + bom_form.product_tmpl_id = cls.comp2.product_tmpl_id + with bom_form.bom_line_ids.new() as bom_line: + bom_line.product_id = cls.comp2comp + bom_line.product_qty = 1 + cls.comp2_bom = bom_form.save() + + cls.warehouse = cls.env['stock.warehouse'].search([], limit=1) diff --git a/addons/mrp_subcontracting/tests/test_subcontracting.py b/addons/mrp_subcontracting/tests/test_subcontracting.py index 6d42bed7e9d..f884e1be4f0 100644 --- a/addons/mrp_subcontracting/tests/test_subcontracting.py +++ b/addons/mrp_subcontracting/tests/test_subcontracting.py @@ -2,7 +2,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.tests import Form -from odoo.tests.common import SavepointCase, TransactionCase +from odoo.tests.common import TransactionCase +from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon from odoo.tests import tagged @@ -16,60 +17,7 @@ class TestSubcontractingBasic(TransactionCase): self.assertTrue(company2.subcontracting_location_id) self.assertTrue(self.env.company.subcontracting_location_id != company2.subcontracting_location_id) -class TestSubcontractingFlows(SavepointCase): - @classmethod - def setUpClass(cls): - super(TestSubcontractingFlows, cls).setUpClass() - # 1: Create a subcontracting partner - main_partner = cls.env['res.partner'].create({'name': 'main_partner'}) - cls.subcontractor_partner1 = cls.env['res.partner'].create({ - 'name': 'subcontractor_partner', - 'parent_id': main_partner.id, - 'company_id': cls.env.ref('base.main_company').id - }) - - # 2. Create a BOM of subcontracting type - cls.comp1 = cls.env['product.product'].create({ - 'name': 'Component1', - 'type': 'product', - 'categ_id': cls.env.ref('product.product_category_all').id, - }) - cls.comp2 = cls.env['product.product'].create({ - 'name': 'Component2', - 'type': 'product', - 'categ_id': cls.env.ref('product.product_category_all').id, - }) - cls.finished = cls.env['product.product'].create({ - 'name': 'finished', - 'type': 'product', - 'categ_id': cls.env.ref('product.product_category_all').id, - }) - bom_form = Form(cls.env['mrp.bom']) - bom_form.type = 'subcontract' - bom_form.product_tmpl_id = cls.finished.product_tmpl_id - with bom_form.bom_line_ids.new() as bom_line: - bom_line.product_id = cls.comp1 - bom_line.product_qty = 1 - with bom_form.bom_line_ids.new() as bom_line: - bom_line.product_id = cls.comp2 - bom_line.product_qty = 1 - cls.bom = bom_form.save() - - # Create a BoM for cls.comp2 - cls.comp2comp = cls.env['product.product'].create({ - 'name': 'component for Component2', - 'type': 'product', - 'categ_id': cls.env.ref('product.product_category_all').id, - }) - bom_form = Form(cls.env['mrp.bom']) - bom_form.product_tmpl_id = cls.comp2.product_tmpl_id - with bom_form.bom_line_ids.new() as bom_line: - bom_line.product_id = cls.comp2comp - bom_line.product_qty = 1 - cls.comp2_bom = bom_form.save() - - cls.warehouse = cls.env['stock.warehouse'].search([], limit=1) - +class TestSubcontractingFlows(TestMrpSubcontractingCommon): def test_flow_1(self): """ Don't tick any route on the components and trigger the creation of the subcontracting manufacturing order through a receipt picking. Create a reordering rule in the |
