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.

101 lines
2.6 KiB

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