diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-09-13 18:07:59 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-09-13 18:07:59 +0200 |
| commit | 6c948c36bbf72dd896e0bff03aa7fbddadcbb0cd (patch) | |
| tree | f8620905c011735d8a3c340c46d1417a54a75972 /addons/mrp/tests/test_multicompany.py | |
| parent | 48503fcf08eac6fed12e080d4f501f9bbc8d257d (diff) | |
| parent | 197474e5b9ad43ab2d587a98136a1a809ce9a2e7 (diff) | |
[MERGE] forward port branch saas-12.5 up to 197474e5b9a
Diffstat (limited to 'addons/mrp/tests/test_multicompany.py')
| -rw-r--r-- | addons/mrp/tests/test_multicompany.py | 219 |
1 files changed, 197 insertions, 22 deletions
diff --git a/addons/mrp/tests/test_multicompany.py b/addons/mrp/tests/test_multicompany.py index fe3b38cd3a5..5b43be07224 100644 --- a/addons/mrp/tests/test_multicompany.py +++ b/addons/mrp/tests/test_multicompany.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.tests import common +from odoo.tests import common, Form +from odoo.exceptions import UserError class TestMrpMulticompany(common.TransactionCase): @@ -10,24 +11,198 @@ class TestMrpMulticompany(common.TransactionCase): super(TestMrpMulticompany, self).setUp() group_user = self.env.ref('base.group_user') - group_stock_manager = self.env.ref('stock.group_stock_manager') - company_2 = self.env.ref('stock.res_company_1') - self.multicompany_user_id = self.env['res.users'].create({ - 'name': 'multicomp', - 'login': 'multicomp', - 'groups_id': [(6, 0, [group_user.id, group_stock_manager.id])], - 'company_id': company_2.id, - 'company_ids': [(6, 0, [company_2.id])] - }) - - def test_00_multicompany_user(self): - """check no error on getting default mrp.production values in multicompany setting""" - StockLocation = self.env['stock.location'].with_user(self.multicompany_user_id) - fields = ['location_src_id', 'location_dest_id'] - defaults = StockLocation.default_get(['location_id', 'location_dest_id', 'type']) - for field in fields: - if defaults.get(field): - try: - StockLocation.check_access_rule([defaults[field]], 'read') - except Exception as exc: - assert False, "unreadable location %s: %s" % (field, exc) + group_mrp_manager = self.env.ref('mrp.group_mrp_manager') + self.company_a = self.env['res.company'].create({'name': 'Company A'}) + self.company_b = self.env['res.company'].create({'name': 'Company B'}) + self.warehouse_a = self.env['stock.warehouse'].search([('company_id', '=', self.company_a.id)], limit=1) + self.warehouse_b = self.env['stock.warehouse'].search([('company_id', '=', self.company_b.id)], limit=1) + self.stock_location_a = self.warehouse_a.lot_stock_id + self.stock_location_b = self.warehouse_b.lot_stock_id + + self.user_a = self.env['res.users'].create({ + 'name': 'user company a with access to company b', + 'login': 'user a', + 'groups_id': [(6, 0, [group_user.id, group_mrp_manager.id])], + 'company_id': self.company_a.id, + 'company_ids': [(6, 0, [self.company_a.id, self.company_b.id])] + }) + self.user_b = self.env['res.users'].create({ + 'name': 'user company a with access to company b', + 'login': 'user b', + 'groups_id': [(6, 0, [group_user.id, group_mrp_manager.id])], + 'company_id': self.company_b.id, + 'company_ids': [(6, 0, [self.company_a.id, self.company_b.id])] + }) + + def test_bom_1(self): + """Check it is not possible to use a product of Company B in a + bom of Company A. """ + + product_b = self.env['product.product'].create({ + 'name': 'p1', + 'company_id': self.company_b.id, + }) + with self.assertRaises(UserError): + self.env['mrp.bom'].create({ + 'product_id': product_b.id, + 'product_tmpl_id': product_b.product_tmpl_id.id, + 'company_id': self.company_a.id, + }) + + def test_bom_2(self): + """Check it is not possible to use a product of Company B as a component + in a bom of Company A. """ + + product_a = self.env['product.product'].create({ + 'name': 'p1', + 'company_id': self.company_a.id, + }) + product_b = self.env['product.product'].create({ + 'name': 'p2', + 'company_id': self.company_b.id, + }) + with self.assertRaises(UserError): + self.env['mrp.bom'].create({ + 'product_id': product_a.id, + 'product_tmpl_id': product_b.product_tmpl_id.id, + 'company_id': self.company_a.id, + 'bom_line_ids': [(0, 0, {'product_id': product_b.id})] + }) + + def test_production_1(self): + """Check it is not possible to confirm a production of Company B with + product of Company A. """ + + product_a = self.env['product.product'].create({ + 'name': 'p1', + 'company_id': self.company_a.id, + }) + mo = self.env['mrp.production'].create({ + 'product_id': product_a.id, + 'product_uom_id': product_a.uom_id.id, + 'company_id': self.company_b.id, + }) + with self.assertRaises(UserError): + mo.action_confirm() + + def test_production_2(self): + """Check that confirming a production in company b with user_a will create + stock moves on company b. """ + + product_a = self.env['product.product'].create({ + 'name': 'p1', + 'company_id': self.company_a.id, + }) + component_a = self.env['product.product'].create({ + 'name': 'p2', + 'company_id': self.company_a.id, + }) + self.env['mrp.bom'].create({ + 'product_id': product_a.id, + 'product_tmpl_id': product_a.product_tmpl_id.id, + 'company_id': self.company_a.id, + 'bom_line_ids': [(0, 0, {'product_id': component_a.id})] + }) + mo_form = Form(self.env['mrp.production'].with_user(self.user_a)) + mo_form.product_id = product_a + mo = mo_form.save() + mo.with_user(self.user_b).action_confirm() + self.assertEqual(mo.move_raw_ids.company_id, self.company_a) + self.assertEqual(mo.move_finished_ids.company_id, self.company_a) + + def test_product_produce_1(self): + """Check that using a finished lot of company b in the produce wizard of a production + of company a is not allowed """ + + product = self.env['product.product'].create({ + 'name': 'p1', + 'tracking': 'lot', + }) + component = self.env['product.product'].create({ + 'name': 'p2', + }) + lot_b = self.env['stock.production.lot'].create({ + 'product_id': product.id, + 'company_id': self.company_b.id, + }) + self.env['mrp.bom'].create({ + 'product_id': product.id, + 'product_tmpl_id': product.product_tmpl_id.id, + 'company_id': self.company_a.id, + 'bom_line_ids': [(0, 0, {'product_id': component.id})] + }) + mo_form = Form(self.env['mrp.production'].with_user(self.user_a)) + mo_form.product_id = product + mo = mo_form.save() + mo.with_user(self.user_b).action_confirm() + produce_form = Form(self.env['mrp.product.produce'].with_user(self.user_b).with_context({ + 'active_id': mo.id, + 'active_ids': [mo.id], + })) + produce_form.finished_lot_id = lot_b + with self.assertRaises(UserError): + produce_form.save() + + def test_product_produce_2(self): + """Check that using a component lot of company b in the produce wizard of a production + of company a is not allowed """ + + product = self.env['product.product'].create({ + 'name': 'p1', + }) + component = self.env['product.product'].create({ + 'name': 'p2', + 'tracking': 'lot', + }) + lot_b = self.env['stock.production.lot'].create({ + 'product_id': component.id, + 'company_id': self.company_b.id, + }) + self.env['mrp.bom'].create({ + 'product_id': product.id, + 'product_tmpl_id': product.product_tmpl_id.id, + 'company_id': self.company_a.id, + 'bom_line_ids': [(0, 0, {'product_id': component.id})] + }) + mo_form = Form(self.env['mrp.production'].with_user(self.user_a)) + mo_form.product_id = product + mo = mo_form.save() + mo.with_user(self.user_b).action_confirm() + produce_form = Form(self.env['mrp.product.produce'].with_user(self.user_b).with_context({ + 'active_id': mo.id, + 'active_ids': [mo.id], + })) + with produce_form.raw_workorder_line_ids.edit(0) as line: + line.lot_id = lot_b + with self.assertRaises(UserError): + produce_form.save() + + def test_workcenter_1(self): + """Check it is not possible to use a routing of Company B in a + workcenter of Company A. """ + + workcenter = self.env['mrp.workcenter'].create({ + 'name': 'WC1', + 'company_id': self.company_a.id, + 'resource_calendar_id': self.company_a.resource_calendar_id.id, + }) + with self.assertRaises(UserError): + self.env['mrp.routing'].create({ + 'name': 'WC1', + 'company_id': self.company_b.id, + 'operation_ids': [(0, 0, { + 'name': 'operation_1', + 'workcenter_id': workcenter.id, + })] + }) + + def test_partner_1(self): + """ On a product without company, as a user of Company B, check it is not possible to use a + location limited to Company A as `property_stock_production` """ + + shared_product = self.env['product.product'].create({ + 'name': 'Shared Product', + 'company_id': False, + }) + with self.assertRaises(UserError): + shared_product.with_user(self.user_b).property_stock_production = self.stock_location_a |
