Skip to Content

Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
28 Views

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

Avatar
Discard

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

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!