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.

183 lines
7.2 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. # Custom values needed to generate report
  15. self.col_pos_initial_balance_label = 5
  16. self.col_count_final_balance_name = 5
  17. self.col_pos_final_balance_label = 5
  18. def _get_report_name(self):
  19. return _('General Ledger')
  20. def _get_report_columns(self):
  21. return {
  22. 0: {'header': _('Date'), 'field': 'date', 'width': 11},
  23. 1: {'header': _('Entry'), 'field': 'entry', 'width': 18},
  24. 2: {'header': _('Journal'), 'field': 'journal', 'width': 8},
  25. 3: {'header': _('Account'), 'field': 'account', 'width': 9},
  26. 4: {'header': _('Partner'), 'field': 'partner', 'width': 25},
  27. 5: {'header': _('Ref - Label'), 'field': 'label', 'width': 40},
  28. 6: {'header': _('Cost center'),
  29. 'field': 'cost_center',
  30. 'width': 15},
  31. 7: {'header': _('Rec.'), 'field': 'matching_number', 'width': 5},
  32. 8: {'header': _('Debit'),
  33. 'field': 'debit',
  34. 'field_initial_balance': 'initial_debit',
  35. 'field_final_balance': 'final_debit',
  36. 'type': 'amount',
  37. 'width': 14},
  38. 9: {'header': _('Credit'),
  39. 'field': 'credit',
  40. 'field_initial_balance': 'initial_credit',
  41. 'field_final_balance': 'final_credit',
  42. 'type': 'amount',
  43. 'width': 14},
  44. 10: {'header': _('Cumul. Bal.'),
  45. 'field': 'cumul_balance',
  46. 'field_initial_balance': 'initial_balance',
  47. 'field_final_balance': 'final_balance',
  48. 'type': 'amount',
  49. 'width': 14},
  50. 11: {'header': _('Cur.'), 'field': 'currency_name', 'width': 7},
  51. 12: {'header': _('Amount cur.'),
  52. 'field': 'amount_currency',
  53. 'type': 'amount',
  54. 'width': 14},
  55. }
  56. def _get_report_filters(self, report):
  57. return [
  58. [_('Date range filter'),
  59. _('From: %s To: %s') % (report.date_from, report.date_to)],
  60. [_('Target moves filter'),
  61. _('All posted entries') if report.only_posted_moves
  62. else _('All entries')],
  63. [_('Account balance at 0 filter'),
  64. _('Hide') if report.hide_account_balance_at_0 else _('Show')],
  65. [_('Centralize filter'),
  66. _('Yes') if report.centralize else _('No')],
  67. ]
  68. def _get_col_count_filter_name(self):
  69. return 2
  70. def _get_col_count_filter_value(self):
  71. return 2
  72. def _generate_report_content(self, workbook, report):
  73. # For each account
  74. for account in report.account_ids:
  75. # Write account title
  76. self.write_array_title(account.code + ' - ' + account.name)
  77. if not account.partner_ids:
  78. # Display array header for move lines
  79. self.write_array_header()
  80. # Display initial balance line for account
  81. self.write_initial_balance(account)
  82. # Display account move lines
  83. for line in account.move_line_ids:
  84. self.write_line(line)
  85. else:
  86. # For each partner
  87. for partner in account.partner_ids:
  88. # Write partner title
  89. self.write_array_title(partner.name)
  90. # Display array header for move lines
  91. self.write_array_header()
  92. # Display initial balance line for partner
  93. self.write_initial_balance(partner)
  94. # Display account move lines
  95. for line in partner.move_line_ids:
  96. self.write_line(line)
  97. # Display ending balance line for partner
  98. self.write_ending_balance(partner, 'partner')
  99. # Line break
  100. self.row_pos += 1
  101. # Display ending balance line for account
  102. self.write_ending_balance(account, 'account')
  103. # 2 lines break
  104. self.row_pos += 2
  105. def write_initial_balance(self, my_object):
  106. """Specific function to write initial balance for General Ledger"""
  107. col_pos_label = self.col_pos_initial_balance_label
  108. self.sheet.write(self.row_pos, col_pos_label, _('Initial balance'),
  109. self.format_right)
  110. for col_pos, column in self.columns.iteritems():
  111. if column.get('field_initial_balance'):
  112. value = getattr(my_object, column['field_initial_balance'])
  113. cell_type = column.get('type', 'string')
  114. if cell_type == 'string':
  115. self.sheet.write_string(self.row_pos, col_pos, value or '')
  116. elif cell_type == 'amount':
  117. self.sheet.write_number(
  118. self.row_pos, col_pos, float(value), self.format_amount
  119. )
  120. self.row_pos += 1
  121. def write_ending_balance(self, my_object, type_object):
  122. """Specific function to write ending balance for General Ledger"""
  123. if type_object == 'partner':
  124. name = my_object.name
  125. label = _('Partner ending balance')
  126. elif type_object == 'account':
  127. name = my_object.code + ' - ' + my_object.name
  128. label = _('Ending balance')
  129. for i in range(0, len(self.columns)):
  130. self.sheet.write(self.row_pos, i, '', self.format_header_right)
  131. row_count_name = self.col_count_final_balance_name
  132. row_pos = self.row_pos
  133. col_pos_label = self.col_pos_final_balance_label
  134. self.sheet.merge_range(
  135. row_pos, 0, row_pos, row_count_name - 1, name,
  136. self.format_header_left
  137. )
  138. self.sheet.write(row_pos, col_pos_label, label,
  139. self.format_header_right)
  140. for col_pos, column in self.columns.iteritems():
  141. if column.get('field_final_balance'):
  142. value = getattr(my_object, column['field_final_balance'])
  143. cell_type = column.get('type', 'string')
  144. if cell_type == 'string':
  145. self.sheet.write_string(self.row_pos, col_pos, value or '',
  146. self.format_header_right)
  147. elif cell_type == 'amount':
  148. self.sheet.write_number(
  149. self.row_pos, col_pos, float(value),
  150. self.format_header_amount
  151. )
  152. self.row_pos += 1
  153. GeneralLedgerXslx(
  154. 'report.account_financial_report_qweb.report_general_ledger_xlsx',
  155. 'report_general_ledger_qweb',
  156. parser=report_sxw.rml_parse
  157. )