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

I have created a scheduled action on ir.cron , and i want to change the task from one stage to another stage based on deadline on the task.
Maybe there will be 3 projects with different tasks , how to get the tasks that belong only to a project through code , and how to stop it after only one change of stage when the deadline has passed.

def _change_task(self):
today = date.today()
get_list = self.env['project.task'].search([('date_deadline', ', today)])
get_task = self.env['project.task.type'].search([(])
for rec in get_task:
for line in get_list:
line.write({
'stage_id': rec.id,
})
return True
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You can try this method


from datetime import date

from odoo import models, fields


class YourModelName(models.Model):

_inherit = 'your.model.name' # Replace with the actual model you're working with


def _change_task(self):

today = date.today()

deadline_passed = fields.Date.from_string(today) > fields.Date.from_string(self.date_deadline)


if deadline_passed and self.stage_id: # Only change stage if the deadline has passed and there is a current stage

new_stage = self.env['project.task.type'].search([(your_domain_condition)])

if new_stage:

self.write({

'stage_id': new_stage.id,

})

return True


Hope it helps


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 25
687
2
thg 8 25
230
1
thg 7 25
552
2
thg 6 25
2482
1
thg 6 25
940