Skip to Content
Menu
This question has been flagged
1 Reply
3245 Views

I'm working with project, task, timesheet modules. I've extended the project_task model with field finish_date that is Date. I've also extended the model project_task_type with field task_usage that is a Selection field.

Because some tasks don't have finish date, I've got to look at tasks write_date and the the usage of the stage that the stage is in a stage that finished tasks are. The task cannot be written to when it gets to one of this "finish" stages 

I need to get timesheets that are in between two dates and that the task was finished in that date interval. So if there is no finish_date it looks at write_date and checks that the task is in the correct stage.

I'm trying to get them with this search:

account_analytic_line_env = self.env['account.analytic.line']

finished_tasks_timesheets = account_analytic_line_env.sudo().search([
('task_id.project_id', '=', project.id),
('task_id.partner_id', '=', doc_data.partner_id.id),
('date', '>=', dates.get('date_from')),
('date', '<=', dates.get('date_to')),
'&', '|', '&', '&', '&', ('task_id.finish_date', '>=', dates.get('date_from')), ('task_id.finish_date', '<=', dates.get('date_to')),
('task_id.finish_date', '=', False),
('task_id.write_date', '>=', '{} 00:00:00'.format(dates.get('date_from'))), ('task_id.write_date', '<=', '{} 23:59:59'.format(dates.get('date_to'))),
('task_id.stage_id.task_usage', 'in', ['3', '4', '5'])
], order='task_id asc')

I need to get it like (not real SQL syntax not going to write all the joins only the WHERE clause with odoo relation fields and the base (FROM) is the timesheet model):

WHERE task_id.project_id = project.id AND task_id.partner_id = doc_data.partner_id.id
AND (date >= dates.get('date_from') AND date <= dates.get('date_to'))
AND (
(task_id.finish_date >= dates.get('date_from') AND task_id.finish_date <= dates.get('date_to'))
OR 
(task_id.finish_date = False AND 
(task_id.write_date >= '{} 00:00:00'.format(dates.get('date_from')) AND task_id.write_date <= '{} 23:59:59'.format(dates.get('date_to')))
AND task_id.stage_id.task_usage IN ('3', '4', '5')
)
 

Hope I've gotten all the "()" right because this new forum text field is just bad compared to the old one. :(

Can' someone help me this search "query"?  


Avatar
Discard
Author Best Answer

Don't bother with the answer... I've gotten all timesheets and just used a few of if else to do the job. 

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 22
14217
1
Apr 20
142
2
Jun 18
89
0
Mar 18
4901
3
May 24
2627