refactor: update loyalty program write logic to ignore non-trigger fields and consolidate bypass conditions
This commit is contained in:
parent
d6d9fba49a
commit
1feec3f725
@ -46,14 +46,22 @@ class LoyaltyProgram(models.Model):
|
||||
program.message_post(body=_("Marketing program reset to Draft."))
|
||||
|
||||
def write(self, vals):
|
||||
# If we are only modifying state, skip the write reset checks
|
||||
if len(vals) == 1 and 'state' in vals:
|
||||
# Fields that do not require re-approval when modified (e.g., sequence reordering, archiving, or chatter/activity updates)
|
||||
non_trigger_fields = {
|
||||
'sequence', 'state', 'active', 'write_uid', 'write_date',
|
||||
'message_follower_ids', 'message_ids', 'message_main_attachment_id',
|
||||
'activity_ids', 'activity_state', 'activity_user_id', 'activity_type_id',
|
||||
'activity_date_deadline', 'activity_summary'
|
||||
}
|
||||
|
||||
# If all modified fields are in the non-trigger list, skip reset logic
|
||||
if all(k in non_trigger_fields for k in vals):
|
||||
return super().write(vals)
|
||||
|
||||
# Skip reset logic if Odoo is installing/upgrading modules or explicitly bypassed
|
||||
if (self.env.context.get('install_mode')
|
||||
or self.env.context.get('module')
|
||||
or self.env.context.get('no_marketing_reset')):
|
||||
or self.env.context.get('no_marketing_reset')
|
||||
or self.env.context.get('module')):
|
||||
return super().write(vals)
|
||||
|
||||
# For modifications, check if they are in pending/approved state
|
||||
|
||||
Loading…
Reference in New Issue
Block a user