From 2b63b7e8edfd052682bb01be7a2b4f66c1f6e8fb Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Tue, 16 Apr 2019 13:38:59 +0000 Subject: [PATCH] [FIX] stock: company_id on stock.move.line Commit 240d191ba302e6df200f7c91898c83c08ced758a introduced the field company_id on model stock.move.line and a python constraint that check if the company is the same on the move line and on the related move. In order to avoid performance issue, this commit replace the constraint by a 'related' parameter on the company field. As the company_id is not editable we suppose this change will not introduced unwanted errors Task : 1970012 closes odoo/odoo#32738 Signed-off-by: Simon Lejeune (sle) --- addons/stock/models/stock_move_line.py | 8 +------- addons/stock/security/stock_security.xml | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 0334981c217..68e5f3c3aad 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -21,7 +21,7 @@ class StockMoveLine(models.Model): move_id = fields.Many2one( 'stock.move', 'Stock Move', help="Change to a better name", index=True) - company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env['res.users']._get_company(), readonly=True) + company_id = fields.Many2one('res.company', string='Company', related='move_id.company_id', store=True, readonly=True) product_id = fields.Many2one('product.product', 'Product', ondelete="cascade") product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True) product_qty = fields.Float( @@ -74,12 +74,6 @@ class StockMoveLine(models.Model): if line.lot_id and line.product_id != line.lot_id.product_id: raise ValidationError(_('This lot %s is incompatible with this product %s' % (line.lot_id.name, line.product_id.display_name))) - @api.constrains('company_id', 'move_id') - def _check_same_company_id(self): - for line in self: - if line.move_id and line.move_id.company_id != line.company_id: - raise ValidationError(_('The move line a a different company than its move')) - @api.one def _set_product_qty(self): """ The meaning of product_qty field changed lately and is now a functional field computing the quantity diff --git a/addons/stock/security/stock_security.xml b/addons/stock/security/stock_security.xml index e33e665842a..87c63386ca7 100644 --- a/addons/stock/security/stock_security.xml +++ b/addons/stock/security/stock_security.xml @@ -101,7 +101,7 @@ stock_move_line multi-company - [('company_id','child_of',[user.company_id.id])] + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]