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

8 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.kpi.style'
  8. # TODO use WEB WIdget color picker
  9. name = fields.Char(string='style name', required=True)
  10. @api.depends('indent_level')
  11. def check_positive_val(self):
  12. return self.indent_level > 0
  13. _font_style_selection = [
  14. ('normal', 'Normal'),
  15. ('italic', 'Italic'),
  16. ]
  17. _font_weight_selection = [
  18. ('nornal', 'Normal'),
  19. ('bold', 'Bold'),
  20. ]
  21. _font_size_selection = [
  22. ('medium', ''),
  23. ('xx-small', 'xx-small'),
  24. ('x-small', 'x-small'),
  25. ('small', 'small'),
  26. ('large', 'large'),
  27. ('x-large', 'x-large'),
  28. ('xx-large', 'xx-large'),
  29. ]
  30. _font_size_to_size = {
  31. 'medium': 11,
  32. 'xx-small': 5,
  33. 'x-small': 7,
  34. 'small': 9,
  35. 'large': 13,
  36. 'x-large': 15,
  37. 'xx-large': 17
  38. }
  39. color = fields.Char(
  40. help='Line color in valid RGB code (from #000000 to #FFFFFF)',
  41. )
  42. background_color = fields.Char(
  43. help='Line 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)