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.

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