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.

182 lines
6.5 KiB

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