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.

79 lines
3.3 KiB

  1. # Copyright 2018 Eficent Business and IT Consulting Services S.L.
  2. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  3. import logging
  4. from odoo import models
  5. from odoo.tools.translate import _
  6. _logger = logging.getLogger(__name__)
  7. class ReportPartnerXlsx(models.AbstractModel):
  8. _name = 'report.privacy_partner_report.report_partner_xlsx'
  9. _inherit = 'report.report_xlsx.abstract'
  10. def _search_longest_row(self, tables):
  11. res = 0
  12. for table in tables:
  13. for model in tables[table]:
  14. if len(tables[table][model]) > 0:
  15. if len(tables[table][model][0]) > res:
  16. res = len(tables[table][model][0])
  17. return res
  18. def generate_xlsx_report(self, workbook, data, objects):
  19. partner = data['form'].get('partner_id', False)
  20. partner = self.env['res.partner'].sudo().browse(partner[0])
  21. workbook.set_properties({
  22. 'comments': 'Created with Python and XlsxWriter from Odoo'})
  23. sheet = workbook.add_worksheet(_('Partner Data'))
  24. sheet.set_landscape()
  25. sheet.fit_to_pages(1, 0)
  26. sheet.set_zoom(75)
  27. sheet.set_column(0, self._search_longest_row(data['tables']), 25)
  28. title_style = workbook.add_format(
  29. {'bold': True, 'bg_color': '#FFFFCC', 'border': 2})
  30. sheet.set_row(0, None, None, {'collapsed': 1})
  31. sheet.write_row(1, 0, ["Partner: " + partner.display_name],
  32. title_style)
  33. i = 3
  34. first_row = i+2
  35. for table in sorted(data['tables'].keys()):
  36. for model in sorted(data['tables'][table].keys()):
  37. rows = len(data['tables'][table][model])
  38. if rows:
  39. style = workbook.add_format()
  40. style.set_bold(True)
  41. style.set_border(2)
  42. sheet.write_row(i, 0, [model], style)
  43. i += 1
  44. j = 0
  45. for column in data['tables'][table][model][0]:
  46. style = workbook.add_format()
  47. style.set_bold(True)
  48. if j == 0:
  49. style.set_left(1)
  50. if j == len(data['tables'][table][model][0]) - 1:
  51. style.set_right(1)
  52. style.set_top(1)
  53. style.set_bottom(1)
  54. sheet.write_row(i, j, [column], style)
  55. j += 1
  56. for row in data['tables'][table][model]:
  57. i += 1
  58. j = 0
  59. for column in row:
  60. style = workbook.add_format()
  61. if j == 0:
  62. style.set_left(1)
  63. if j == len(row) - 1:
  64. style.set_right(1)
  65. if i == rows + first_row - 1:
  66. style.set_bottom(1)
  67. if row[column]:
  68. sheet.write_row(i, j, [row[column]], style)
  69. else:
  70. sheet.write_row(i, j, [''], style)
  71. j += 1
  72. i += 2
  73. first_row = i+2