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.

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