[FIX] stock: company_id on stock.move.line

Commit 240d191ba3 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) <sle@openerp.com>
This commit is contained in:
William Henrotin
2019-04-16 13:38:59 +00:00
parent 3992b01de1
commit 2b63b7e8ed
2 changed files with 2 additions and 8 deletions
+1 -7
View File
@@ -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
+1 -1
View File
@@ -101,7 +101,7 @@
<field name="name">stock_move_line multi-company</field>
<field name="model_id" search="[('model','=','stock.move.line')]" model="ir.model"/>
<field name="global" eval="True"/>
<field name="domain_force">[('company_id','child_of',[user.company_id.id])]</field>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
</record>
<record model="ir.rule" id="stock_quant_rule">