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.

95 lines
3.9 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # mis_builder module for Odoo, Management Information System Builder
  5. # Copyright (C) 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
  6. #
  7. # This file is a part of mis_builder
  8. #
  9. # mis_builder is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License v3 or later
  11. # as published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # mis_builder is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License v3 or later for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # v3 or later along with this program.
  21. # If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. from openerp.addons.report_xlsx.report.report_xlsx import ReportXlsx
  25. from openerp.report import report_sxw
  26. import logging
  27. _logger = logging.getLogger(__name__)
  28. class MisBuilderXslx(ReportXlsx):
  29. def __init__(self, name, table, rml=False, parser=False, header=True,
  30. store=False):
  31. super(MisBuilderXslx, self).__init__(
  32. name, table, rml, parser, header, store)
  33. def generate_xlsx_report(self, workbook, data, objects):
  34. report_name = objects[0].name
  35. sheet = workbook.add_worksheet(report_name[:31])
  36. row_pos = 0
  37. col_pos = 0
  38. sheet.set_column(col_pos, col_pos, 30)
  39. bold = workbook.add_format({'bold': True})
  40. header_format = workbook.add_format({'bold': True,
  41. 'align': 'center',
  42. 'border': True,
  43. 'bg_color': '#FFFFCC'})
  44. kpi_name_format = workbook.add_format({'bold': True,
  45. 'border': True,
  46. 'bg_color': '#FFFFCC'})
  47. sheet.write(row_pos, 0, report_name, bold)
  48. row_pos += 1
  49. col_pos += 1
  50. # get the computed result of the report
  51. data = objects.compute()
  52. # Column headers
  53. for col in data['header'][0]['cols']:
  54. sheet.set_column(col_pos, col_pos, 30)
  55. sheet.write(row_pos, col_pos, col['name'], header_format)
  56. sheet.write(row_pos+1, col_pos, col['date'], header_format)
  57. col_pos += 1
  58. row_pos += 2
  59. for line in data['content']:
  60. col = 0
  61. sheet.write(row_pos, col, line['kpi_name'], kpi_name_format)
  62. for value in line['cols']:
  63. col += 1
  64. num_format_str = '#'
  65. if value.get('dp'):
  66. num_format_str += '.'
  67. num_format_str += '0' * int(value['dp'])
  68. if value.get('prefix'):
  69. num_format_str = '"%s"' % value['prefix'] + num_format_str
  70. if value.get('suffix'):
  71. num_format_str = num_format_str + ' "%s"' % value['suffix']
  72. kpi_format = workbook.add_format({'num_format': num_format_str,
  73. 'border': 1,
  74. 'align': 'right'})
  75. if value.get('val'):
  76. val = value['val']
  77. if value.get('is_percentage'):
  78. val = val / 0.01
  79. sheet.write(row_pos, col, val, kpi_format)
  80. else:
  81. sheet.write(row_pos, col, value['val_r'], kpi_format)
  82. row_pos += 1
  83. MisBuilderXslx('report.mis.report.instance.xlsx',
  84. 'mis.report.instance', parser=report_sxw.rml_parse)