fix: only clear membership level when archiving loyalty card if no other active cards exist for the program
This commit is contained in:
parent
73c35159fb
commit
96d86809a6
@ -21,5 +21,13 @@ class LoyaltyCard(models.Model):
|
|||||||
elif 'active' in vals and not vals['active']:
|
elif 'active' in vals and not vals['active']:
|
||||||
# Card was archived, if it matched the partner's current membership level, clear it or let auto-leveling recalculate
|
# Card was archived, if it matched the partner's current membership level, clear it or let auto-leveling recalculate
|
||||||
if card.partner_id and card.partner_id.membership_level_id == card.program_id:
|
if card.partner_id and card.partner_id.membership_level_id == card.program_id:
|
||||||
card.partner_id.sudo().write({'membership_level_id': False})
|
# Only clear if there are no other active cards for this program
|
||||||
|
other_active = self.env['loyalty.card'].sudo().search_count([
|
||||||
|
('partner_id', '=', card.partner_id.id),
|
||||||
|
('program_id', '=', card.program_id.id),
|
||||||
|
('active', '=', True),
|
||||||
|
('id', '!=', card.id),
|
||||||
|
])
|
||||||
|
if not other_active:
|
||||||
|
card.partner_id.sudo().write({'membership_level_id': False})
|
||||||
return res
|
return res
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user