Hi,
In
your compute function code, there appears to be an error, particularly
in the computation of the date difference. Let's address the problem in
the third field:
Dependencies: x_studio_start_date, x_studio_end_date
Compute:
for record in self:
date_diff = (record.x_studio_end_date - record.x_studio_start_date).total_seconds() / 3600 if record.x_studio_start_date and record.x_studio_end_date else 0
record['x_studio_date_difference'] = date_diff
Explanation:
The
corrected code snippet calculates the date difference accurately by
subtracting the end date from the start date. Additionally, it ensures
that the computation only proceeds if both the start date and end date
are present. If either of these dates is missing, it sets the date
difference to zero.
This adjustment should resolve the error in
your compute function code. If you encounter any further issues or have
additional questions, feel free to ask for clarification.
Hope it helps
Hi Katalina,
I did test my solution, and when the date is changed it does recalculate the number of days. That's defining the computed field as "stored".
Don't forget to include both fields as dependencies.
Having said that, I have had problems before with computed fields! Maybe someone else can offer more advice!