mirror of https://github.com/OCA/web.git
[FIX] web_company_color: changed scss sanitized values
parent
5a9a06efc2
commit
1c34f2e489
|
@ -55,11 +55,11 @@ class ResCompany(models.Model):
|
||||||
sparse='company_colors')
|
sparse='company_colors')
|
||||||
scss_modif_timestamp = fields.Char('SCSS Modif. Timestamp')
|
scss_modif_timestamp = fields.Char('SCSS Modif. Timestamp')
|
||||||
|
|
||||||
@api.model
|
@api.model_create_multi
|
||||||
def create(self, values):
|
def create(self, vals_list):
|
||||||
record = super().create(values)
|
records = super().create(vals_list)
|
||||||
record.scss_create_or_update_attachment()
|
records.scss_create_or_update_attachment()
|
||||||
return record
|
return records
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
|
@ -106,12 +106,17 @@ class ResCompany(models.Model):
|
||||||
@api.multi
|
@api.multi
|
||||||
def _scss_get_sanitized_values(self):
|
def _scss_get_sanitized_values(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
values = dict(self.company_colors)
|
# Clone company_color as dictionary to avoid ORM operations
|
||||||
|
# This allow extend company_colors and only sanitize selected fields
|
||||||
|
# or add custom values
|
||||||
|
values = dict(self.company_colors or {})
|
||||||
values.update({
|
values.update({
|
||||||
'color_navbar_bg': values['color_navbar_bg'] or '$o-brand-odoo',
|
'color_navbar_bg': (values.get('color_navbar_bg')
|
||||||
'color_navbar_bg_hover': values['color_navbar_bg_hover']
|
or '$o-brand-odoo'),
|
||||||
or '$o-navbar-inverse-link-hover-bg',
|
'color_navbar_bg_hover': (
|
||||||
'color_navbar_text': values['color_navbar_text'] or '#FFF',
|
values.get('color_navbar_bg_hover')
|
||||||
|
or '$o-navbar-inverse-link-hover-bg'),
|
||||||
|
'color_navbar_text': (values.get('color_navbar_text') or '#FFF'),
|
||||||
})
|
})
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
@ -139,7 +144,10 @@ class ResCompany(models.Model):
|
||||||
@api.multi
|
@api.multi
|
||||||
def scss_create_or_update_attachment(self):
|
def scss_create_or_update_attachment(self):
|
||||||
IrAttachmentObj = self.env['ir.attachment']
|
IrAttachmentObj = self.env['ir.attachment']
|
||||||
modif_timestamp = str(int(time.time())) # One second resolution
|
# The time window is 1 second
|
||||||
|
# This mean that all modifications realized in that second will
|
||||||
|
# have the same timestamp
|
||||||
|
modif_timestamp = str(int(time.time()))
|
||||||
for record in self:
|
for record in self:
|
||||||
datas = base64.b64encode(
|
datas = base64.b64encode(
|
||||||
record._scss_generate_content().encode('utf-8'))
|
record._scss_generate_content().encode('utf-8'))
|
||||||
|
|
|
@ -15,12 +15,6 @@ class TestResCompany(common.TransactionCase):
|
||||||
num_companies = self.env['res.company'].search_count([])
|
num_companies = self.env['res.company'].search_count([])
|
||||||
self.assertEqual(num_scss, num_companies, "Invalid scss attachments")
|
self.assertEqual(num_scss, num_companies, "Invalid scss attachments")
|
||||||
|
|
||||||
def test_change_logo(self):
|
|
||||||
company_id = self.env['res.company'].search([], limit=1)
|
|
||||||
company_id.sudo().write({'logo': self.IMG_GREEN})
|
|
||||||
self.assertEqual(company_id.color_navbar_bg, '#00ff00',
|
|
||||||
"Invalid Navbar Background Color")
|
|
||||||
|
|
||||||
def test_create_unlink_company(self):
|
def test_create_unlink_company(self):
|
||||||
company_id = self.env['res.company'].create({
|
company_id = self.env['res.company'].create({
|
||||||
'name': 'Company Test'
|
'name': 'Company Test'
|
||||||
|
@ -33,3 +27,33 @@ class TestResCompany(common.TransactionCase):
|
||||||
"Invalid Navbar Background Color")
|
"Invalid Navbar Background Color")
|
||||||
company_id.sudo().unlink()
|
company_id.sudo().unlink()
|
||||||
self.test_scss_attachment()
|
self.test_scss_attachment()
|
||||||
|
|
||||||
|
def test_change_logo(self):
|
||||||
|
company_id = self.env['res.company'].search([], limit=1)
|
||||||
|
company_id.sudo().write({'logo': self.IMG_GREEN})
|
||||||
|
self.assertEqual(company_id.color_navbar_bg, '#00ff00',
|
||||||
|
"Invalid Navbar Background Color")
|
||||||
|
|
||||||
|
def test_scss_sanitized_values(self):
|
||||||
|
company_id = self.env['res.company'].search([], limit=1)
|
||||||
|
company_id.sudo().write({'color_navbar_bg': False})
|
||||||
|
values = company_id.sudo()._scss_get_sanitized_values()
|
||||||
|
self.assertEqual(values['color_navbar_bg'], '$o-brand-odoo',
|
||||||
|
"Invalid Navbar Background Color")
|
||||||
|
company_id.sudo().write({'color_navbar_bg': '#DEAD00'})
|
||||||
|
values = company_id.sudo()._scss_get_sanitized_values()
|
||||||
|
self.assertEqual(values['color_navbar_bg'], '#DEAD00',
|
||||||
|
"Invalid Navbar Background Color")
|
||||||
|
|
||||||
|
def test_change_color(self):
|
||||||
|
company_id = self.env['res.company'].search([], limit=1)
|
||||||
|
company_id.sudo().write({'color_navbar_bg': '#DEAD00'})
|
||||||
|
self.assertEqual(company_id.color_navbar_bg, '#DEAD00',
|
||||||
|
"Invalid Navbar Background Color")
|
||||||
|
self.assertEqual(company_id.company_colors['color_navbar_bg'],
|
||||||
|
'#DEAD00', "Invalid Navbar Background Color")
|
||||||
|
company_id.sudo().write({'color_navbar_bg': False})
|
||||||
|
self.assertFalse(company_id.color_navbar_bg,
|
||||||
|
"Invalid Navbar Background Color")
|
||||||
|
self.assertNotIn('color_navbar_bg', company_id.company_colors,
|
||||||
|
"Invalid Navbar Background Color")
|
||||||
|
|
Loading…
Reference in New Issue