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.

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