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.

122 lines
4.4 KiB

  1. # Author: Julien Coux
  2. # Copyright 2016 Camptocamp SA
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import _, models
  5. class TrialBalanceXslx(models.AbstractModel):
  6. _name = 'report.a_f_r.report_trial_balance_xlsx'
  7. _inherit = 'report.account_financial_report.abstract_report_xlsx'
  8. def _get_report_name(self):
  9. return _('Trial Balance')
  10. def _get_report_columns(self, report):
  11. if not report.show_partner_details:
  12. return {
  13. 0: {'header': _('Code'), 'field': 'code', 'width': 10},
  14. 1: {'header': _('Account'), 'field': 'name', 'width': 60},
  15. 2: {'header': _('Initial balance'),
  16. 'field': 'initial_balance',
  17. 'type': 'amount',
  18. 'width': 14},
  19. 3: {'header': _('Debit'),
  20. 'field': 'debit',
  21. 'type': 'amount',
  22. 'width': 14},
  23. 4: {'header': _('Credit'),
  24. 'field': 'credit',
  25. 'type': 'amount',
  26. 'width': 14},
  27. 5: {'header': _('Ending balance'),
  28. 'field': 'final_balance',
  29. 'type': 'amount',
  30. 'width': 14},
  31. }
  32. else:
  33. return {
  34. 0: {'header': _('Partner'), 'field': 'name', 'width': 70},
  35. 1: {'header': _('Initial balance'),
  36. 'field': 'initial_balance',
  37. 'type': 'amount',
  38. 'width': 14},
  39. 2: {'header': _('Debit'),
  40. 'field': 'debit',
  41. 'type': 'amount',
  42. 'width': 14},
  43. 3: {'header': _('Credit'),
  44. 'field': 'credit',
  45. 'type': 'amount',
  46. 'width': 14},
  47. 4: {'header': _('Ending balance'),
  48. 'field': 'final_balance',
  49. 'type': 'amount',
  50. 'width': 14},
  51. }
  52. def _get_report_filters(self, report):
  53. return [
  54. [_('Date range filter'),
  55. _('From: %s To: %s') % (report.date_from, report.date_to)],
  56. [_('Target moves filter'),
  57. _('All posted entries') if report.only_posted_moves
  58. else _('All entries')],
  59. [_('Account balance at 0 filter'),
  60. _('Hide') if report.hide_account_balance_at_0 else _('Show')],
  61. ]
  62. def _get_col_count_filter_name(self):
  63. return 2
  64. def _get_col_count_filter_value(self):
  65. return 3
  66. def _generate_report_content(self, workbook, report):
  67. if not report.show_partner_details:
  68. # Display array header for account lines
  69. self.write_array_header()
  70. # For each account
  71. for account in report.account_ids:
  72. if not report.show_partner_details:
  73. # Display account lines
  74. self.write_line(account)
  75. else:
  76. # Write account title
  77. self.write_array_title(account.code + ' - ' + account.name)
  78. # Display array header for partner lines
  79. self.write_array_header()
  80. # For each partner
  81. for partner in account.partner_ids:
  82. # Display partner lines
  83. self.write_line(partner)
  84. # Display account footer line
  85. self.write_account_footer(account,
  86. account.code + ' - ' + account.name)
  87. # Line break
  88. self.row_pos += 2
  89. def write_account_footer(self, account, name_value):
  90. """Specific function to write account footer for Trial Balance"""
  91. for col_pos, column in self.columns.items():
  92. if column['field'] == 'name':
  93. value = name_value
  94. else:
  95. value = getattr(account, column['field'])
  96. cell_type = column.get('type', 'string')
  97. if cell_type == 'string':
  98. self.sheet.write_string(self.row_pos, col_pos, value or '',
  99. self.format_header_left)
  100. elif cell_type == 'amount':
  101. self.sheet.write_number(self.row_pos, col_pos, float(value),
  102. self.format_header_amount)
  103. self.row_pos += 1