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.

199 lines
7.0 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 odoo.report import report_sxw
  8. from odoo 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, report):
  15. report_name = _('General Ledger')
  16. return self._get_report_complete_name(report, report_name)
  17. def _get_report_columns(self, report):
  18. res = {
  19. 0: {'header': _('Date'), 'field': 'date', 'width': 11},
  20. 1: {'header': _('Entry'), 'field': 'entry', 'width': 18},
  21. 2: {'header': _('Journal'), 'field': 'journal', 'width': 8},
  22. 3: {'header': _('Account'), 'field': 'account', 'width': 9},
  23. 4: {'header': _('Taxes'),
  24. 'field': 'taxes_description',
  25. 'width': 15},
  26. 5: {'header': _('Partner'), 'field': 'partner', 'width': 25},
  27. 6: {'header': _('Ref - Label'), 'field': 'label', 'width': 40},
  28. 7: {'header': _('Cost center'),
  29. 'field': 'cost_center',
  30. 'width': 15},
  31. 8: {'header': _('Tags'),
  32. 'field': 'tags',
  33. 'width': 10},
  34. 9: {'header': _('Rec.'),
  35. 'field': 'reconcile_string',
  36. 'width': 5},
  37. 10: {'header': _('Debit'),
  38. 'field': 'debit',
  39. 'field_initial_balance': 'initial_debit',
  40. 'field_final_balance': 'final_debit',
  41. 'type': 'amount',
  42. 'width': 14},
  43. 11: {
  44. 'header': _('Credit'),
  45. 'field': 'credit',
  46. 'field_initial_balance': 'initial_credit',
  47. 'field_final_balance': 'final_credit',
  48. 'type': 'amount',
  49. 'width': 14
  50. },
  51. 12: {'header': _('Cumul. Bal.'),
  52. 'field': 'cumul_balance',
  53. 'field_initial_balance': 'initial_balance',
  54. 'field_final_balance': 'final_balance',
  55. 'type': 'amount',
  56. 'width': 14},
  57. }
  58. if report.foreign_currency:
  59. foreign_currency = {
  60. 13: {'header': _('Cur.'),
  61. 'field': 'currency_id',
  62. 'field_currency_balance': 'currency_id',
  63. 'type': 'many2one',
  64. 'width': 7},
  65. 14: {'header': _('Amount cur.'),
  66. 'field': 'amount_currency',
  67. 'field_initial_balance':
  68. 'initial_balance_foreign_currency',
  69. 'field_final_balance': 'final_balance_foreign_currency',
  70. 'type': 'amount_currency',
  71. 'width': 14},
  72. }
  73. res = dict(res.items() + foreign_currency.items())
  74. return res
  75. def _get_report_filters(self, report):
  76. return [
  77. [
  78. _('Date range filter'),
  79. _('From: %s To: %s') % (report.date_from, report.date_to),
  80. ],
  81. [
  82. _('Target moves filter'),
  83. _('All posted entries') if report.only_posted_moves
  84. else _('All entries'),
  85. ],
  86. [
  87. _('Account balance at 0 filter'),
  88. _('Hide') if report.hide_account_at_0 else _('Show'),
  89. ],
  90. [
  91. _('Centralize filter'),
  92. _('Yes') if report.centralize else _('No'),
  93. ],
  94. [
  95. _('Show analytic tags'),
  96. _('Yes') if report.show_analytic_tags else _('No'),
  97. ],
  98. [
  99. _('Show foreign currency'),
  100. _('Yes') if report.foreign_currency else _('No')
  101. ],
  102. ]
  103. def _get_col_count_filter_name(self):
  104. return 2
  105. def _get_col_count_filter_value(self):
  106. return 2
  107. def _get_col_pos_initial_balance_label(self):
  108. return 5
  109. def _get_col_count_final_balance_name(self):
  110. return 5
  111. def _get_col_pos_final_balance_label(self):
  112. return 5
  113. def _generate_report_content(self, workbook, report):
  114. # For each account
  115. for account in report.account_ids:
  116. # Write account title
  117. self.write_array_title(account.code + ' - ' + account.name)
  118. if not account.partner_ids:
  119. # Display array header for move lines
  120. self.write_array_header()
  121. # Display initial balance line for account
  122. self.write_initial_balance(account)
  123. # Display account move lines
  124. for line in account.move_line_ids:
  125. self.write_line(line)
  126. else:
  127. # For each partner
  128. for partner in account.partner_ids:
  129. # Write partner title
  130. self.write_array_title(partner.name)
  131. # Display array header for move lines
  132. self.write_array_header()
  133. # Display initial balance line for partner
  134. self.write_initial_balance(partner)
  135. # Display account move lines
  136. for line in partner.move_line_ids:
  137. self.write_line(line)
  138. # Display ending balance line for partner
  139. self.write_ending_balance(partner)
  140. # Line break
  141. self.row_pos += 1
  142. # Display ending balance line for account
  143. self.write_ending_balance(account)
  144. # 2 lines break
  145. self.row_pos += 2
  146. def write_initial_balance(self, my_object):
  147. """Specific function to write initial balance for General Ledger"""
  148. if 'partner' in my_object._name:
  149. label = _('Partner Initial balance')
  150. my_object.currency_id = my_object.report_account_id.currency_id
  151. elif 'account' in my_object._name:
  152. label = _('Initial balance')
  153. super(GeneralLedgerXslx, self).write_initial_balance(
  154. my_object, label
  155. )
  156. def write_ending_balance(self, my_object):
  157. """Specific function to write ending balance for General Ledger"""
  158. if 'partner' in my_object._name:
  159. name = my_object.name
  160. label = _('Partner ending balance')
  161. elif 'account' in my_object._name:
  162. name = my_object.code + ' - ' + my_object.name
  163. label = _('Ending balance')
  164. super(GeneralLedgerXslx, self).write_ending_balance(
  165. my_object, name, label
  166. )
  167. GeneralLedgerXslx(
  168. 'report.account_financial_report_qweb.report_general_ledger_xlsx',
  169. 'report_general_ledger_qweb',
  170. parser=report_sxw.rml_parse
  171. )