From 5cffea8f916a7db26eaf6a2350e2e7b997eb31f9 Mon Sep 17 00:00:00 2001 From: jayraj-omnia Date: Tue, 7 Jan 2025 14:38:15 +0530 Subject: [PATCH] [MOD] activity unlink issue fix --- .../data/mail_activity_data.xml | 2 +- activity_validation/models/mail_activity.py | 18 ++----- .../models/mail_activity_shedule.py | 49 ++++++++++++------- activity_validation/views/mail_activity.xml | 8 +-- plm/data/data.xml | 1 - plm/views/mail_activity_type.xml | 1 + 6 files changed, 38 insertions(+), 41 deletions(-) diff --git a/activity_validation/data/mail_activity_data.xml b/activity_validation/data/mail_activity_data.xml index 27c16f9e..009a01ac 100755 --- a/activity_validation/data/mail_activity_data.xml +++ b/activity_validation/data/mail_activity_data.xml @@ -9,7 +9,7 @@ product.product 200 request + True - diff --git a/activity_validation/models/mail_activity.py b/activity_validation/models/mail_activity.py index d5ec9e63..b02cfbd2 100755 --- a/activity_validation/models/mail_activity.py +++ b/activity_validation/models/mail_activity.py @@ -100,11 +100,8 @@ def changeActivityTypeId(self): def write(self, vals): ret = super(MailActivity, self).write(vals) - for activity_id in self: - if self.env.user.has_group('activity_validation.group_force_activity_validation_admin'): - return ret - if activity_id.plm_state == 'done' and 'plm_state' not in vals: - raise UserError('You cannot modify a confirmed activity') + if self.env.user.has_group('activity_validation.group_force_activity_validation_admin'): + return ret return ret def checkConfirmed(self, check=False): @@ -157,13 +154,6 @@ def isCustomType(self): return True return False - def unlink(self): - for activity_id in self: - if activity_id.isCustomType(): - if not self.env.su: - return - return super(MailActivity, self).unlink() - def clearChildrenActivities(self): for child_id in self.children_ids: for child_rel in child_id.mail_children_activity_id.sudo(): @@ -193,7 +183,7 @@ def action_to_done(self): if child_activity_id.plm_state != 'done': close = False if close: - parents._action_done() + parents.children_ids.mail_children_activity_id._action_done() else: activity_id._action_done() @@ -217,7 +207,7 @@ def action_to_cancel(self): def cancelChildrenECR(self, activity_id): for child in activity_id.children_ids: if child.plm_state not in ['done', 'cancel']: - child.action_to_cancel() + child.mail_children_activity_id.action_to_cancel() def cancelChildrenECO(self, activity_id): for child in activity_id.children_ids: diff --git a/activity_validation/models/mail_activity_shedule.py b/activity_validation/models/mail_activity_shedule.py index 57629003..72c628c3 100644 --- a/activity_validation/models/mail_activity_shedule.py +++ b/activity_validation/models/mail_activity_shedule.py @@ -55,15 +55,25 @@ class MailActivitySchedule(models.TransientModel): def _action_schedule_activities(self): res = super()._action_schedule_activities() - res.write({ - 'children_ids': [ - (0, 0, { - 'name': self.children_ids.name, - 'user_id': self.children_ids.user_id.id, - 'mail_children_activity_id' : res.id - }), - ] - }) + children_data = [] + for child in self.children_ids: + activity = self.env['mail.activity'].create({ + 'summary': res.summary, + 'activity_type_id': res.activity_type_id.id, + 'user_id': child.user_id.id, + 'res_model_id':res.res_model_id.id, + 'date_deadline':res.date_deadline, + 'res_id': res.res_id, + }) + children_data.append({ + 'name': child.name, + 'user_id': child.user_id.id, + 'mail_children_activity_id': activity.id, + }) + + if children_data: + res.write({'children_ids': [(0, 0, data) for data in children_data]}) + return res def _compute_mail_activity_type(self): @@ -115,11 +125,8 @@ def changeActivityTypeId(self): def write(self, vals): ret = super(MailActivitySchedule, self).write(vals) - for activity_id in self: - if self.env.user.has_group('activity_validation.group_force_activity_validation_admin'): - return ret - if activity_id.plm_state == 'done' and 'plm_state' not in vals: - raise UserError('You cannot modify a confirmed activity') + if self.env.user.has_group('activity_validation.group_force_activity_validation_admin'): + return ret return ret def checkConfirmed(self, check=False): @@ -224,11 +231,15 @@ def action_to_exception(self): def action_to_cancel(self): for activity_id in self: - activity_id.plm_state = 'cancel' - self.cancelChildrenECO(activity_id) - self.cancelChildrenECR(activity_id) - activity_id._action_done() - + if activity_id._name == 'mail.activity': + activity_id.plm_state = 'cancel' + self.cancelChildrenECO(activity_id) + self.cancelChildrenECR(activity_id) + activity_id._action_done() + else: + return { + 'type': 'ir.actions.act_window_close', + } def cancelChildrenECR(self, activity_id): for child in activity_id.children_ids: if child.plm_state not in ['done', 'cancel']: diff --git a/activity_validation/views/mail_activity.xml b/activity_validation/views/mail_activity.xml index 1111c903..20e7aa5a 100755 --- a/activity_validation/views/mail_activity.xml +++ b/activity_validation/views/mail_activity.xml @@ -106,8 +106,6 @@ - - @@ -167,14 +165,12 @@