feat: add app branding fields and update configuration management to use server actions
This commit is contained in:
parent
2e189dbe6a
commit
01ea159235
@ -131,15 +131,27 @@ class AppNotificationController(http.Controller):
|
||||
@http.route('/api/loyalty/app_config', type='jsonrpc', auth='public', methods=['POST'], csrf=False)
|
||||
def fetch_app_config(self, **kw):
|
||||
"""
|
||||
Public endpoint to fetch app configuration (About Us URL, Contact Us URL).
|
||||
Public endpoint to fetch app configuration (About Us URL, Contact Us URL, Branding & Theme).
|
||||
"""
|
||||
config = request.env['mapan.app.config'].sudo().search([], limit=1)
|
||||
if not config:
|
||||
config = request.env['mapan.app.config'].sudo().create({'name': 'App Configuration'})
|
||||
config = request.env['mapan.app.config'].sudo().create({
|
||||
'name': 'App Configuration',
|
||||
'primary_color': '#C62828',
|
||||
'secondary_color': '#FF8F00'
|
||||
})
|
||||
|
||||
brand_logo = config.brand_logo
|
||||
if brand_logo and isinstance(brand_logo, bytes):
|
||||
brand_logo = brand_logo.decode('utf-8')
|
||||
|
||||
return {
|
||||
'status': 'success',
|
||||
'about_us_url': config.about_us_url or '',
|
||||
'contact_us_url': config.contact_us_url or '',
|
||||
'brand_logo': brand_logo or '',
|
||||
'primary_color': config.primary_color or '#C62828',
|
||||
'secondary_color': config.secondary_color or '#FF8F00',
|
||||
}
|
||||
|
||||
@http.route('/api/loyalty/order_history', type='jsonrpc', auth='user', methods=['POST'], csrf=False)
|
||||
|
||||
@ -18,10 +18,41 @@ class AppCmsConfig(models.Model):
|
||||
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'
|
||||
)
|
||||
|
||||
@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'})
|
||||
return config
|
||||
config = self.create({
|
||||
'name': 'App Configuration',
|
||||
'primary_color': '#C62828',
|
||||
'secondary_color': '#FF8F00'
|
||||
})
|
||||
@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',
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,15 @@
|
||||
<div class="oe_title">
|
||||
<h1>Mobile App Settings</h1>
|
||||
</div>
|
||||
<group>
|
||||
<group string="Dynamic Branding & Theme">
|
||||
<field name="brand_logo" widget="image" options="{'size': [0, 90]}"
|
||||
help="Upload the brand logo to display in the app toolbar."/>
|
||||
<field name="primary_color" placeholder="#C62828"
|
||||
help="Primary theme color in Hex (e.g. #C62828)"/>
|
||||
<field name="secondary_color" placeholder="#FF8F00"
|
||||
help="Secondary theme color in Hex (e.g. #FF8F00)"/>
|
||||
</group>
|
||||
<group string="Account Menu Links">
|
||||
<field name="about_us_url"
|
||||
placeholder="https://yourwebsite.com/about"
|
||||
@ -18,19 +27,20 @@
|
||||
placeholder="https://yourwebsite.com/contact"
|
||||
help="URL opened when the user taps Contact Us in the app."/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Singleton action: always opens the single config record -->
|
||||
<record id="action_mapan_app_config" model="ir.actions.act_window">
|
||||
<!-- Singleton server action: calls python method to load config record -->
|
||||
<record id="action_mapan_app_config" model="ir.actions.server">
|
||||
<field name="name">App Settings</field>
|
||||
<field name="res_model">mapan.app.config</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">inline</field>
|
||||
<!-- Open existing record if it exists -->
|
||||
<field name="domain">[]</field>
|
||||
<field name="model_id" ref="model_mapan_app_config"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
action = model.action_open_config()
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_mapan_app_config"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user