从Odoo17开始,社区版原生支持以PWA方式运行;那么在一些项目中免不了要对其进行一些自定义;
修改点如下
在controllers下添加webmanifest.py
# -*- coding: utf-8 -*-
import base64
import json
import mimetypes
from odoo import http
from odoo.exceptions import AccessError
from odoo.http import request
from odoo.tools import ustr, file_open
from odoo.addons.web.controllers import webmanifest
class WebManifest(webmanifest.WebManifest):
@http.route('/web/manifest.webmanifest', type='http', auth='public', methods=['GET'])
def webmanifest(self):
""" Returns a WebManifest describing the metadata associated with a web application.
Using this metadata, user agents can provide developers with means to create user
experiences that are more comparable to that of a native application.
"""
web_app_name = request.env['ir.config_parameter'].sudo().get_param('web.web_app_name', 'Odoo')
manifest = {
# 'name': web_app_name,
'name': '大大大',
'scope': '/web',
'start_url': '/web',
'display': 'standalone',
# 'background_color': '#714B67',
# 'theme_color': '#714B67',
'background_color': 'red',
'theme_color': '#065279',
'prefer_related_applications': False,
}
icon_sizes = ['192x192', '512x512']
manifest['icons'] = [{
'src': '/web/static/img/odoo-icon-%s.png' % size,
'sizes': size,
'type': 'image/png',
} for size in icon_sizes]
manifest['shortcuts'] = self._get_shortcuts()
body = json.dumps(manifest, default=ustr)
response = request.make_response(body, [
('Content-Type', 'application/manifest+json'),
])
return response
因为odoo里面还定死了主题颜色,需要去掉它
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- 修改针对PWA定死的标题栏主题色 -->
<template id="webclient_bootstrap" name="Web Client" inherit_id="web.webclient_bootstrap">
<xpath expr="//meta[@name='theme-color']" position="attributes">
<attribute name="content">#065279</attribute>
</xpath>
</template>
</odoo>