38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
from odoo import models, fields, api
|
|
from datetime import timedelta
|
|
|
|
|
|
class SubscriptionPlan(models.Model):
|
|
_name = 'subscription.plan'
|
|
_description = 'Subscription Plan'
|
|
_order = 'price, duration_months'
|
|
|
|
name = fields.Char(string='Plan Name', required=True)
|
|
duration_months = fields.Integer(string='Duration (Months)', required=True)
|
|
price = fields.Float(string='Price', required=True)
|
|
currency_id = fields.Many2one('res.currency', string='Currency',
|
|
default=lambda self: self.env.company.currency_id)
|
|
description = fields.Text(string='Description')
|
|
features = fields.Text(string='Features')
|
|
is_trial = fields.Boolean(string='Is Trial Plan', default=False)
|
|
trial_days = fields.Integer(string='Trial Days', default=15)
|
|
max_apps = fields.Integer(string='Maximum Apps', default=10)
|
|
max_users = fields.Integer(string='Maximum Users', default=1)
|
|
max_storage_mb = fields.Integer(string='Max Storage (MB)', default=100)
|
|
active = fields.Boolean(string='Active', default=True)
|
|
|
|
plan_code = fields.Selection([
|
|
('3_months', '3 Months'),
|
|
('6_months', '6 Months'),
|
|
('1_year', '1 Year'),
|
|
('trial', 'Free Trial'),
|
|
], string='Plan Code', required=True)
|
|
|
|
@api.model
|
|
def get_trial_plan(self):
|
|
return self.search([('is_trial', '=', True), ('active', '=', True)], limit=1)
|
|
|
|
@api.model
|
|
def get_paid_plans(self):
|
|
return self.search([('is_trial', '=', False), ('active', '=', True)],
|
|
order='duration_months ASC') |