This question has been flagged
3 Replies
3755 Views

I have this code. I need a function that filters all Tasks out that are in stage == "finished" . How Can I make that?

When the task is in stage finished it should't show up in the selector of all tasks.


This function shows me all tasks from a project and again all tasks that are in stage_id == finished


How Can I make that so, that all "finished" tasks are not showing in this selector include_in_task_work_view???

class ProjectWork(models.Model):

_inherit = 'project.task.work'

project = fields.Many2one(

string='Project', related='task_id.project_id', store=True,

domain="[('state', 'not in', ('template', 'cancelled', 'close'))]")

include_in_task_work_view = fields.Boolean(

related='task_id.stage_id.include_in_task_work_view', readonly=True,

store=True)

@api.onchange('project')

def onchange_project(self):

if not self.project:

return {'domain': {'task_id': []}}

return {

'domain': {

'task_id': [('project_id', '=', self.project.id),

('include_in_task_work_view', '=', True)]},

}

@api.onchange('task_id')

def onchange_task_id(self):

if not self.task_id:

return {}

return {'value': {'project': self.task_id.project_id.id}}

Avatar
Discard
Best Answer

Hi,

I didn't get the question very well, But you get the ids of the records not in finished state by using the search method:

not_finished_ids = self.search([('state', '!=', 'finished')]) ...

Hope this could help

Avatar
Discard
Author

I want a function that search all tasks that are not finished and that they display on this : @api.onchange('task_id') def onchange_task_id(self): if not self.task_id: return {} return {'value': {'project': self.task_id.project_id.id}}

Best Answer

Hi,


I honestly don't really get the question as well.


If what you want is to hide tasks from task selectors (many2one fields on other objects that link to a task), you could use the "active" field on tasks. The active field is used by the ORM/web client to hide things from list views, selectors, etc. automatically.

Avatar
Discard
Author

I want to hide all tasks that are in stage "finished" . I have this modul. https://www.odoo.com/apps/modules/8.0/project_work_time_control/ The Problem is , that the selector (field that shows all tasks) is not filtering the task. So all finished tasks are showed up. I want to hide all finished-tasks.