The error also gives a hint
"
HINT: You will need to rewrite or cast the expression.
"
here's my python code:
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
start_date = fields.Date()
end_date = fields.Date()
total_months = fields.Integer(compute='_total_months')
deferred_revenue = fields.Boolean()
@api.multi
def _total_months(self):
if self.start_date and self.end_date:
for rec in self:
date1 = dt.strptime(str(rec.start_date), '%Y-%m-%d')
date2 = dt.strptime(str(rec.end_date), '%Y-%m-%d')
r = rd(date2, date1)
rec.total_months = r.months
@api.multi
def action_invoice_open(self):
res = super(AccountInvoice, self).action_invoice_open()
obj = self.env['account.asset.category'].browse([('method_number', '=', self.total_months)]).id
if self.deferred_revenue == True:
self.env['account.asset.asset'].create({
'name' : self.name or 'kkkkk',
'category_id' : obj,
'date' : self.date,
'value' : self.amount_total,
'partner_id' : self.partner_id.id,
'invoice_id' : self.id,
})
return res
i want 'category_id' to get a specified account from model 'account.asset.category' on the basis of total_months.
In model 'account.asset.category' method_number is defined. for example if total_months = 5 then the category_id should be 'cat 5' from 'account.asset.category' model. i've tried different solutions. hope I have explained my problem.
@niyas Thank You so much it worked (y)
Don't forget to upvote/accept answers if they've helped you. I'll accept this one as I consider it solved your issue.