From d479315e18ab8c2e2b5947cb7530458045cc50d4 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 23 Sep 2024 21:13:31 +0530 Subject: [PATCH] fix: unassign and assign if task user is changed --- crm/fcrm/doctype/crm_task/crm_task.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crm/fcrm/doctype/crm_task/crm_task.py b/crm/fcrm/doctype/crm_task/crm_task.py index 73ed845b..fed31c1c 100644 --- a/crm/fcrm/doctype/crm_task/crm_task.py +++ b/crm/fcrm/doctype/crm_task/crm_task.py @@ -12,6 +12,17 @@ class CRMTask(Document): def after_insert(self): self.assign_to() + def validate(self): + if self.is_new() or not self.assigned_to: + return + + if self.get_doc_before_save().assigned_to != self.assigned_to: + self.unassign_from_previous_user(self.get_doc_before_save().assigned_to) + self.assign_to() + + def unassign_from_previous_user(self, user): + unassign(self.doctype, self.name, user) + def assign_to(self): if self.assigned_to: assign({