feat: add app branding fields and update configuration management to use server actions

This commit is contained in:
Suherdy Yacob 2026-06-14 09:18:29 +07:00
parent 2e189dbe6a
commit 01ea159235
3 changed files with 71 additions and 18 deletions

View File

@ -131,15 +131,27 @@ class AppNotificationController(http.Controller):
@http.route('/api/loyalty/app_config', type='jsonrpc', auth='public', methods=['POST'], csrf=False) @http.route('/api/loyalty/app_config', type='jsonrpc', auth='public', methods=['POST'], csrf=False)
def fetch_app_config(self, **kw): 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) config = request.env['mapan.app.config'].sudo().search([], limit=1)
if not config: 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 { return {
'status': 'success', 'status': 'success',
'about_us_url': config.about_us_url or '', 'about_us_url': config.about_us_url or '',
'contact_us_url': config.contact_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) @http.route('/api/loyalty/order_history', type='jsonrpc', auth='user', methods=['POST'], csrf=False)

View File

@ -18,10 +18,41 @@ class AppCmsConfig(models.Model):
help='URL to open when user taps "Contact Us" in the app account menu.' 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 @api.model
def get_config(self): def get_config(self):
"""Always return the single config record, creating it if it does not exist.""" """Always return the single config record, creating it if it does not exist."""
config = self.search([], limit=1) config = self.search([], limit=1)
if not config: if not config:
config = self.create({'name': 'App Configuration'}) config = self.create({
return config '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',
}

View File

@ -10,6 +10,15 @@
<div class="oe_title"> <div class="oe_title">
<h1>Mobile App Settings</h1> <h1>Mobile App Settings</h1>
</div> </div>
<group>
<group string="Dynamic Branding &amp; 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"> <group string="Account Menu Links">
<field name="about_us_url" <field name="about_us_url"
placeholder="https://yourwebsite.com/about" placeholder="https://yourwebsite.com/about"
@ -18,19 +27,20 @@
placeholder="https://yourwebsite.com/contact" placeholder="https://yourwebsite.com/contact"
help="URL opened when the user taps Contact Us in the app."/> help="URL opened when the user taps Contact Us in the app."/>
</group> </group>
</group>
</sheet> </sheet>
</form> </form>
</field> </field>
</record> </record>
<!-- Singleton action: always opens the single config record --> <!-- Singleton server action: calls python method to load config record -->
<record id="action_mapan_app_config" model="ir.actions.act_window"> <record id="action_mapan_app_config" model="ir.actions.server">
<field name="name">App Settings</field> <field name="name">App Settings</field>
<field name="res_model">mapan.app.config</field> <field name="model_id" ref="model_mapan_app_config"/>
<field name="view_mode">form</field> <field name="state">code</field>
<field name="target">inline</field> <field name="code">
<!-- Open existing record if it exists --> action = model.action_open_config()
<field name="domain">[]</field> </field>
</record> </record>
<menuitem id="menu_mapan_app_config" <menuitem id="menu_mapan_app_config"