Skip to Content
Menu
This question has been flagged
1 Reply
2539 Views

i am trying to add a new compute field that add a mounth from an existing date field 

the code is working on odoo13 but i don't know why it isn't on the odoo 8

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp.osv import expression

class contract(models.Model):
_inherit = 'res.contract'

mounth = fields.Datetime(string="Date plus mois", compute='_add_mth')
def _add_mth(self):
for order in self:
d = 1
if self.date_start:
date_st = fields.Datetime.from_string(self.date_start)
dt = date_start_dt + relativedelta(months=d)
mounth = fields.Datetime.to_string(dt)
order.update({'mounth': mounth})

i have this error message Expected singleton: res.contract(137, 138)

Avatar
Discard
Best Answer

Change "self.date_start" to "order.date_start" and the code should work. Also, make sure the indentation of the code is correct since this is not apparent from the snippet of code posted above.

Avatar
Discard
Related Posts Replies Views Activity
0
Jul 24
193
1
Jul 23
1861
2
Dec 22
12869
4
Dec 22
7959
1
Nov 21
3146