Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2929 Widoki

I want to mark scheduled activities a project task as over if it has been moved to a different stage(stage_id).

Scheduled Activity Creation

def_timesheet_create_task(self, project):
#send notification when task is created
    task = super()._timesheet_create_task(project)
    fornotified_userintask.stage_id.task_create_notified_groups.users:
        task.activity_schedule('mail.mail_activity_data_todo', user_id=notified_user.id)

Scheduled Activity Removal

@api.onchange("stage_id")
def_onchange_stage_id(self):
    self.activity_feedback(['mail.mail_activity_data_todo']) # Completes the acitivity but Throws error. 
It seems like the error is being triggered because the front-end is trying to read mail.message but fails because the mail.activity is gone due to onchange being run before it.

Console output

2022-08-03 02:13:20,600 47312 INFO odoo-dev4 werkzeug: 127.0.0.1 - - [03/Aug/2022 02:13:20] "POST /web/dataset/call_kw/project.task/onchange HTTP/1.1" 200 - 120 0.101 0.108

2022-08-03 02:13:20,608 47312 INFO odoo-dev4 werkzeug: 127.0.0.1 - - [03/Aug/2022 02:13:20] "POST /longpolling/poll HTTP/1.1" 200 - 11 0.016 7.770

2022-08-03 02:13:20,609 47312 INFO odoo-dev4 werkzeug: 127.0.0.1 - - [03/Aug/2022 02:13:20] "POST /longpolling/poll HTTP/1.1" 200 - 12 0.013 7.788

2022-08-03 02:13:20,610 47312 INFO odoo-dev4 werkzeug: 127.0.0.1 - - [03/Aug/2022 02:13:20] "POST /longpolling/poll HTTP/1.1" 200 - 11 0.015 7.777

2022-08-03 02:13:20,625 47312 INFO odoo-dev4 werkzeug: 127.0.0.1 - - [03/Aug/2022 02:13:20] "POST /web/dataset/call_kw/mail.message/read HTTP/1.1" 200 - 5 0.010 0.006

2022-08-03 02:13:20,655 47312 WARNING odoo-dev4 odoo.http: Record does not exist or has been deleted.

(Record: mail.activity(73,), User: 2) 

Awatar
Odrzuć
Autor Najlepsza odpowiedź

I managed to figure out the issue as well as find a solution. (sort of, i found a way to bypass the root cause)

Problem

If we unlink the activities in the onchange function, the subsequent call which is made to update the record using write(vals) will fail because for some reason vals will include the now-deleted activity.

Solution

Specific to my use case I was able to move the unlink from the onchange method to the write(self,val) method which I overrode.

defwrite(self, vals):
""" override write function so as to remove and re-attach new scheduled activities """
self.activity_feedback(['mail.mail_activity_data_todo']) #remove automated activities attached to task
super().write(vals)
#Add sheduled activities on the new user group
fornotified_userinself.stage_id.task_create_notified_groups.users:
self.activity_schedule('mail.mail_activity_data_todo', user_id=notified_user.id)

Each time the task is editted(using write). It unlinks the activity via activity_feedback() and creates a new one with the new user group computed from the task.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
gru 24
68834
2
maj 25
2642
2
lip 24
1733
1
paź 23
1954
2
paź 23
2157