You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.6 KiB

9 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Therp BV (<http://therp.nl>)
  3. # © 2016 ACSONE SA/NV (<http://acsone.eu>)
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from openerp import api, fields, models
  6. class MisReportKpiStyle(models.Model):
  7. _name = 'mis.report.style'
  8. @api.depends('indent_level')
  9. def check_positive_val(self):
  10. return self.indent_level > 0
  11. _font_style_selection = [
  12. ('normal', 'Normal'),
  13. ('italic', 'Italic'),
  14. ]
  15. _font_weight_selection = [
  16. ('nornal', 'Normal'),
  17. ('bold', 'Bold'),
  18. ]
  19. _font_size_selection = [
  20. ('medium', ''),
  21. ('xx-small', 'xx-small'),
  22. ('x-small', 'x-small'),
  23. ('small', 'small'),
  24. ('large', 'large'),
  25. ('x-large', 'x-large'),
  26. ('xx-large', 'xx-large'),
  27. ]
  28. _font_size_to_size = {
  29. 'medium': 11,
  30. 'xx-small': 5,
  31. 'x-small': 7,
  32. 'small': 9,
  33. 'large': 13,
  34. 'x-large': 15,
  35. 'xx-large': 17
  36. }
  37. name = fields.Char(string='Style name', required=True)
  38. color = fields.Char(
  39. string='Text color',
  40. help='Text color in valid RGB code (from #000000 to #FFFFFF)',
  41. )
  42. background_color = fields.Char(
  43. help='Background color in valid RGB code (from #000000 to #FFFFFF)'
  44. )
  45. font_style = fields.Selection(
  46. selection=_font_style_selection,
  47. )
  48. font_weight = fields.Selection(
  49. selection=_font_weight_selection
  50. )
  51. font_size = fields.Selection(
  52. selection=_font_size_selection
  53. )
  54. indent_level = fields.Integer()
  55. @api.multi
  56. def font_size_to_size(self):
  57. self.ensure_one()
  58. return self._font_size_to_size.get(self.font_size, 11)
  59. @api.multi
  60. def to_xlsx_format_properties(self):
  61. self.ensure_one()
  62. props = {
  63. 'italic': self.font_style == 'italic',
  64. 'bold': self.font_weight == 'bold',
  65. 'font_color': self.color,
  66. 'bg_color': self.background_color,
  67. 'indent': self.indent_level,
  68. 'size': self.font_size_to_size()
  69. }
  70. return props
  71. @api.multi
  72. def to_css_style(self):
  73. self.ensure_one()
  74. css_attributes = [
  75. ('font-style', self.font_style),
  76. ('font-weight', self.font_weight),
  77. ('font-size', self.font_size),
  78. ('color', self.color),
  79. ('background-color', self.background_color),
  80. ('indent-level', self.indent_level)
  81. ]
  82. css_list = [
  83. '%s:%s' % x for x in css_attributes if x[1]
  84. ]
  85. return ';'.join(css_item for css_item in css_list)