I'd like my clients to buy a subscription that allow them to access a certain number of times to my weekly event, eg. they can access the weekly event only 2 times per month.
Any ideas on how to implement that?
For reference, here's what Deepseek imagine:
_____________________
Yes! You can configure your Odoo subscription product to issue a fixed number of time-limited coupons that expire with the subscription and cannot be rolled over. Here’s how to set it up:
Step 1: Create a Subscription Product
- Go to Sales > Products and create a new product.
- Enable Subscription:
- Set the billing cycle (e.g., monthly).
- Under Subscription Plan, define the duration (e.g., 30 days).
Step 2: Configure Coupons with Subscription-Based Expiry
Option A: Automated Coupons via Loyalty Program
- Create a Loyalty Program:
- Navigate to Sales > Loyalty > Programs.
- Select "Coupons" as the program type.
- Set "Generate coupons automatically" for subscriptions.
- Link Coupons to Subscription:
- Use a custom field on coupon.coupon to track the linked subscription:
python
Copysubscription_id = fields.Many2one('sale.subscription', string="Linked Subscription")
- Set coupon expiry date = subscription end date:
python
Copy# Scheduled action (runs daily) for sub in env['sale.subscription'].search([('state', '=', 'active')]): coupons = env['coupon.coupon'].search([('subscription_id', '=', sub.id)]) coupons.write({'expiry_date': sub.end_date}) # Coupons expire with subscription
- Use a custom field on coupon.coupon to track the linked subscription:
Option B: Generate Coupons on Subscription Renewal
- Create a Coupon Template:
- Go to Sales > Coupons and define:
- Validity: Dynamic (set expiry = subscription end date).
- Usage Limit: 1 per coupon (to prevent reuse).
- Go to Sales > Coupons and define:
- Automate Coupon Creation:
- Trigger coupon generation when subscriptions renew:
python
Copydef generate_subscription_coupons(self): for sub in self: for _ in range(sub.coupon_quantity): # E.g., 3 coupons/month env['coupon.coupon'].create({ 'program_id': sub.coupon_program_id.id, 'expiry_date': sub.end_date, 'subscription_id': sub.id })
- Trigger coupon generation when subscriptions renew:
Step 3: Enforce "Use-It-or-Lose-It" Rules
- Prevent Rollover:
- Add a constraint to delete unused coupons at subscription renewal:
python
Copy# Scheduled action (runs on subscription renewal) expired_subs = env['sale.subscription'].search([('end_date', '<', fields.Date.today())]) env['coupon.coupon'].search([('subscription_id', 'in', expired_subs.ids)]).unlink()
- Add a constraint to delete unused coupons at subscription renewal:
- Restrict Redemption:
- Use server actions to validate coupon usage:
python
Copydef validate_coupon(self): if self.subscription_id.state != 'active': raise UserError("Coupon expired with subscription!")
- Use server actions to validate coupon usage:
Step 4: Notify Customers
- Email Templates:
- Send coupons automatically via Sales > Configuration > Email Templates.
- Include warnings like:
"Your 3 monthly coupons expire on {subscription.end_date}. Unused coupons will not roll over."
Key Features
- Time-Limited Coupons: Expire with the subscription.
- No Accumulation: Unused coupons are destroyed on renewal.
- Flexible Redemption: Coupons can be exchanged for specific products (configure in Coupon Program).
Testing Scenario
- A client subscribes for 1 month and receives 3 coupons.
- They use 2 coupons; the 3rd expires when the subscription ends.
- On renewal, they get 3 new coupons (previous unused coupons are deleted).
Why This Works
- Tight Coupon-Subscription Binding: Coupons are tied to the subscription’s lifecycle.
- Automated Cleanup: Cron jobs enforce expiration rules.
- Transparency: Customers see coupon validity upfront.
For advanced workflows (e.g., prorated coupons), consider custom development. Otherwise, this setup works out-of-the-box with minor configurations.