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.

92 lines
3.7 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. import logging
  26. _logger = logging.getLogger(__name__)
  27. class MisBuilderXslx(ReportXlsx):
  28. def __init__(self, name, table, rml=False, parser=False, header=True,
  29. store=False):
  30. super(MisBuilderXslx, self).__init__(
  31. name, table, rml, parser, header, store)
  32. def generate_xlsx_report(self, workbook, data, objects):
  33. report_name = objects[0].name
  34. sheet = workbook.add_worksheet(report_name[:31])
  35. row_pos = 0
  36. col_pos = 0
  37. sheet.set_column(col_pos, col_pos, 30)
  38. bold = workbook.add_format({'bold': True})
  39. header_format = workbook.add_format({'bold': True,
  40. 'align': 'center',
  41. 'border': True,
  42. 'bg_color': '#FFFFCC'})
  43. kpi_name_format = workbook.add_format({'bold': True,
  44. 'border': True,
  45. 'bg_color': '#FFFFCC'})
  46. sheet.write(row_pos, 0, report_name, bold)
  47. row_pos += 1
  48. col_pos += 1
  49. # get the computed result of the report
  50. data = objects.compute()
  51. # Column headers
  52. for col in data['header'][0]['cols']:
  53. sheet.set_column(col_pos, col_pos, 30)
  54. sheet.write(row_pos, col_pos, col['name'], header_format)
  55. sheet.write(row_pos+1, col_pos, col['date'], header_format)
  56. col_pos += 1
  57. row_pos += 2
  58. for line in data['content']:
  59. col = 0
  60. sheet.write(row_pos, col, line['kpi_name'], kpi_name_format)
  61. for value in line['cols']:
  62. col += 1
  63. num_format_str = '#'
  64. if value.get('dp'):
  65. num_format_str += '.'
  66. num_format_str += '0' * int(value['dp'])
  67. if value.get('suffix'):
  68. num_format_str = num_format_str + ' "%s"' % value['suffix']
  69. kpi_format = workbook.add_format({'num_format': num_format_str,
  70. 'border': 1,
  71. 'align': 'right'})
  72. if value.get('val'):
  73. val = value['val']
  74. if value.get('is_percentage'):
  75. val = val / 0.01
  76. sheet.write(row_pos, col, val, kpi_format)
  77. else:
  78. sheet.write(row_pos, col, value['val_r'], kpi_format)
  79. row_pos += 1
  80. MisBuilderXslx('report.mis.report.instance.xlsx',
  81. 'mis.report.instance')