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

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
645
2
8月 25
161
1
7月 25
514
2
6月 25
2419
1
6月 25
883