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.

249 lines
7.4 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 JournalLedgerXslx(models.AbstractModel):
  7. _name = 'report.a_f_r.report_journal_ledger_xlsx'
  8. _inherit = 'report.account_financial_report.abstract_report_xlsx'
  9. def _get_report_name(self):
  10. return _('Journal Ledger')
  11. def _get_report_columns(self, report):
  12. columns = [
  13. {
  14. 'header': _('Entry'),
  15. 'field': 'entry',
  16. 'width': 18
  17. },
  18. {
  19. 'header': _('Date'),
  20. 'field': 'date',
  21. 'width': 11
  22. },
  23. {
  24. 'header': _('Account'),
  25. 'field': 'account_code',
  26. 'width': 9
  27. },
  28. ]
  29. if report.with_account_name:
  30. columns.append({
  31. 'header': _('Account Name'),
  32. 'field': 'account',
  33. 'width': 15
  34. })
  35. columns += [
  36. {
  37. 'header': _('Partner'),
  38. 'field': 'partner',
  39. 'width': 25
  40. },
  41. {
  42. 'header': _('Ref - Label'),
  43. 'field': 'label',
  44. 'width': 40
  45. },
  46. {
  47. 'header': _('Taxes'),
  48. 'field': 'taxes_description',
  49. 'width': 11
  50. },
  51. {
  52. 'header': _('Debit'),
  53. 'field': 'debit',
  54. 'type': 'amount',
  55. 'width': 14,
  56. },
  57. {
  58. 'header': _('Credit'),
  59. 'field': 'credit',
  60. 'type': 'amount',
  61. 'width': 14
  62. }
  63. ]
  64. if report.foreign_currency:
  65. columns += [
  66. {
  67. 'header': _('Currency'),
  68. 'field': 'currency_id',
  69. 'type': 'many2one',
  70. 'width': 14
  71. },
  72. {
  73. 'header': _('Amount Currency'),
  74. 'field': 'amount_currency',
  75. 'type': 'amount',
  76. 'width': 18
  77. },
  78. ]
  79. columns_as_dict = {}
  80. for i, column in enumerate(columns):
  81. columns_as_dict[i] = column
  82. return columns_as_dict
  83. def _get_journal_tax_columns(self, report):
  84. return {
  85. 0: {
  86. 'header': _('Name'),
  87. 'field': 'tax_name',
  88. 'width': 35
  89. },
  90. 1: {
  91. 'header': _('Description'),
  92. 'field': 'tax_code',
  93. 'width': 18
  94. },
  95. 2: {
  96. 'header': _('Base Debit'),
  97. 'field': 'base_debit',
  98. 'type': 'amount',
  99. 'width': 14
  100. },
  101. 3: {
  102. 'header': _('Base Credit'),
  103. 'field': 'base_credit',
  104. 'type': 'amount',
  105. 'width': 14
  106. },
  107. 4: {
  108. 'header': _('Base Balance'),
  109. 'field': 'base_balance',
  110. 'type': 'amount',
  111. 'width': 14
  112. },
  113. 5: {
  114. 'header': _('Tax Debit'),
  115. 'field': 'tax_debit',
  116. 'type': 'amount',
  117. 'width': 14
  118. },
  119. 6: {
  120. 'header': _('Tax Credit'),
  121. 'field': 'tax_credit',
  122. 'type': 'amount',
  123. 'width': 14
  124. },
  125. 7: {
  126. 'header': _('Tax Balance'),
  127. 'field': 'tax_balance',
  128. 'type': 'amount',
  129. 'width': 14
  130. },
  131. }
  132. def _get_col_count_filter_name(self):
  133. return 2
  134. def _get_col_count_filter_value(self):
  135. return 3
  136. def _get_report_filters(self, report):
  137. target_label_by_value = {
  138. value: label
  139. for value, label in
  140. self.env['journal.ledger.report.wizard']._get_move_targets()
  141. }
  142. sort_option_label_by_value = {
  143. value: label
  144. for value, label in
  145. self.env['journal.ledger.report.wizard']._get_sort_options()
  146. }
  147. return [
  148. [
  149. _('Company'),
  150. report.company_id.name
  151. ],
  152. [
  153. _('Date range filter'),
  154. _('From: %s To: %s') % (report.date_from, report.date_to)
  155. ],
  156. [
  157. _('Target moves filter'),
  158. _("%s") % target_label_by_value[report.move_target],
  159. ],
  160. [
  161. _('Entries sorted by'),
  162. _("%s") % sort_option_label_by_value[report.sort_option],
  163. ],
  164. [
  165. _('Journals'),
  166. ', '.join([
  167. "%s - %s" % (report_journal.code, report_journal.name)
  168. for report_journal in report.report_journal_ledger_ids
  169. ])
  170. ]
  171. ]
  172. def _generate_report_content(self, workbook, report):
  173. group_option = report.group_option
  174. if group_option == 'journal':
  175. for report_journal in report.report_journal_ledger_ids:
  176. self._generate_journal_content(workbook, report_journal)
  177. elif group_option == 'none':
  178. self._generate_no_group_content(workbook, report)
  179. def _generate_no_group_content(self, workbook, report):
  180. self._generate_moves_content(
  181. workbook, report, "Report", report.report_move_ids)
  182. self._generate_no_group_taxes_summary(workbook, report)
  183. def _generate_journal_content(self, workbook, report_journal):
  184. sheet_name = "%s (%s) - %s" % (
  185. report_journal.code,
  186. report_journal.currency_id.name,
  187. report_journal.name,
  188. )
  189. self._generate_moves_content(
  190. workbook, report_journal.report_id, sheet_name,
  191. report_journal.report_move_ids)
  192. self._generate_journal_taxes_summary(workbook, report_journal)
  193. def _generate_no_group_taxes_summary(self, workbook, report):
  194. self._generate_taxes_summary(
  195. workbook, report, "Tax Report", report.report_tax_line_ids)
  196. def _generate_journal_taxes_summary(self, workbook, report_journal):
  197. sheet_name = "Tax - %s (%s) - %s" % (
  198. report_journal.code,
  199. report_journal.currency_id.name,
  200. report_journal.name,
  201. )
  202. report = report_journal.report_id
  203. self._generate_taxes_summary(
  204. workbook, report, sheet_name, report_journal.report_tax_line_ids)
  205. def _generate_moves_content(self, workbook, report, sheet_name, moves):
  206. self.workbook = workbook
  207. self.sheet = workbook.add_worksheet(sheet_name)
  208. self._set_column_width()
  209. self.row_pos = 1
  210. self.write_array_title(sheet_name)
  211. self.row_pos += 2
  212. self.write_array_header()
  213. for move in moves:
  214. for line in move.report_move_line_ids:
  215. self.write_line(line)
  216. self.row_pos += 1
  217. def _generate_taxes_summary(self, workbook, report, sheet_name, tax_lines):
  218. self.workbook = workbook
  219. self.sheet = workbook.add_worksheet(sheet_name)
  220. self.row_pos = 1
  221. self.write_array_title(sheet_name)
  222. self.row_pos += 2