[FIX] analytic: methods used in default attribute should return a RecordSet
If a method used as a default returns an id instead of a RecordSet, it could fail in 'convert_to_write' (Many2One field) because it will try to return "value.id". If "value" is an integer, it fails. Also changed the method to a lambda expression and removed the '_default_user' method because it's not used anywhere.
This commit is contained in:
@@ -41,14 +41,6 @@ class account_analytic_account(models.Model):
|
||||
account.credit = data_credit.get(account.id, 0.0)
|
||||
account.balance = account.credit - account.debit
|
||||
|
||||
@api.model
|
||||
def _default_company(self):
|
||||
return self.env.user.company_id.id
|
||||
|
||||
@api.model
|
||||
def _default_user(self):
|
||||
return self.env.user.id
|
||||
|
||||
name = fields.Char(string='Analytic Account', index=True, required=True, track_visibility='onchange')
|
||||
code = fields.Char(string='Reference', index=True, track_visibility='onchange')
|
||||
account_type = fields.Selection([
|
||||
@@ -58,7 +50,7 @@ class account_analytic_account(models.Model):
|
||||
tag_ids = fields.Many2many('account.analytic.tag', 'account_analytic_account_tag_rel', 'account_id', 'tag_id', string='Tags', copy=True)
|
||||
line_ids = fields.One2many('account.analytic.line', 'account_id', string="Analytic Lines")
|
||||
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=_default_company)
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
|
||||
partner_id = fields.Many2one('res.partner', string='Customer')
|
||||
|
||||
balance = fields.Monetary(compute='_compute_debit_credit_balance', string='Balance')
|
||||
|
||||
Reference in New Issue
Block a user