theme.py
6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: utf-8 -*-
import base64
from odoo import models, fields, api
from odoo.modules import get_module_resource
class Theme(models.TransientModel):
_name = "theme.data"
def _get_current_theme(self):
return self.env['theme.data.stored'].sudo().search([], limit=1).name
name = fields.Selection([
('default', 'Default'),
('two', 'Green'),
('three', 'Black'),
], 'Theme', required=True, default=_get_current_theme)
@api.onchange('name')
def onchange_name(self):
theme = self.sudo().env.ref('idg_theme.theme_data_stored')
if theme:
theme.name = self.name
else:
theme.create({
'name': self.name
})
def action_apply(self):
name = self.env['theme.data.stored'].sudo().search([], limit=1).name
if name == 'two':
link = '<link rel="stylesheet" href="/idg_theme/static/src/scss/theme_two.scss"/>'
self.icon_change_theme_green()
elif name == 'three':
link = '<link rel="stylesheet" href="/idg_theme/static/src/scss/theme_three.scss"/>'
self.icon_change_theme_default()
else:
link = '<link rel="stylesheet" href="/idg_theme/static/src/scss/theme_accent.scss"/>'
self.icon_change_theme_default()
theme = self.sudo().env.ref('idg_theme.idg_theme_assets')
login = self.sudo().env.ref(
'idg_theme.idg_theme_assets_frontend')
theme.arch_base = '''
<data name="SDN Theme Assets" inherit_id="web.assets_backend">
<xpath expr=".">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600&display=swap" rel="stylesheet"/>
%s
<link rel="stylesheet" href="/idg_theme/static/src/scss/datetimepicker.scss"/>
<link rel="stylesheet" href="/idg_theme/static/src/scss/theme.scss"/>
<link rel="stylesheet" href="/idg_theme/static/src/scss/sidebar.scss"/>
<script type="application/javascript" src="/idg_theme/static/src/js/chrome/sidebar.js"/>
<script type="application/javascript" src="/idg_theme/static/src/js/chrome/sidebar_menu.js"/>
<script type="application/javascript" src="/idg_theme/static/src/js/systray.js"/>
<script type="application/javascript" src="/idg_theme/static/src/js/load.js"/>
</xpath>
</data>
''' % link
login.arch_base = '''
<data name="idg_theme_assets_frontend" inherit_id="web.assets_backend">
<xpath expr=".">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600&display=swap" rel="stylesheet"/>
%s
<link rel="stylesheet" href="/idg_theme/static/src/scss/login.scss"/>
</xpath>
</data>
''' % link
return {
'type': 'ir.actions.client',
'tag': 'reload',
}
def icon_change_theme_default(self):
menu_item = self.env['ir.ui.menu'].sudo().search([('parent_id', '=', False)])
for menu in menu_item:
if menu.name == 'PDL Kab/Kota':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img', 'icons',
'idg_pdl.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
if menu.name == 'BPHTB':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img', 'icons',
'idg_bphtb.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
if menu.name == 'IDG Account':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img', 'icons',
'idg_account.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
if menu.name == 'ID Dashboard':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img', 'icons',
'idg_board.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
def icon_change_theme_green(self):
menu_item = self.env['ir.ui.menu'].sudo().search([('parent_id', '=', False)])
for menu in menu_item:
if menu.name == 'PDL Kab/Kota':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img',
'icons_light',
'idg_pdl.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
if menu.name == 'BPHTB':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img',
'icons_light',
'idg_bphtb.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
if menu.name == 'IDG Account':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img',
'icons_light',
'idg_account.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
if menu.name == 'ID Dashboard':
img_path = get_module_resource(
'idg_theme', 'static', 'src', 'img',
'icons_light',
'idg_board.png')
menu.write({'web_icon_data': base64.b64encode(
open(img_path, "rb").read())})
class ThemeStored(models.Model):
_name = "theme.data.stored"
name = fields.Selection([
('default', 'Default'),
('two', 'Green'),
('three', 'Black'),
], 'Theme', default='default')