跳至内容
菜单
此问题已终结
1 回复
2366 查看

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
形象
丢弃
最佳答案

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


形象
丢弃
相关帖文 回复 查看 活动
1
5月 25
647
2
8月 25
164
1
7月 25
518
2
6月 25
2420
1
6月 25
887