diff options
| author | Simon Lejeune <sle@openerp.com> | 2019-08-26 15:37:16 +0000 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2019-09-03 15:05:03 +0000 |
| commit | 9d4a5526906e20a8628d3f52674c466a0625bad7 (patch) | |
| tree | b6b87392100f49167872239c29b758ad483e72ec /addons | |
| parent | 96406dc2a9e06595961f6d4bec6b66f27b94e2ff (diff) | |
[REF] mrp_subcontracting: multi company
Ensure proper domains are applied and enforced on relation fields thanks
to the `check_company` attributes.
task-1985992
Diffstat (limited to 'addons')
5 files changed, 21 insertions, 10 deletions
diff --git a/addons/mrp_subcontracting/models/mrp_bom.py b/addons/mrp_subcontracting/models/mrp_bom.py index a0a1d054cb9..a34e3bda163 100644 --- a/addons/mrp_subcontracting/models/mrp_bom.py +++ b/addons/mrp_subcontracting/models/mrp_bom.py @@ -8,10 +8,11 @@ class MrpBom(models.Model): _inherit = 'mrp.bom' type = fields.Selection(selection_add=[('subcontract', 'Subcontracting')]) - subcontractor_ids = fields.Many2many('res.partner', 'mrp_bom_subcontractor', string='Subcontractors') + subcontractor_ids = fields.Many2many('res.partner', 'mrp_bom_subcontractor', string='Subcontractors', check_company=True) def _bom_subcontract_find(self, product_tmpl=None, product=None, picking_type=None, company_id=False, bom_type='subcontract', subcontractor=False): domain = self._bom_find_domain(product_tmpl=product_tmpl, product=product, picking_type=picking_type, company_id=company_id, bom_type=bom_type) if subcontractor: domain = AND([domain, [('subcontractor_ids', 'in', subcontractor.id)]]) return self.search(domain, order='subcontractor_ids, sequence, product_id', limit=1) + diff --git a/addons/mrp_subcontracting/models/stock_warehouse.py b/addons/mrp_subcontracting/models/stock_warehouse.py index 41e5d704bc1..ef1a605608e 100644 --- a/addons/mrp_subcontracting/models/stock_warehouse.py +++ b/addons/mrp_subcontracting/models/stock_warehouse.py @@ -110,6 +110,7 @@ class StockWarehouse(models.Model): 'use_create_components_lots': True, 'sequence': next_sequence + 2, 'sequence_code': 'SBC', + 'company_id': self.company_id.id, }, }) return data, max_sequence + 4 @@ -117,7 +118,7 @@ class StockWarehouse(models.Model): def _get_sequence_values(self): values = super(StockWarehouse, self)._get_sequence_values() values.update({ - 'subcontracting_type_id': {'name': self.name + ' ' + _('Sequence subcontracting'), 'prefix': self.code + '/SBC/', 'padding': 5}, + 'subcontracting_type_id': {'name': self.name + ' ' + _('Sequence subcontracting'), 'prefix': self.code + '/SBC/', 'padding': 5, 'company_id': self.company_id.id}, }) return values diff --git a/addons/mrp_subcontracting/tests/test_subcontracting.py b/addons/mrp_subcontracting/tests/test_subcontracting.py index 448eda56547..029d9e3a71f 100644 --- a/addons/mrp_subcontracting/tests/test_subcontracting.py +++ b/addons/mrp_subcontracting/tests/test_subcontracting.py @@ -429,15 +429,18 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): lot_c1 = self.env['stock.production.lot'].create({ 'name': 'LOT C1', - 'product_id': self.comp1.id + 'product_id': self.comp1.id, + 'company_id': self.env.company.id, }) lot_c2 = self.env['stock.production.lot'].create({ 'name': 'LOT C2', - 'product_id': self.comp2.id + 'product_id': self.comp2.id, + 'company_id': self.env.company.id, }) lot_f1 = self.env['stock.production.lot'].create({ 'name': 'LOT F1', - 'product_id': self.finished.id + 'product_id': self.finished.id, + 'company_id': self.env.company.id, }) register_form = Form(self.env['mrp.product.produce'].with_context( @@ -476,7 +479,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): corrected_final_lot = self.env['stock.production.lot'].create({ 'name': 'LOT F2', - 'product_id': self.finished.id + 'product_id': self.finished.id, + 'company_id': self.env.company.id, }) details_operation_form = Form(picking_receipt.move_lines, view=self.env.ref('stock.view_stock_move_operations')) @@ -594,11 +598,13 @@ class TestSubcontractingTracking(TransactionCase): lot_id = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.finished_lot.id + 'product_id': self.finished_lot.id, + 'company_id': self.env.company.id, }) serial_id = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.comp1_sn.id + 'product_id': self.comp1_sn.id, + 'company_id': self.env.company.id, }) produce_form = Form(self.env['mrp.product.produce'].with_context({ 'active_id': mo.id, diff --git a/addons/mrp_subcontracting/views/stock_move_views.xml b/addons/mrp_subcontracting/views/stock_move_views.xml index 565dece1ad6..63ccc1c0a62 100644 --- a/addons/mrp_subcontracting/views/stock_move_views.xml +++ b/addons/mrp_subcontracting/views/stock_move_views.xml @@ -7,11 +7,13 @@ <field name="arch" type="xml"> <form create="0" delete="0"> <sheet> + <field name="company_id" invisible="1"/> <field name="product_id" invisible="1"/> <field name="finished_lots_exist" invisible="1"/> <field name="state" invisible="1"/> <field name="move_line_ids" context="{'default_product_id': product_id}" attrs="{'readonly': [('state', 'in', ['done', 'cancel'])]}"> <tree editable="bottom" decoration-muted="state in ('done', 'cancel')"> + <field name="company_id" invisible="1"/> <field name="state" invisible="1"/> <field name="tracking" invisible="1"/> <field name="product_id" readonly="1"/> @@ -41,4 +43,4 @@ </xpath> </field> </record> -</odoo>
\ No newline at end of file +</odoo> diff --git a/addons/mrp_subcontracting/wizard/mrp_product_produce.py b/addons/mrp_subcontracting/wizard/mrp_product_produce.py index 0629bc64d68..db386fd0648 100644 --- a/addons/mrp_subcontracting/wizard/mrp_product_produce.py +++ b/addons/mrp_subcontracting/wizard/mrp_product_produce.py @@ -7,7 +7,7 @@ from odoo.tools.float_utils import float_is_zero class MrpProductProduce(models.TransientModel): _inherit = 'mrp.product.produce' - subcontract_move_id = fields.Many2one('stock.move', 'stock move from the subcontract picking') + subcontract_move_id = fields.Many2one('stock.move', 'stock move from the subcontract picking', check_company=True) def continue_production(self): action = super(MrpProductProduce, self).continue_production() @@ -53,3 +53,4 @@ class MrpProductProduce(models.TransientModel): ml.product_uom_qty = ml.qty_done self.subcontract_move_id._recompute_state() return res + |
