feat: add dependency on pos_loyalty_multi_level and skip auto-leveling for manual memberships

This commit is contained in:
Suherdy Yacob 2026-06-02 11:51:59 +07:00
parent e286b6c6e6
commit 7631a3e93e
2 changed files with 7 additions and 4 deletions

View File

@ -17,7 +17,7 @@ Key Features:
4. **Intelligent Point Consolidation**: If a customer changes tiers, the module seamlessly sweeps loyalty points from any of their older tier cards and consolidates them into the new membership card. This happens synchronously to ensure all points are perfectly transferred without race conditions. 4. **Intelligent Point Consolidation**: If a customer changes tiers, the module seamlessly sweeps loyalty points from any of their older tier cards and consolidates them into the new membership card. This happens synchronously to ensure all points are perfectly transferred without race conditions.
5. **High Performance**: Evaluates membership instantly without recalculating the entire transaction history by leveraging the `total_spend` field. 5. **High Performance**: Evaluates membership instantly without recalculating the entire transaction history by leveraging the `total_spend` field.
""", """,
'depends': ['point_of_sale', 'pos_loyalty'], 'depends': ['point_of_sale', 'pos_loyalty', 'pos_loyalty_multi_level'],
'data': [ 'data': [
'views/res_partner_views.xml', 'views/res_partner_views.xml',
], ],

View File

@ -30,13 +30,16 @@ class PosOrder(models.Model):
"""Internal logic for membership determination, called by background worker.""" """Internal logic for membership determination, called by background worker."""
self.ensure_one() self.ensure_one()
partner = self.partner_id partner = self.partner_id
# If the customer has a manual membership level assigned, do not auto-change it.
if partner.membership_level_id and partner.membership_level_id.manual_membership:
return
# 1. Get total purchases from the new total_spend field # 1. Get total purchases from the new total_spend field
total_purchases = partner.total_spend total_purchases = partner.total_spend
# 2. Get multi-level programs # 2. Get multi-level programs that are not manual-only
loyalty_programs = self.env['loyalty.program'].sudo().search( loyalty_programs = self.env['loyalty.program'].sudo().search(
[('multi_level_membership', '=', True)], [('multi_level_membership', '=', True), ('manual_membership', '=', False)],
order='minimum_spend asc', order='minimum_spend asc',
) )