Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2740 Lượt xem

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)
Ảnh đại diện
Huỷ bỏ

What field is ejecuction?

Câu trả lời hay nhất

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)
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 11 22
6332
1
thg 6 22
8303
1
thg 9 21
3218
0
thg 8 21
95
0
thg 7 21
172