diff --git a/__init__.py b/__init__.py index 40a96af..cde864b 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1,3 @@ # -*- coding: utf-8 -*- + +from . import models diff --git a/__manifest__.py b/__manifest__.py index bb74b87..3ca96e2 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -20,7 +20,9 @@ Use Case: Ideal for retail environments running promotions such as 'Redeem X points for 1 Free Item'. By default, if a user has 3x points, Odoo allows them to claim 3 free items at once. This module strictly restricts the reward so only 1 free item can be claimed per transaction, exactly matching the configuration in the backend. """, 'depends': ['point_of_sale', 'pos_loyalty'], - 'data': [], + 'data': [ + 'views/loyalty_program_views.xml', + ], 'assets': { 'point_of_sale._assets_pos': [ 'pos_loyalty_reward_qty_limit/static/src/app/models/pos_order.js', diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..d63ba4c --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import loyalty_program diff --git a/models/loyalty_program.py b/models/loyalty_program.py new file mode 100644 index 0000000..ffa5e8b --- /dev/null +++ b/models/loyalty_program.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields + +class LoyaltyProgram(models.Model): + _inherit = 'loyalty.program' + + reward_claim_limit_type = fields.Selection([ + ('limited', 'Limited to 1 Time Claim'), + ('multiple', 'Multiple Times Claim') + ], string="Reward Claim Limit Type", default='limited', required=True, + help="If 'Limited to 1 Time Claim', the reward is capped at its defined quantity. If 'Multiple Times Claim', customers can claim the reward as many times as their points allow.") + + def _load_pos_data_fields(self, config): + params = super()._load_pos_data_fields(config) + params.append('reward_claim_limit_type') + return params diff --git a/static/src/app/models/pos_order.js b/static/src/app/models/pos_order.js index d4c6e8c..a67b857 100644 --- a/static/src/app/models/pos_order.js +++ b/static/src/app/models/pos_order.js @@ -7,6 +7,10 @@ patch(PosOrder.prototype, { _computeUnclaimedFreeProductQty(reward, coupon_id, product, remainingPoints) { const unclaimed = super._computeUnclaimedFreeProductQty(...arguments); + if (reward.program_id && reward.program_id.reward_claim_limit_type === 'multiple') { + return unclaimed; + } + // Find how many of this reward have already been claimed in the order let claimed = 0; for (const line of this.getOrderlines()) { @@ -26,6 +30,10 @@ patch(PosOrder.prototype, { _computePotentialFreeProductQty(reward, product, remainingPoints) { const potential = super._computePotentialFreeProductQty(...arguments); + if (reward.program_id && reward.program_id.reward_claim_limit_type === 'multiple') { + return potential; + } + // Apply the same cap here for display purposes let claimed = 0; for (const line of this.getOrderlines()) { diff --git a/views/loyalty_program_views.xml b/views/loyalty_program_views.xml new file mode 100644 index 0000000..009e27f --- /dev/null +++ b/views/loyalty_program_views.xml @@ -0,0 +1,13 @@ + + + + loyalty.program.view.form.inherit.reward.limit + loyalty.program + + + + + + + +