跳至內容
選單
此問題已被標幟
1 回覆
2722 瀏覽次數

In proyects, in every task i have a "total float field", and i need to sum the totals of tasks and render it in the project view, but only the tasks that are in the stage "To do".

this is my code, but is not working.

@api.depends('tasks.sum_total_cost')
    def todo_sum(self):
        todo = self.env['project.task'].search([('stage_id', '=', 'To Do')])
        for task in todo:
            task.sum_todo= round(sum(task.mapped('sum_total_cost')), 2)
頭像
捨棄

What field is ejecuction?

最佳答案

You just need to apply the sum after filtering with the correct path.

Try this


@api.depends('tasks.sum_total_cost')
def todo_sum(self):
  todo = self.env['project.task'].search([('stage_id', '=', 'To Do')])
for data in todo:
if data:
self.sum_todo = round(sum(todo.mapped('sum_total_cost')), 2)
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
11月 22
6262
1
6月 22
8248
1
9月 21
3171
0
8月 21
95
0
7月 21
172