mapan_loyalty_push/models/app_cms_config.py

78 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, fields, api
class AppCmsConfig(models.Model):
"""Singleton model for Mobile App global configuration."""
_name = 'mapan.app.config'
_description = 'Mobile App Configuration'
name = fields.Char(default='App Configuration', readonly=True)
about_us_url = fields.Char(
string='About Us URL',
help='URL to open when user taps "About Us" in the app account menu.'
)
contact_us_url = fields.Char(
string='Contact Us URL',
help='URL to open when user taps "Contact Us" in the app account menu.'
)
brand_logo = fields.Image(
string='Brand Logo',
help='Logo to be displayed in the app header/dashboard.'
)
primary_color = fields.Char(
string='Primary Color (Hex)',
default='#C62828',
help='Hex color code for primary theme color, e.g. #C62828'
)
secondary_color = fields.Char(
string='Secondary Color (Hex)',
default='#FF8F00',
help='Hex color code for secondary theme color, e.g. #FF8F00'
)
tertiary_color = fields.Char(
string='Tertiary Color (Hex)',
default='#4A7C59',
help='Hex color code for tertiary theme color (e.g. accent for tags/chips), e.g. #4A7C59'
)
background_color = fields.Char(
string='Background Color (Hex)',
default='#FAF6EE',
help='Hex color code for background color, e.g. #FAF6EE'
)
background_gradient_color = fields.Char(
string='Background Gradient Color (Hex)',
default='#F3EAD3',
help='Hex color code for bottom of background gradient, e.g. #F3EAD3'
)
@api.model
def get_config(self):
"""Always return the single config record, creating it if it does not exist."""
config = self.search([], limit=1)
if not config:
config = self.create({
'name': 'App Configuration',
'primary_color': '#C62828',
'secondary_color': '#FF8F00',
'tertiary_color': '#4A7C59',
'background_color': '#FAF6EE',
'background_gradient_color': '#F3EAD3',
})
return config
@api.model
def action_open_config(self):
"""Action to open the singleton configuration record."""
config = self.get_config()
return {
'name': 'App Settings',
'type': 'ir.actions.act_window',
'res_model': 'mapan.app.config',
'view_mode': 'form',
'res_id': config.id,
'target': 'current',
}