refactor: update loyalty program write logic to ignore non-trigger fields and consolidate bypass conditions

This commit is contained in:
Suherdy Yacob 2026-06-12 11:23:10 +07:00
parent d6d9fba49a
commit 1feec3f725

View File

@ -46,14 +46,22 @@ class LoyaltyProgram(models.Model):
program.message_post(body=_("Marketing program reset to Draft.")) program.message_post(body=_("Marketing program reset to Draft."))
def write(self, vals): def write(self, vals):
# If we are only modifying state, skip the write reset checks # Fields that do not require re-approval when modified (e.g., sequence reordering, archiving, or chatter/activity updates)
if len(vals) == 1 and 'state' in vals: 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) return super().write(vals)
# Skip reset logic if Odoo is installing/upgrading modules or explicitly bypassed # Skip reset logic if Odoo is installing/upgrading modules or explicitly bypassed
if (self.env.context.get('install_mode') 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) return super().write(vals)
# For modifications, check if they are in pending/approved state # For modifications, check if they are in pending/approved state