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.

216 lines
8.2 KiB

  1. # Author: Julien Coux
  2. # Copyright 2016 Camptocamp SA
  3. # Copyright 2021 Tecnativa - João Marques
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import _, models
  6. class OpenItemsXslx(models.AbstractModel):
  7. _name = "report.a_f_r.report_open_items_xlsx"
  8. _description = "Open Items XLSX Report"
  9. _inherit = "report.account_financial_report.abstract_report_xlsx"
  10. def _get_report_name(self, report, data=False):
  11. company_id = data.get("company_id", False)
  12. report_name = _("Open Items")
  13. if company_id:
  14. company = self.env["res.company"].browse(company_id)
  15. suffix = " - {} - {}".format(company.name, company.currency_id.name)
  16. report_name = report_name + suffix
  17. return report_name
  18. def _get_report_columns(self, report):
  19. res = {
  20. 0: {"header": _("Date"), "field": "date", "width": 11},
  21. 1: {"header": _("Entry"), "field": "move_name", "width": 18},
  22. 2: {"header": _("Journal"), "field": "journal", "width": 8},
  23. 3: {"header": _("Account"), "field": "account", "width": 9},
  24. 4: {"header": _("Partner"), "field": "partner_name", "width": 25},
  25. 5: {"header": _("Ref - Label"), "field": "ref_label", "width": 40},
  26. 6: {"header": _("Due date"), "field": "date_maturity", "width": 11},
  27. 7: {
  28. "header": _("Original"),
  29. "field": "original",
  30. "type": "amount",
  31. "width": 14,
  32. },
  33. 8: {
  34. "header": _("Residual"),
  35. "field": "amount_residual",
  36. "field_final_balance": "residual",
  37. "type": "amount",
  38. "width": 14,
  39. },
  40. }
  41. if report.foreign_currency:
  42. foreign_currency = {
  43. 9: {
  44. "header": _("Cur."),
  45. "field": "currency_name",
  46. "field_currency_balance": "currency_name",
  47. "type": "currency_name",
  48. "width": 7,
  49. },
  50. 10: {
  51. "header": _("Cur. Original"),
  52. "field": "amount_currency",
  53. "field_final_balance": "amount_currency",
  54. "type": "amount_currency",
  55. "width": 14,
  56. },
  57. 11: {
  58. "header": _("Cur. Residual"),
  59. "field": "amount_residual_currency",
  60. "field_final_balance": "amount_currency",
  61. "type": "amount_currency",
  62. "width": 14,
  63. },
  64. }
  65. res = {**res, **foreign_currency}
  66. return res
  67. def _get_report_filters(self, report):
  68. return [
  69. [_("Date at filter"), report.date_at.strftime("%d/%m/%Y")],
  70. [
  71. _("Target moves filter"),
  72. _("All posted entries")
  73. if report.target_move == "posted"
  74. else _("All entries"),
  75. ],
  76. [
  77. _("Account balance at 0 filter"),
  78. _("Hide") if report.hide_account_at_0 else _("Show"),
  79. ],
  80. [
  81. _("Show foreign currency"),
  82. _("Yes") if report.foreign_currency else _("No"),
  83. ],
  84. ]
  85. def _get_col_count_filter_name(self):
  86. return 2
  87. def _get_col_count_filter_value(self):
  88. return 2
  89. def _get_col_count_final_balance_name(self):
  90. return 5
  91. def _get_col_pos_final_balance_label(self):
  92. return 5
  93. def _generate_report_content(self, workbook, report, data, report_data):
  94. res_data = self.env[
  95. "report.account_financial_report.open_items"
  96. ]._get_report_values(report, data)
  97. # For each account
  98. Open_items = res_data["Open_Items"]
  99. accounts_data = res_data["accounts_data"]
  100. partners_data = res_data["partners_data"]
  101. journals_data = res_data["journals_data"]
  102. total_amount = res_data["total_amount"]
  103. show_partner_details = res_data["show_partner_details"]
  104. for account_id in Open_items.keys():
  105. # Write account title
  106. self.write_array_title(
  107. accounts_data[account_id]["code"]
  108. + " - "
  109. + accounts_data[account_id]["name"],
  110. report_data,
  111. )
  112. # For each partner
  113. if Open_items[account_id]:
  114. if show_partner_details:
  115. for partner_id in Open_items[account_id]:
  116. type_object = "partner"
  117. # Write partner title
  118. self.write_array_title(
  119. partners_data[partner_id]["name"], report_data
  120. )
  121. # Display array header for move lines
  122. self.write_array_header(report_data)
  123. # Display account move lines
  124. for line in Open_items[account_id][partner_id]:
  125. line.update(
  126. {
  127. "account": accounts_data[account_id]["code"],
  128. "journal": journals_data[line["journal_id"]][
  129. "code"
  130. ],
  131. }
  132. )
  133. self.write_line_from_dict(line, report_data)
  134. # Display ending balance line for partner
  135. partners_data[partner_id].update(
  136. {
  137. "currency_id": accounts_data[account_id]["currency_id"],
  138. "currency_name": accounts_data[account_id][
  139. "currency_name"
  140. ],
  141. }
  142. )
  143. self.write_ending_balance_from_dict(
  144. partners_data[partner_id],
  145. type_object,
  146. total_amount,
  147. report_data,
  148. account_id=account_id,
  149. partner_id=partner_id,
  150. )
  151. # Line break
  152. report_data["row_pos"] += 1
  153. else:
  154. # Display array header for move lines
  155. self.write_array_header(report_data)
  156. # Display account move lines
  157. for line in Open_items[account_id]:
  158. line.update(
  159. {
  160. "account": accounts_data[account_id]["code"],
  161. "journal": journals_data[line["journal_id"]]["code"],
  162. }
  163. )
  164. self.write_line_from_dict(line, report_data)
  165. # Display ending balance line for account
  166. type_object = "account"
  167. self.write_ending_balance_from_dict(
  168. accounts_data[account_id],
  169. type_object,
  170. total_amount,
  171. report_data,
  172. account_id=account_id,
  173. )
  174. # 2 lines break
  175. report_data["row_pos"] += 2
  176. def write_ending_balance_from_dict(
  177. self,
  178. my_object,
  179. type_object,
  180. total_amount,
  181. report_data,
  182. account_id=False,
  183. partner_id=False,
  184. ):
  185. """Specific function to write ending balance for Open Items"""
  186. if type_object == "partner":
  187. name = my_object["name"]
  188. my_object["residual"] = total_amount[account_id][partner_id]["residual"]
  189. label = _("Partner ending balance")
  190. elif type_object == "account":
  191. name = my_object["code"] + " - " + my_object["name"]
  192. my_object["residual"] = total_amount[account_id]["residual"]
  193. label = _("Ending balance")
  194. super(OpenItemsXslx, self).write_ending_balance_from_dict(
  195. my_object, name, label, report_data
  196. )