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.

295 lines
12 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, data=False):
  10. company_id = data.get("company_id", False)
  11. report_name = _("General Ledger")
  12. if company_id:
  13. company = self.env["res.company"].browse(company_id)
  14. suffix = " - {} - {}".format(company.name, company.currency_id.name)
  15. report_name = report_name + suffix
  16. return report_name
  17. def _get_report_columns(self, report):
  18. res = {
  19. 0: {"header": _("Date"), "field": "date", "width": 11},
  20. 1: {"header": _("Entry"), "field": "entry", "width": 18},
  21. 2: {"header": _("Journal"), "field": "journal", "width": 8},
  22. 3: {"header": _("Account"), "field": "account", "width": 9},
  23. 4: {"header": _("Taxes"), "field": "taxes_description", "width": 15},
  24. 5: {"header": _("Partner"), "field": "partner_name", "width": 25},
  25. 6: {"header": _("Ref - Label"), "field": "ref", "width": 40},
  26. 7: {"header": _("Cost center"), "field": "cost_center", "width": 15},
  27. 8: {"header": _("Tags"), "field": "tags", "width": 10},
  28. 9: {"header": _("Rec."), "field": "rec_name", "width": 5},
  29. 10: {
  30. "header": _("Debit"),
  31. "field": "debit",
  32. "field_initial_balance": "initial_debit",
  33. "field_final_balance": "final_debit",
  34. "type": "amount",
  35. "width": 14,
  36. },
  37. 11: {
  38. "header": _("Credit"),
  39. "field": "credit",
  40. "field_initial_balance": "initial_credit",
  41. "field_final_balance": "final_credit",
  42. "type": "amount",
  43. "width": 14,
  44. },
  45. 12: {
  46. "header": _("Cumul. Bal."),
  47. "field": "balance",
  48. "field_initial_balance": "initial_balance",
  49. "field_final_balance": "final_balance",
  50. "type": "amount",
  51. "width": 14,
  52. },
  53. }
  54. if report.foreign_currency:
  55. foreign_currency = {
  56. 13: {
  57. "header": _("Cur."),
  58. "field": "currency_name",
  59. "field_currency_balance": "currency_name",
  60. "type": "currency_name",
  61. "width": 7,
  62. },
  63. 14: {
  64. "header": _("Amount cur."),
  65. "field": "bal_curr",
  66. "field_initial_balance": "initial_bal_curr",
  67. "field_final_balance": "final_bal_curr",
  68. "type": "amount_currency",
  69. "width": 14,
  70. },
  71. }
  72. res = {**res, **foreign_currency}
  73. return res
  74. def _get_report_filters(self, report):
  75. return [
  76. [
  77. _("Date range filter"),
  78. _("From: %s To: %s") % (report.date_from, report.date_to),
  79. ],
  80. [
  81. _("Target moves filter"),
  82. _("All posted entries")
  83. if report.target_move == "all"
  84. else _("All entries"),
  85. ],
  86. [
  87. _("Account balance at 0 filter"),
  88. _("Hide") if report.hide_account_at_0 else _("Show"),
  89. ],
  90. [_("Centralize filter"), _("Yes") if report.centralize else _("No"),],
  91. [
  92. _("Show analytic tags"),
  93. _("Yes") if report.show_analytic_tags else _("No"),
  94. ],
  95. [
  96. _("Show foreign currency"),
  97. _("Yes") if report.foreign_currency else _("No"),
  98. ],
  99. ]
  100. def _get_col_count_filter_name(self):
  101. return 2
  102. def _get_col_count_filter_value(self):
  103. return 2
  104. def _get_col_pos_initial_balance_label(self):
  105. return 5
  106. def _get_col_count_final_balance_name(self):
  107. return 5
  108. def _get_col_pos_final_balance_label(self):
  109. return 5
  110. def _generate_report_content(self, workbook, report, data):
  111. res_data = self.env[
  112. "report.account_financial_report.general_ledger"
  113. ]._get_report_values(report, data)
  114. general_ledger = res_data["general_ledger"]
  115. accounts_data = res_data["accounts_data"]
  116. partners_data = res_data["partners_data"]
  117. journals_data = res_data["journals_data"]
  118. taxes_data = res_data["taxes_data"]
  119. tags_data = res_data["tags_data"]
  120. filter_partner_ids = res_data["filter_partner_ids"]
  121. foreign_currency = res_data["foreign_currency"]
  122. # For each account
  123. for account in general_ledger:
  124. # Write account title
  125. self.write_array_title(
  126. account["code"] + " - " + accounts_data[account["id"]]["name"]
  127. )
  128. if not account["partners"]:
  129. # Display array header for move lines
  130. self.write_array_header()
  131. # Display initial balance line for account
  132. account.update(
  133. {
  134. "initial_debit": account["init_bal"]["debit"],
  135. "initial_credit": account["init_bal"]["credit"],
  136. "initial_balance": account["init_bal"]["balance"],
  137. }
  138. )
  139. if foreign_currency:
  140. account.update(
  141. {"initial_bal_curr": account["init_bal"]["bal_curr"],}
  142. )
  143. self.write_initial_balance_from_dict(account)
  144. # Display account move lines
  145. for line in account["move_lines"]:
  146. line.update(
  147. {
  148. "account": account["code"],
  149. "journal": journals_data[line["journal_id"]]["code"],
  150. }
  151. )
  152. if line["currency_id"]:
  153. line.update(
  154. {
  155. "currency_name": line["currency_id"][1],
  156. "currency_id": line["currency_id"][0],
  157. }
  158. )
  159. if line["ref"] != "Centralized entries":
  160. taxes_description = ""
  161. tags = ""
  162. for tax_id in line["tax_ids"]:
  163. taxes_description += (
  164. str(taxes_data[tax_id]["amount"])
  165. + " "
  166. + taxes_data[tax_id]["string"]
  167. + " "
  168. )
  169. for tag_id in line["tag_ids"]:
  170. tags += tags_data[tag_id]["name"] + " "
  171. line.update(
  172. {"taxes_description": taxes_description, "tags": tags,}
  173. )
  174. self.write_line_from_dict(line)
  175. else:
  176. # For each partner
  177. for partner in account["list_partner"]:
  178. # Write partner title
  179. self.write_array_title(partners_data[partner["id"]]["name"])
  180. # Display array header for move lines
  181. self.write_array_header()
  182. # Display initial balance line for partner
  183. partner.update(
  184. {
  185. "initial_debit": partner["init_bal"]["debit"],
  186. "initial_credit": partner["init_bal"]["credit"],
  187. "initial_balance": partner["init_bal"]["balance"],
  188. "name": partners_data[partner["id"]]["name"],
  189. "type": "partner",
  190. "currency_id": accounts_data[account["id"]]["currency_id"],
  191. }
  192. )
  193. if foreign_currency:
  194. partner.update(
  195. {"initial_bal_culrr": partner["init_bal"]["bal_curr"],}
  196. )
  197. self.write_initial_balance_from_dict(partner)
  198. # Display account move lines
  199. for line in partner["move_lines"]:
  200. line.update(
  201. {
  202. "account": account["code"],
  203. "journal": journals_data[line["journal_id"]]["code"],
  204. }
  205. )
  206. if line["ref"] != "Centralized entries":
  207. taxes_description = ""
  208. tags = ""
  209. for tax_id in line["tax_ids"]:
  210. taxes_description += (
  211. str(taxes_data[tax_id]["amount"])
  212. + " "
  213. + taxes_data[tax_id]["string"]
  214. + " "
  215. )
  216. for tag_id in line["tag_ids"]:
  217. tags += tags_data[tag_id]["name"] + " "
  218. line.update(
  219. {"taxes_description": taxes_description, "tags": tags,}
  220. )
  221. self.write_line_from_dict(line)
  222. # Display ending balance line for partner
  223. partner.update(
  224. {
  225. "final_debit": partner["fin_bal"]["debit"],
  226. "final_credit": partner["fin_bal"]["credit"],
  227. "final_balance": partner["fin_bal"]["balance"],
  228. }
  229. )
  230. if foreign_currency:
  231. partner.update(
  232. {"final_bal_curr": partner["fin_bal"]["bal_curr"],}
  233. )
  234. self.write_ending_balance_from_dict(partner)
  235. # Line break
  236. self.row_pos += 1
  237. # Display ending balance line for account
  238. if not filter_partner_ids:
  239. account.update(
  240. {
  241. "final_debit": account["fin_bal"]["debit"],
  242. "final_credit": account["fin_bal"]["credit"],
  243. "final_balance": account["fin_bal"]["balance"],
  244. }
  245. )
  246. if foreign_currency:
  247. account.update(
  248. {"final_bal_curr": account["fin_bal"]["bal_curr"],}
  249. )
  250. self.write_ending_balance_from_dict(account)
  251. # 2 lines break
  252. self.row_pos += 2
  253. def write_initial_balance_from_dict(self, my_object):
  254. """Specific function to write initial balance for General Ledger"""
  255. if "partner" in my_object["type"]:
  256. label = _("Partner Initial balance")
  257. elif "account" in my_object["type"]:
  258. label = _("Initial balance")
  259. super(GeneralLedgerXslx, self).write_initial_balance_from_dict(my_object, label)
  260. def write_ending_balance_from_dict(self, my_object):
  261. """Specific function to write ending balance for General Ledger"""
  262. if "partner" in my_object["type"]:
  263. name = my_object["name"]
  264. label = _("Partner ending balance")
  265. elif "account" in my_object["type"]:
  266. name = my_object["code"] + " - " + my_object["name"]
  267. label = _("Ending balance")
  268. super(GeneralLedgerXslx, self).write_ending_balance_from_dict(
  269. my_object, name, label
  270. )