Skip to Content
Menu
This question has been flagged
2 Replies
1104 Rodiniai

Hi to all

I build a custom app within I try to calculate a Date from an other one and an Int.


# Odoo saas~15.2+e (Enterprise Edition)

for record in self :
d = datetime.date(record['x_studio_dde'].year,record['x_studio_dde'].month,record['x_studio_dde'].day)
record['x_studio_dfe'] = d + datetime.timedelta(days = (record['x_studio_dure'] * 30))


On existing records, it works then Odoo sends me the following error

Traceback (most recent call last):
  File "/home/odoo/src/odoo/saas-15.2/odoo/tools/safe_eval.py", line 330, in safe_eval
    return unsafe_eval(c, globals_dict, locals_dict)
  File "", line 2, in 
AttributeError: 'bool' object has no attribute 'year'

If I change the root date... it works without error

If I change the Int value... error

If i remove all existing records and create a new first one.... error


Any idea ? Thanks in advance

Regards

Portretas
Atmesti
Best Answer

Try simplify it to 

record['x_studio_dfe'] = record.x_studio_dde + datetime.timedelta(days = (record['x_studio_dure'] * 30))

If any of the values used are empty/null then the calculation will not work. So new records will produce an error as the custom dates will be null. You need to add an 'if' condition so that the code only applies if the fields are not empty.

e.g. If record['x_studio_dde']

    execute code

Hope this helps


Portretas
Atmesti
Autorius Best Answer

Hi Lucas,

Thanks, it works! 

for beginners "If" statement starts with a minuscule "if"

Portretas
Atmesti