Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
2754 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
1
juil. 23
2569
2
déc. 22
13653
4
déc. 22
8641
1
nov. 21
3787
2
avr. 21
2822