mirror of https://github.com/OCA/web.git
[FIX] web_company_color: changed scss sanitized values
parent
a197b7cfb6
commit
a69be8f1df
|
@ -55,11 +55,11 @@ class ResCompany(models.Model):
|
|||
sparse='company_colors')
|
||||
scss_modif_timestamp = fields.Char('SCSS Modif. Timestamp')
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
record = super().create(values)
|
||||
record.scss_create_or_update_attachment()
|
||||
return record
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super().create(vals_list)
|
||||
records.scss_create_or_update_attachment()
|
||||
return records
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
|
@ -106,12 +106,17 @@ class ResCompany(models.Model):
|
|||
@api.multi
|
||||
def _scss_get_sanitized_values(self):
|
||||
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({
|
||||
'color_navbar_bg': values['color_navbar_bg'] or '$o-brand-odoo',
|
||||
'color_navbar_bg_hover': values['color_navbar_bg_hover']
|
||||
or '$o-navbar-inverse-link-hover-bg',
|
||||
'color_navbar_text': values['color_navbar_text'] or '#FFF',
|
||||
'color_navbar_bg': (values.get('color_navbar_bg')
|
||||
or '$o-brand-odoo'),
|
||||
'color_navbar_bg_hover': (
|
||||
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
|
||||
|
||||
|
@ -139,7 +144,10 @@ class ResCompany(models.Model):
|
|||
@api.multi
|
||||
def scss_create_or_update_attachment(self):
|
||||
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:
|
||||
datas = base64.b64encode(
|
||||
record._scss_generate_content().encode('utf-8'))
|
||||
|
|
|
@ -15,12 +15,6 @@ class TestResCompany(common.TransactionCase):
|
|||
num_companies = self.env['res.company'].search_count([])
|
||||
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):
|
||||
company_id = self.env['res.company'].create({
|
||||
'name': 'Company Test'
|
||||
|
@ -33,3 +27,33 @@ class TestResCompany(common.TransactionCase):
|
|||
"Invalid Navbar Background Color")
|
||||
company_id.sudo().unlink()
|
||||
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