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.

133 lines
4.7 KiB

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