I have created a new model called project.phase, referenced on the project.project model from a one2many field (x_project_phaselist).
project.phase has the following fields: name, start_date, end_date, total_days, project_id
Working good. Now I need to get the overall for those phases to get the project totals.
I have managed to get the sum of total_days, using the following code:
for record in self: record['x_project_total_phases'] = sum(line['total_days'] for line in record['x_project_phaselist'])
Now I need to get the lowest start_date and the highest end_date, to be stored on two new fields on project.project. With the following code, I've been able to get the lowest date but from all the project.phase on all the projects, not the ones referenced on the actual project, referenced by project_id
for record in self:
recs = record['x_project_phaselist'].search([], order='start_date asc')
if recs:
record['x_project_min_date'] = recs[0].start_date
I need help to get only the phases for that project to be taken on account. Also I need help getting the higher end_date, as using the same but changing start_date for end_date and changing the asc for desc is not doing anything.
For info, I'm using the inbuilt editor, not coding new modules on .py but using the web builder, which I think is a very nice tool.