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.

149 lines
5.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Author: Damien Crier
  3. # Author: Julien Coux
  4. # Copyright 2016 Camptocamp SA
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. from . import abstract_report_xlsx
  7. from openerp.report import report_sxw
  8. from openerp import _
  9. class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx):
  10. def __init__(self, name, table, rml=False, parser=False, header=True,
  11. store=False):
  12. super(GeneralLedgerXslx, self).__init__(
  13. name, table, rml, parser, header, store)
  14. def _get_report_name(self):
  15. return _('General Ledger')
  16. def _get_report_columns(self, report):
  17. return {
  18. 0: {'header': _('Date'), 'field': 'date', 'width': 11},
  19. 1: {'header': _('Entry'), 'field': 'entry', 'width': 18},
  20. 2: {'header': _('Journal'), 'field': 'journal', 'width': 8},
  21. 3: {'header': _('Account'), 'field': 'account', 'width': 9},
  22. 4: {'header': _('Partner'), 'field': 'partner', 'width': 25},
  23. 5: {'header': _('Ref - Label'), 'field': 'label', 'width': 40},
  24. 6: {'header': _('Cost center'),
  25. 'field': 'cost_center',
  26. 'width': 15},
  27. 7: {'header': _('Rec.'), 'field': 'matching_number', 'width': 5},
  28. 8: {'header': _('Debit'),
  29. 'field': 'debit',
  30. 'field_initial_balance': 'initial_debit',
  31. 'field_final_balance': 'final_debit',
  32. 'type': 'amount',
  33. 'width': 14},
  34. 9: {'header': _('Credit'),
  35. 'field': 'credit',
  36. 'field_initial_balance': 'initial_credit',
  37. 'field_final_balance': 'final_credit',
  38. 'type': 'amount',
  39. 'width': 14},
  40. 10: {'header': _('Cumul. Bal.'),
  41. 'field': 'cumul_balance',
  42. 'field_initial_balance': 'initial_balance',
  43. 'field_final_balance': 'final_balance',
  44. 'type': 'amount',
  45. 'width': 14},
  46. 11: {'header': _('Cur.'), 'field': 'currency_name', 'width': 7},
  47. 12: {'header': _('Amount cur.'),
  48. 'field': 'amount_currency',
  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. [_('Centralize filter'),
  62. _('Yes') if report.centralize else _('No')],
  63. ]
  64. def _get_col_count_filter_name(self):
  65. return 2
  66. def _get_col_count_filter_value(self):
  67. return 2
  68. def _get_col_pos_initial_balance_label(self):
  69. return 5
  70. def _get_col_count_final_balance_name(self):
  71. return 5
  72. def _get_col_pos_final_balance_label(self):
  73. return 5
  74. def _generate_report_content(self, workbook, report):
  75. # For each account
  76. for account in report.account_ids:
  77. # Write account title
  78. self.write_array_title(account.code + ' - ' + account.name)
  79. if not account.partner_ids:
  80. # Display array header for move lines
  81. self.write_array_header()
  82. # Display initial balance line for account
  83. self.write_initial_balance(account, _('Initial balance'))
  84. # Display account move lines
  85. for line in account.move_line_ids:
  86. self.write_line(line)
  87. else:
  88. # For each partner
  89. for partner in account.partner_ids:
  90. # Write partner title
  91. self.write_array_title(partner.name)
  92. # Display array header for move lines
  93. self.write_array_header()
  94. # Display initial balance line for partner
  95. self.write_initial_balance(partner, _('Initial balance'))
  96. # Display account move lines
  97. for line in partner.move_line_ids:
  98. self.write_line(line)
  99. # Display ending balance line for partner
  100. self.write_ending_balance(partner, 'partner')
  101. # Line break
  102. self.row_pos += 1
  103. # Display ending balance line for account
  104. self.write_ending_balance(account, 'account')
  105. # 2 lines break
  106. self.row_pos += 2
  107. def write_ending_balance(self, my_object, type_object):
  108. """Specific function to write ending balance for General Ledger"""
  109. if type_object == 'partner':
  110. name = my_object.name
  111. label = _('Partner ending balance')
  112. elif type_object == 'account':
  113. name = my_object.code + ' - ' + my_object.name
  114. label = _('Ending balance')
  115. super(GeneralLedgerXslx, self).write_ending_balance(
  116. my_object, name, label
  117. )
  118. GeneralLedgerXslx(
  119. 'report.account_financial_report_qweb.report_general_ledger_xlsx',
  120. 'report_general_ledger_qweb',
  121. parser=report_sxw.rml_parse
  122. )