fix: include archived loyalty cards in search and reactivate them during level transitions
This commit is contained in:
parent
67bdf004e4
commit
941ed35e42
@ -71,15 +71,16 @@ class PosOrder(models.Model):
|
||||
other_programs = [pid for pid in all_multi_level_program_ids if pid != matched_program.id]
|
||||
|
||||
if other_programs:
|
||||
# Find ALL active old cards (with or without points) to clean them up
|
||||
all_old_cards = self.env['loyalty.card'].sudo().search([
|
||||
# Find ALL old cards (active or archived, with or without points) to clean them up.
|
||||
# We use with_context(active_test=False) to include archived cards.
|
||||
all_old_cards = self.env['loyalty.card'].sudo().with_context(active_test=False).search([
|
||||
('partner_id', '=', partner.id),
|
||||
('program_id', 'in', other_programs),
|
||||
('active', '=', True),
|
||||
])
|
||||
|
||||
if all_old_cards:
|
||||
new_card = self.env['loyalty.card'].sudo().search([
|
||||
# Find the target level card (even if archived) to avoid duplicates.
|
||||
new_card = self.env['loyalty.card'].sudo().with_context(active_test=False).search([
|
||||
('partner_id', '=', partner.id),
|
||||
('program_id', '=', matched_program.id),
|
||||
], limit=1)
|
||||
@ -90,6 +91,9 @@ class PosOrder(models.Model):
|
||||
'program_id': matched_program.id,
|
||||
'points': 0,
|
||||
})
|
||||
elif not new_card.active:
|
||||
# Reactivate the card if it was archived
|
||||
new_card.active = True
|
||||
|
||||
# Transfer non-zero points to the new card, then archive ALL old cards
|
||||
for old_card in all_old_cards:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user