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.

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