OCA reporting engine fork for dev and update.
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.

106 lines
3.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. # Copyright 2009-2019 Noviat.
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import models
  4. # TODO:
  5. # make PR to move this class as well as the report_xlsx test class
  6. # to the tests folder (requires dynamic update Odoo registry when
  7. # running unit tests.
  8. class TestPartnerXlsx(models.AbstractModel):
  9. _name = 'report.report_xlsx_helper.test_partner_xlsx'
  10. _inherit = 'report.report_xlsx.abstract'
  11. def _get_ws_params(self, wb, data, partners):
  12. partner_template = {
  13. 'name': {
  14. 'header': {
  15. 'value': 'Name',
  16. },
  17. 'data': {
  18. 'value': self._render("partner.name"),
  19. },
  20. 'width': 20,
  21. },
  22. 'number_of_contacts': {
  23. 'header': {
  24. 'value': '# Contacts',
  25. },
  26. 'data': {
  27. 'value': self._render("len(partner.child_ids)"),
  28. },
  29. 'width': 10,
  30. },
  31. 'is_customer': {
  32. 'header': {
  33. 'value': 'Customer',
  34. },
  35. 'data': {
  36. 'value': self._render("partner.customer"),
  37. },
  38. 'width': 10,
  39. },
  40. 'is_customer_formula': {
  41. 'header': {
  42. 'value': 'Customer Y/N ?',
  43. },
  44. 'data': {
  45. 'type': 'formula',
  46. 'value': self._render("customer_formula"),
  47. },
  48. 'width': 14,
  49. },
  50. 'date': {
  51. 'header': {
  52. 'value': 'Date',
  53. },
  54. 'data': {
  55. 'value': self._render("partner.date"),
  56. },
  57. 'width': 13,
  58. },
  59. }
  60. ws_params = {
  61. 'ws_name': 'Partners',
  62. 'generate_ws_method': '_partner_report',
  63. 'title': 'Partners',
  64. 'wanted_list': [k for k in partner_template],
  65. 'col_specs': partner_template,
  66. }
  67. return [ws_params]
  68. def _partner_report(self, workbook, ws, ws_params, data, partners):
  69. ws.set_portrait()
  70. ws.fit_to_pages(1, 0)
  71. ws.set_header(self.xls_headers['standard'])
  72. ws.set_footer(self.xls_footers['standard'])
  73. self._set_column_width(ws, ws_params)
  74. row_pos = 0
  75. row_pos = self._write_ws_title(ws, row_pos, ws_params)
  76. row_pos = self._write_line(
  77. ws, row_pos, ws_params, col_specs_section='header',
  78. default_format=self.format_theader_yellow_left)
  79. ws.freeze_panes(row_pos, 0)
  80. wl = ws_params['wanted_list']
  81. for partner in partners:
  82. is_customer_pos = 'is_customer' in wl and \
  83. wl.index('is_customer')
  84. is_customer_cell = self._rowcol_to_cell(
  85. row_pos, is_customer_pos)
  86. customer_formula = 'IF({},"Y", "N")'.format(is_customer_cell)
  87. row_pos = self._write_line(
  88. ws, row_pos, ws_params, col_specs_section='data',
  89. render_space={
  90. 'partner': partner,
  91. 'customer_formula': customer_formula,
  92. },
  93. default_format=self.format_tcell_left)