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