Skip to content

Commit

Permalink
[MOD] activity unlink issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 7, 2025
1 parent 3c9275a commit 5cffea8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 41 deletions.
2 changes: 1 addition & 1 deletion activity_validation/data/mail_activity_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<field name="res_model">product.product</field>
<field name="sequence">200</field>
<field name="change_activity_type">request</field>
<field name="keep_done">True</field>
</record>

</data>
</odoo>
18 changes: 4 additions & 14 deletions activity_validation/models/mail_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down
49 changes: 30 additions & 19 deletions activity_validation/models/mail_activity_shedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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']:
Expand Down
8 changes: 2 additions & 6 deletions activity_validation/views/mail_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@
</list>
</field>
</xpath>


</field>
</record>

Expand Down Expand Up @@ -167,14 +165,12 @@
<label for="children_ids"
invisible="change_activity_type != 'request'"
readonly="plm_state in ['eco', 'done']"/>
<field name="children_ids"
nolabel="1"
invisible="change_activity_type != 'request'"
readonly="plm_state=='eco'">
<field name="children_ids" nolabel="1" invisible="change_activity_type != 'request'" readonly="plm_state=='eco'">
<list editable='bottom'>
<field name="name"/>
<field name="user_id"/>
<field name="activity_user_id"/>
<field name="mail_children_activity_id" invisible="1" force_save="1"/>
<field name="plm_state" />
</list>
</field>
Expand Down
1 change: 0 additions & 1 deletion plm/data/data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
<field name="sequence">200</field>
<field name="change_activity_type">request</field>
</record>

</data>
</odoo>
1 change: 1 addition & 0 deletions plm/views/mail_activity_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<field name="res_model">product.product</field>
<field name="sequence">200</field>
<field name="change_activity_type">plm_activity</field>
<field name="keep_done">True</field>
</record>

</odoo>

0 comments on commit 5cffea8

Please sign in to comment.