Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2358 Представления

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


Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мая 25
645
2
авг. 25
143
1
июл. 25
508
2
июн. 25
2412
1
июн. 25
876