From 0c76bd3c6373de7bc89818f86d377eb61a74faba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Thu, 26 Apr 2018 09:19:38 +0200 Subject: [PATCH] [FIX] account_asset: avoid company mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was possible to change manually the company of an asset, although its category would be belonging to another company and thus its depreciation lines and journal items also. To tackle this problem, we set the company_id field of an asset as related to its category Was PR #23498. Courtesy of Miquel Raïch --- addons/account_asset/models/account_asset.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/account_asset/models/account_asset.py b/addons/account_asset/models/account_asset.py index 75d5467a94d..36fdb84cf21 100644 --- a/addons/account_asset/models/account_asset.py +++ b/addons/account_asset/models/account_asset.py @@ -72,8 +72,7 @@ class AccountAssetAsset(models.Model): value = fields.Float(string='Gross Value', required=True, readonly=True, digits=0, states={'draft': [('readonly', False)]}, oldname='purchase_value') currency_id = fields.Many2one('res.currency', string='Currency', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.user.company_id.currency_id.id) - company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, states={'draft': [('readonly', False)]}, - default=lambda self: self.env['res.company']._company_default_get('account.asset.asset')) + company_id = fields.Many2one('res.company', string='Company', readonly=True, related="category_id.company_id", store=True) note = fields.Text() category_id = fields.Many2one('account.asset.category', string='Category', required=True, change_default=True, readonly=True, states={'draft': [('readonly', False)]}) date = fields.Date(string='Date', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=fields.Date.context_today, oldname="purchase_date")