Skip to Content
Menú
This question has been flagged
1 Respondre
2370 Vistes

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
Avatar
Descartar
Best Answer

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


Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de maig 25
650
2
d’ag. 25
170
1
de jul. 25
524
2
de juny 25
2430
1
de juny 25
900