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.

856 lines
33 KiB

  1. # Author: Julien Coux
  2. # Copyright 2016 Camptocamp SA
  3. # Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo.addons.account.tests.common import AccountTestInvoicingCommon
  6. class TestTrialBalanceReport(AccountTestInvoicingCommon):
  7. @classmethod
  8. def setUpClass(cls, chart_template_ref=None):
  9. super().setUpClass(chart_template_ref=chart_template_ref)
  10. # Remove previous account groups and related invoices to avoid conflicts
  11. group_obj = cls.env["account.group"]
  12. cls.group1 = group_obj.create({"code_prefix_start": "1", "name": "Group 1"})
  13. cls.group11 = group_obj.create(
  14. {"code_prefix_start": "11", "name": "Group 11", "parent_id": cls.group1.id}
  15. )
  16. cls.group2 = group_obj.create({"code_prefix_start": "2", "name": "Group 2"})
  17. # Set accounts
  18. cls.account100 = cls.company_data["default_account_receivable"]
  19. cls.account100.group_id = cls.group1.id
  20. cls.account110 = cls.env["account.account"].search(
  21. [
  22. (
  23. "user_type_id",
  24. "=",
  25. cls.env.ref("account.data_unaffected_earnings").id,
  26. ),
  27. ],
  28. limit=1,
  29. )
  30. cls.account200 = cls._create_account_account(
  31. cls,
  32. {
  33. "code": "200",
  34. "name": "Account 200",
  35. "group_id": cls.group2.id,
  36. "user_type_id": cls.env.ref(
  37. "account.data_account_type_other_income"
  38. ).id,
  39. },
  40. )
  41. cls.account300 = cls._create_account_account(
  42. cls,
  43. {
  44. "code": "300",
  45. "name": "Account 300",
  46. "user_type_id": cls.env.ref(
  47. "account.data_account_type_other_income"
  48. ).id,
  49. },
  50. )
  51. cls.account301 = cls._create_account_account(
  52. cls,
  53. {
  54. "code": "301",
  55. "name": "Account 301",
  56. "group_id": cls.group2.id,
  57. "user_type_id": cls.env.ref(
  58. "account.data_account_type_other_income"
  59. ).id,
  60. },
  61. )
  62. cls.previous_fy_date_start = "2015-01-01"
  63. cls.previous_fy_date_end = "2015-12-31"
  64. cls.fy_date_start = "2016-01-01"
  65. cls.fy_date_end = "2016-12-31"
  66. cls.date_start = "2016-01-01"
  67. cls.date_end = "2016-12-31"
  68. cls.partner = cls.env.ref("base.res_partner_12")
  69. cls.unaffected_account = cls.env["account.account"].search(
  70. [
  71. (
  72. "user_type_id",
  73. "=",
  74. cls.env.ref("account.data_unaffected_earnings").id,
  75. ),
  76. ],
  77. limit=1,
  78. )
  79. def _create_account_account(self, vals):
  80. item = self.env["account.account"].create(vals)
  81. if "group_id" in vals:
  82. item.group_id = vals["group_id"]
  83. return item
  84. def _add_move(
  85. self,
  86. date,
  87. receivable_debit,
  88. receivable_credit,
  89. income_debit,
  90. income_credit,
  91. unaffected_debit=0,
  92. unaffected_credit=0,
  93. ):
  94. journal = self.env["account.journal"].search(
  95. [("company_id", "=", self.env.user.company_id.id)], limit=1
  96. )
  97. partner = self.env.ref("base.res_partner_12")
  98. move_vals = {
  99. "journal_id": journal.id,
  100. "date": date,
  101. "line_ids": [
  102. (
  103. 0,
  104. 0,
  105. {
  106. "debit": receivable_debit,
  107. "credit": receivable_credit,
  108. "partner_id": partner.id,
  109. "account_id": self.account100.id,
  110. },
  111. ),
  112. (
  113. 0,
  114. 0,
  115. {
  116. "debit": income_debit,
  117. "credit": income_credit,
  118. "partner_id": partner.id,
  119. "account_id": self.account200.id,
  120. },
  121. ),
  122. (
  123. 0,
  124. 0,
  125. {
  126. "debit": unaffected_debit,
  127. "credit": unaffected_credit,
  128. "partner_id": partner.id,
  129. "account_id": self.account110.id,
  130. },
  131. ),
  132. (
  133. 0,
  134. 0,
  135. {
  136. "debit": receivable_debit,
  137. "credit": receivable_credit,
  138. "partner_id": partner.id,
  139. "account_id": self.account300.id,
  140. },
  141. ),
  142. (
  143. 0,
  144. 0,
  145. {
  146. "debit": receivable_credit,
  147. "credit": receivable_debit,
  148. "partner_id": partner.id,
  149. "account_id": self.account301.id,
  150. },
  151. ),
  152. ],
  153. }
  154. move = self.env["account.move"].create(move_vals)
  155. move.action_post()
  156. def _get_report_lines(
  157. self, with_partners=False, account_ids=False, hierarchy_on="computed"
  158. ):
  159. company = self.env.user.company_id
  160. trial_balance = self.env["trial.balance.report.wizard"].create(
  161. {
  162. "date_from": self.date_start,
  163. "date_to": self.date_end,
  164. "target_move": "posted",
  165. "hide_account_at_0": True,
  166. "hierarchy_on": hierarchy_on,
  167. "company_id": company.id,
  168. "account_ids": account_ids,
  169. "fy_start_date": self.fy_date_start,
  170. "show_partner_details": with_partners,
  171. }
  172. )
  173. data = trial_balance._prepare_report_trial_balance()
  174. res_data = self.env[
  175. "report.account_financial_report.trial_balance"
  176. ]._get_report_values(trial_balance, data)
  177. return res_data
  178. def check_account_in_report(self, account_id, trial_balance):
  179. account_in_report = False
  180. for account in trial_balance:
  181. if account["id"] == account_id and account["type"] == "account_type":
  182. account_in_report = True
  183. break
  184. return account_in_report
  185. def _get_account_lines(self, account_id, trial_balance):
  186. lines = False
  187. for account in trial_balance:
  188. if account["id"] == account_id and account["type"] == "account_type":
  189. lines = {
  190. "initial_balance": account["initial_balance"],
  191. "debit": account["debit"],
  192. "credit": account["credit"],
  193. "final_balance": account["ending_balance"],
  194. }
  195. return lines
  196. def _get_group_lines(self, group_id, trial_balance):
  197. lines = False
  198. for group in trial_balance:
  199. if group["id"] == group_id and group["type"] == "group_type":
  200. lines = {
  201. "initial_balance": group["initial_balance"],
  202. "debit": group["debit"],
  203. "credit": group["credit"],
  204. "final_balance": group["ending_balance"],
  205. }
  206. return lines
  207. def check_partner_in_report(self, account_id, partner_id, total_amount):
  208. partner_in_report = False
  209. if account_id in total_amount.keys():
  210. if partner_id in total_amount[account_id]:
  211. partner_in_report = True
  212. return partner_in_report
  213. def _get_partner_lines(self, account_id, partner_id, total_amount):
  214. acc_id = account_id
  215. prt_id = partner_id
  216. lines = {
  217. "initial_balance": total_amount[acc_id][prt_id]["initial_balance"],
  218. "debit": total_amount[acc_id][prt_id]["debit"],
  219. "credit": total_amount[acc_id][prt_id]["credit"],
  220. "final_balance": total_amount[acc_id][prt_id]["ending_balance"],
  221. }
  222. return lines
  223. def _sum_all_accounts(self, trial_balance, feature):
  224. total = 0.0
  225. for account in trial_balance:
  226. if account["type"] == "account_type":
  227. for key in account.keys():
  228. if key == feature:
  229. total += account[key]
  230. return total
  231. def test_00_account_group(self):
  232. self.assertTrue(self.account100 in self.group1.compute_account_ids)
  233. self.assertTrue(self.account200 in self.group2.compute_account_ids)
  234. def test_01_account_balance_computed(self):
  235. # Change code of the P&L for not being automatically included
  236. # in group 1 balances
  237. earning_accs = self.env["account.account"].search(
  238. [
  239. (
  240. "user_type_id",
  241. "=",
  242. self.env.ref("account.data_unaffected_earnings").id,
  243. ),
  244. ("company_id", "=", self.env.user.company_id.id),
  245. ]
  246. )
  247. for acc in earning_accs:
  248. acc.code = "999" + acc.code
  249. # Generate the general ledger line
  250. res_data = self._get_report_lines()
  251. trial_balance = res_data["trial_balance"]
  252. check_receivable_account = self.check_account_in_report(
  253. self.account100.id, trial_balance
  254. )
  255. self.assertFalse(check_receivable_account)
  256. check_income_account = self.check_account_in_report(
  257. self.account200.id, trial_balance
  258. )
  259. self.assertFalse(check_income_account)
  260. self.assertTrue(
  261. self.check_account_in_report(self.unaffected_account.id, trial_balance)
  262. )
  263. # Add a move at the previous day of the first day of fiscal year
  264. # to check the initial balance
  265. self._add_move(
  266. date=self.previous_fy_date_end,
  267. receivable_debit=1000,
  268. receivable_credit=0,
  269. income_debit=0,
  270. income_credit=1000,
  271. )
  272. # Re Generate the trial balance line
  273. res_data = self._get_report_lines()
  274. trial_balance = res_data["trial_balance"]
  275. check_receivable_account = self.check_account_in_report(
  276. self.account100.id, trial_balance
  277. )
  278. self.assertTrue(check_receivable_account)
  279. check_income_account = self.check_account_in_report(
  280. self.account200.id, trial_balance
  281. )
  282. self.assertFalse(check_income_account)
  283. # Check the initial and final balance
  284. account_receivable_lines = self._get_account_lines(
  285. self.account100.id, trial_balance
  286. )
  287. group1_lines = self._get_group_lines(self.group1.id, trial_balance)
  288. self.assertEqual(account_receivable_lines["initial_balance"], 1000)
  289. self.assertEqual(account_receivable_lines["debit"], 0)
  290. self.assertEqual(account_receivable_lines["credit"], 0)
  291. self.assertEqual(account_receivable_lines["final_balance"], 1000)
  292. self.assertEqual(group1_lines["initial_balance"], 1000)
  293. self.assertEqual(group1_lines["debit"], 0)
  294. self.assertEqual(group1_lines["credit"], 0)
  295. self.assertEqual(group1_lines["final_balance"], 1000)
  296. # Add reversed move of the initial move the first day of fiscal year
  297. # to check the first day of fiscal year is not used
  298. # to compute the initial balance
  299. self._add_move(
  300. date=self.fy_date_start,
  301. receivable_debit=0,
  302. receivable_credit=1000,
  303. income_debit=1000,
  304. income_credit=0,
  305. )
  306. # Re Generate the trial balance line
  307. res_data = self._get_report_lines()
  308. trial_balance = res_data["trial_balance"]
  309. check_receivable_account = self.check_account_in_report(
  310. self.account100.id, trial_balance
  311. )
  312. self.assertTrue(check_receivable_account)
  313. check_income_account = self.check_account_in_report(
  314. self.account200.id, trial_balance
  315. )
  316. self.assertTrue(check_income_account)
  317. # Re Generate the trial balance line with an account filter
  318. res_data = self._get_report_lines(
  319. account_ids=(self.account100 + self.account200).ids
  320. )
  321. trial_balance = res_data["trial_balance"]
  322. self.assertTrue(self.check_account_in_report(self.account100.id, trial_balance))
  323. self.assertTrue(self.check_account_in_report(self.account200.id, trial_balance))
  324. # Unaffected account should not be present
  325. self.assertFalse(
  326. self.check_account_in_report(self.unaffected_account.id, trial_balance)
  327. )
  328. # Check the initial and final balance
  329. account_receivable_lines = self._get_account_lines(
  330. self.account100.id, trial_balance
  331. )
  332. account_income_lines = self._get_account_lines(
  333. self.account200.id, trial_balance
  334. )
  335. group1_lines = self._get_group_lines(self.group1.id, trial_balance)
  336. group2_lines = self._get_group_lines(self.group2.id, trial_balance)
  337. self.assertEqual(account_receivable_lines["initial_balance"], 1000)
  338. self.assertEqual(account_receivable_lines["debit"], 0)
  339. self.assertEqual(account_receivable_lines["credit"], 1000)
  340. self.assertEqual(account_receivable_lines["final_balance"], 0)
  341. self.assertEqual(account_income_lines["initial_balance"], 0)
  342. self.assertEqual(account_income_lines["debit"], 1000)
  343. self.assertEqual(account_income_lines["credit"], 0)
  344. self.assertEqual(account_income_lines["final_balance"], 1000)
  345. self.assertEqual(group1_lines["initial_balance"], 1000)
  346. self.assertEqual(group1_lines["debit"], 0)
  347. self.assertEqual(group1_lines["credit"], 1000)
  348. self.assertEqual(group1_lines["final_balance"], 0)
  349. self.assertEqual(group2_lines["initial_balance"], 0)
  350. self.assertEqual(group2_lines["debit"], 1000)
  351. self.assertEqual(group2_lines["credit"], 0)
  352. self.assertEqual(group2_lines["final_balance"], 1000)
  353. # Add another move at the end day of fiscal year
  354. # to check that it correctly used on report
  355. self._add_move(
  356. date=self.fy_date_end,
  357. receivable_debit=0,
  358. receivable_credit=1000,
  359. income_debit=1000,
  360. income_credit=0,
  361. )
  362. # Re Generate the trial balance line
  363. res_data = self._get_report_lines()
  364. trial_balance = res_data["trial_balance"]
  365. check_receivable_account = self.check_account_in_report(
  366. self.account100.id, trial_balance
  367. )
  368. self.assertTrue(check_receivable_account)
  369. check_income_account = self.check_account_in_report(
  370. self.account200.id, trial_balance
  371. )
  372. self.assertTrue(check_income_account)
  373. # Check the initial and final balance
  374. account_receivable_lines = self._get_account_lines(
  375. self.account100.id, trial_balance
  376. )
  377. account_income_lines = self._get_account_lines(
  378. self.account200.id, trial_balance
  379. )
  380. group1_lines = self._get_group_lines(self.group1.id, trial_balance)
  381. group2_lines = self._get_group_lines(self.group2.id, trial_balance)
  382. self.assertEqual(account_receivable_lines["initial_balance"], 1000)
  383. self.assertEqual(account_receivable_lines["debit"], 0)
  384. self.assertEqual(account_receivable_lines["credit"], 2000)
  385. self.assertEqual(account_receivable_lines["final_balance"], -1000)
  386. self.assertEqual(account_income_lines["initial_balance"], 0)
  387. self.assertEqual(account_income_lines["debit"], 2000)
  388. self.assertEqual(account_income_lines["credit"], 0)
  389. self.assertEqual(account_income_lines["final_balance"], 2000)
  390. self.assertEqual(group1_lines["initial_balance"], 1000)
  391. self.assertEqual(group1_lines["debit"], 0)
  392. self.assertEqual(group1_lines["credit"], 2000)
  393. self.assertEqual(group1_lines["final_balance"], -1000)
  394. self.assertEqual(group2_lines["initial_balance"], 0)
  395. self.assertEqual(group2_lines["debit"], 2000)
  396. self.assertEqual(group2_lines["credit"], 0)
  397. self.assertEqual(group2_lines["final_balance"], 2000)
  398. def test_02_account_balance_hierarchy(self):
  399. # Generate the general ledger line
  400. res_data = self._get_report_lines(hierarchy_on="relation")
  401. trial_balance = res_data["trial_balance"]
  402. check_receivable_account = self.check_account_in_report(
  403. self.account100.id, trial_balance
  404. )
  405. self.assertFalse(check_receivable_account)
  406. check_income_account = self.check_account_in_report(
  407. self.account200.id, trial_balance
  408. )
  409. self.assertFalse(check_income_account)
  410. # Add a move at the previous day of the first day of fiscal year
  411. # to check the initial balance
  412. self._add_move(
  413. date=self.previous_fy_date_end,
  414. receivable_debit=1000,
  415. receivable_credit=0,
  416. income_debit=0,
  417. income_credit=1000,
  418. )
  419. # Re Generate the trial balance line
  420. res_data = self._get_report_lines(hierarchy_on="relation")
  421. trial_balance = res_data["trial_balance"]
  422. check_receivable_account = self.check_account_in_report(
  423. self.account100.id, trial_balance
  424. )
  425. self.assertTrue(check_receivable_account)
  426. check_income_account = self.check_account_in_report(
  427. self.account200.id, trial_balance
  428. )
  429. self.assertFalse(check_income_account)
  430. # Check the initial and final balance
  431. account_receivable_lines = self._get_account_lines(
  432. self.account100.id, trial_balance
  433. )
  434. group1_lines = self._get_group_lines(self.group1.id, trial_balance)
  435. self.assertEqual(account_receivable_lines["initial_balance"], 1000)
  436. self.assertEqual(account_receivable_lines["debit"], 0)
  437. self.assertEqual(account_receivable_lines["credit"], 0)
  438. self.assertEqual(account_receivable_lines["final_balance"], 1000)
  439. self.assertEqual(group1_lines["initial_balance"], 1000)
  440. self.assertEqual(group1_lines["debit"], 0)
  441. self.assertEqual(group1_lines["credit"], 0)
  442. self.assertEqual(group1_lines["final_balance"], 1000)
  443. # Add reversale move of the initial move the first day of fiscal year
  444. # to check the first day of fiscal year is not used
  445. # to compute the initial balance
  446. self._add_move(
  447. date=self.fy_date_start,
  448. receivable_debit=0,
  449. receivable_credit=1000,
  450. income_debit=1000,
  451. income_credit=0,
  452. )
  453. # Re Generate the trial balance line
  454. res_data = self._get_report_lines(hierarchy_on="relation")
  455. trial_balance = res_data["trial_balance"]
  456. check_receivable_account = self.check_account_in_report(
  457. self.account100.id, trial_balance
  458. )
  459. self.assertTrue(check_receivable_account)
  460. check_income_account = self.check_account_in_report(
  461. self.account200.id, trial_balance
  462. )
  463. self.assertTrue(check_income_account)
  464. # Check the initial and final balance
  465. account_receivable_lines = self._get_account_lines(
  466. self.account100.id, trial_balance
  467. )
  468. account_income_lines = self._get_account_lines(
  469. self.account200.id, trial_balance
  470. )
  471. group1_lines = self._get_group_lines(self.group1.id, trial_balance)
  472. group2_lines = self._get_group_lines(self.group2.id, trial_balance)
  473. self.assertEqual(account_receivable_lines["initial_balance"], 1000)
  474. self.assertEqual(account_receivable_lines["debit"], 0)
  475. self.assertEqual(account_receivable_lines["credit"], 1000)
  476. self.assertEqual(account_receivable_lines["final_balance"], 0)
  477. self.assertEqual(account_income_lines["initial_balance"], 0)
  478. self.assertEqual(account_income_lines["debit"], 1000)
  479. self.assertEqual(account_income_lines["credit"], 0)
  480. self.assertEqual(account_income_lines["final_balance"], 1000)
  481. self.assertEqual(group1_lines["initial_balance"], 1000)
  482. self.assertEqual(group1_lines["debit"], 0)
  483. self.assertEqual(group1_lines["credit"], 1000)
  484. self.assertEqual(group1_lines["final_balance"], 0)
  485. self.assertEqual(group2_lines["initial_balance"], 0)
  486. self.assertEqual(group2_lines["debit"], 2000)
  487. self.assertEqual(group2_lines["credit"], 0)
  488. self.assertEqual(group2_lines["final_balance"], 2000)
  489. # Add another move at the end day of fiscal year
  490. # to check that it correctly used on report
  491. self._add_move(
  492. date=self.fy_date_end,
  493. receivable_debit=0,
  494. receivable_credit=1000,
  495. income_debit=1000,
  496. income_credit=0,
  497. )
  498. # Re Generate the trial balance line
  499. res_data = self._get_report_lines(hierarchy_on="relation")
  500. trial_balance = res_data["trial_balance"]
  501. check_receivable_account = self.check_account_in_report(
  502. self.account100.id, trial_balance
  503. )
  504. self.assertTrue(check_receivable_account)
  505. check_income_account = self.check_account_in_report(
  506. self.account200.id, trial_balance
  507. )
  508. self.assertTrue(check_income_account)
  509. # Check the initial and final balance
  510. account_receivable_lines = self._get_account_lines(
  511. self.account100.id, trial_balance
  512. )
  513. account_income_lines = self._get_account_lines(
  514. self.account200.id, trial_balance
  515. )
  516. group1_lines = self._get_group_lines(self.group1.id, trial_balance)
  517. group2_lines = self._get_group_lines(self.group2.id, trial_balance)
  518. self.assertEqual(account_receivable_lines["initial_balance"], 1000)
  519. self.assertEqual(account_receivable_lines["debit"], 0)
  520. self.assertEqual(account_receivable_lines["credit"], 2000)
  521. self.assertEqual(account_receivable_lines["final_balance"], -1000)
  522. self.assertEqual(account_income_lines["initial_balance"], 0)
  523. self.assertEqual(account_income_lines["debit"], 2000)
  524. self.assertEqual(account_income_lines["credit"], 0)
  525. self.assertEqual(account_income_lines["final_balance"], 2000)
  526. self.assertEqual(group1_lines["initial_balance"], 1000)
  527. self.assertEqual(group1_lines["debit"], 0)
  528. self.assertEqual(group1_lines["credit"], 2000)
  529. self.assertEqual(group1_lines["final_balance"], -1000)
  530. self.assertEqual(group2_lines["initial_balance"], 0)
  531. self.assertEqual(group2_lines["debit"], 4000)
  532. self.assertEqual(group2_lines["credit"], 0)
  533. self.assertEqual(group2_lines["final_balance"], 4000)
  534. def test_03_partner_balance(self):
  535. # Generate the trial balance line
  536. res_data = self._get_report_lines(with_partners=True)
  537. total_amount = res_data["total_amount"]
  538. check_partner_receivable = self.check_partner_in_report(
  539. self.account100.id, self.partner.id, total_amount
  540. )
  541. self.assertFalse(check_partner_receivable)
  542. # Add a move at the previous day of the first day of fiscal year
  543. # to check the initial balance
  544. self._add_move(
  545. date=self.previous_fy_date_end,
  546. receivable_debit=1000,
  547. receivable_credit=0,
  548. income_debit=0,
  549. income_credit=1000,
  550. )
  551. # Re Generate the trial balance line
  552. res_data = self._get_report_lines(with_partners=True)
  553. total_amount = res_data["total_amount"]
  554. check_partner_receivable = self.check_partner_in_report(
  555. self.account100.id, self.partner.id, total_amount
  556. )
  557. self.assertTrue(check_partner_receivable)
  558. # Check the initial and final balance
  559. partner_lines = self._get_partner_lines(
  560. self.account100.id, self.partner.id, total_amount
  561. )
  562. self.assertEqual(partner_lines["initial_balance"], 1000)
  563. self.assertEqual(partner_lines["debit"], 0)
  564. self.assertEqual(partner_lines["credit"], 0)
  565. self.assertEqual(partner_lines["final_balance"], 1000)
  566. # Add reversale move of the initial move the first day of fiscal year
  567. # to check the first day of fiscal year is not used
  568. # to compute the initial balance
  569. self._add_move(
  570. date=self.fy_date_start,
  571. receivable_debit=0,
  572. receivable_credit=1000,
  573. income_debit=1000,
  574. income_credit=0,
  575. )
  576. # Re Generate the trial balance line
  577. res_data = self._get_report_lines(with_partners=True)
  578. total_amount = res_data["total_amount"]
  579. check_partner_receivable = self.check_partner_in_report(
  580. self.account100.id, self.partner.id, total_amount
  581. )
  582. self.assertTrue(check_partner_receivable)
  583. # Check the initial and final balance
  584. partner_lines = self._get_partner_lines(
  585. self.account100.id, self.partner.id, total_amount
  586. )
  587. self.assertEqual(partner_lines["initial_balance"], 1000)
  588. self.assertEqual(partner_lines["debit"], 0)
  589. self.assertEqual(partner_lines["credit"], 1000)
  590. self.assertEqual(partner_lines["final_balance"], 0)
  591. # Add another move at the end day of fiscal year
  592. # to check that it correctly used on report
  593. self._add_move(
  594. date=self.fy_date_end,
  595. receivable_debit=0,
  596. receivable_credit=1000,
  597. income_debit=1000,
  598. income_credit=0,
  599. )
  600. # Re Generate the trial balance line
  601. res_data = self._get_report_lines(with_partners=True)
  602. total_amount = res_data["total_amount"]
  603. check_partner_receivable = self.check_partner_in_report(
  604. self.account100.id, self.partner.id, total_amount
  605. )
  606. self.assertTrue(check_partner_receivable)
  607. # Check the initial and final balance
  608. partner_lines = self._get_partner_lines(
  609. self.account100.id, self.partner.id, total_amount
  610. )
  611. self.assertEqual(partner_lines["initial_balance"], 1000)
  612. self.assertEqual(partner_lines["debit"], 0)
  613. self.assertEqual(partner_lines["credit"], 2000)
  614. self.assertEqual(partner_lines["final_balance"], -1000)
  615. def test_04_undistributed_pl(self):
  616. # Add a P&L Move in the previous FY
  617. journal = self.env["account.journal"].search(
  618. [("company_id", "=", self.env.user.company_id.id)], limit=1
  619. )
  620. move_vals = {
  621. "journal_id": journal.id,
  622. "date": self.previous_fy_date_end,
  623. "line_ids": [
  624. (
  625. 0,
  626. 0,
  627. {"debit": 0.0, "credit": 1000.0, "account_id": self.account300.id},
  628. ),
  629. (
  630. 0,
  631. 0,
  632. {"debit": 1000.0, "credit": 0.0, "account_id": self.account100.id},
  633. ),
  634. ],
  635. }
  636. move = self.env["account.move"].create(move_vals)
  637. move.action_post()
  638. # Generate the trial balance line
  639. company = self.env.user.company_id
  640. trial_balance = self.env["trial.balance.report.wizard"].create(
  641. {
  642. "date_from": self.date_start,
  643. "date_to": self.date_end,
  644. "target_move": "posted",
  645. "hide_account_at_0": False,
  646. "hierarchy_on": "none",
  647. "company_id": company.id,
  648. "fy_start_date": self.fy_date_start,
  649. }
  650. )
  651. data = trial_balance._prepare_report_trial_balance()
  652. res_data = self.env[
  653. "report.account_financial_report.trial_balance"
  654. ]._get_report_values(trial_balance, data)
  655. trial_balance = res_data["trial_balance"]
  656. check_unaffected_account = self.check_account_in_report(
  657. self.unaffected_account.id, trial_balance
  658. )
  659. self.assertTrue(check_unaffected_account)
  660. unaffected_lines = self._get_account_lines(
  661. self.unaffected_account.id, trial_balance
  662. )
  663. self.assertEqual(unaffected_lines["initial_balance"], -1000)
  664. self.assertEqual(unaffected_lines["debit"], 0)
  665. self.assertEqual(unaffected_lines["credit"], 0)
  666. self.assertEqual(unaffected_lines["final_balance"], -1000)
  667. # Add a P&L Move to the current FY
  668. journal = self.env["account.journal"].search(
  669. [("company_id", "=", self.env.user.company_id.id)], limit=1
  670. )
  671. move_vals = {
  672. "journal_id": journal.id,
  673. "date": self.date_start,
  674. "line_ids": [
  675. (
  676. 0,
  677. 0,
  678. {"debit": 0.0, "credit": 1000.0, "account_id": self.account300.id},
  679. ),
  680. (
  681. 0,
  682. 0,
  683. {"debit": 1000.0, "credit": 0.0, "account_id": self.account100.id},
  684. ),
  685. ],
  686. }
  687. move = self.env["account.move"].create(move_vals)
  688. move.action_post()
  689. # Re Generate the trial balance line
  690. trial_balance = self.env["trial.balance.report.wizard"].create(
  691. {
  692. "date_from": self.date_start,
  693. "date_to": self.date_end,
  694. "target_move": "posted",
  695. "hide_account_at_0": False,
  696. "hierarchy_on": "none",
  697. "company_id": company.id,
  698. "fy_start_date": self.fy_date_start,
  699. }
  700. )
  701. data = trial_balance._prepare_report_trial_balance()
  702. res_data = self.env[
  703. "report.account_financial_report.trial_balance"
  704. ]._get_report_values(trial_balance, data)
  705. trial_balance = res_data["trial_balance"]
  706. # The unaffected earnings account is not affected by a journal entry
  707. # made to the P&L in the current fiscal year.
  708. check_unaffected_account = self.check_account_in_report(
  709. self.unaffected_account.id, trial_balance
  710. )
  711. self.assertTrue(check_unaffected_account)
  712. unaffected_lines = self._get_account_lines(
  713. self.unaffected_account.id, trial_balance
  714. )
  715. self.assertEqual(unaffected_lines["initial_balance"], -1000)
  716. self.assertEqual(unaffected_lines["debit"], 0)
  717. self.assertEqual(unaffected_lines["credit"], 0)
  718. self.assertEqual(unaffected_lines["final_balance"], -1000)
  719. # Add a Move including Unaffected Earnings to the current FY
  720. journal = self.env["account.journal"].search(
  721. [("company_id", "=", self.env.user.company_id.id)], limit=1
  722. )
  723. move_vals = {
  724. "journal_id": journal.id,
  725. "date": self.date_start,
  726. "line_ids": [
  727. (
  728. 0,
  729. 0,
  730. {"debit": 0.0, "credit": 1000.0, "account_id": self.account110.id},
  731. ),
  732. (
  733. 0,
  734. 0,
  735. {"debit": 1000.0, "credit": 0.0, "account_id": self.account100.id},
  736. ),
  737. ],
  738. }
  739. move = self.env["account.move"].create(move_vals)
  740. move.action_post()
  741. # Re Generate the trial balance line
  742. trial_balance = self.env["trial.balance.report.wizard"].create(
  743. {
  744. "date_from": self.date_start,
  745. "date_to": self.date_end,
  746. "target_move": "posted",
  747. "hide_account_at_0": False,
  748. "hierarchy_on": "none",
  749. "company_id": company.id,
  750. "fy_start_date": self.fy_date_start,
  751. }
  752. )
  753. data = trial_balance._prepare_report_trial_balance()
  754. res_data = self.env[
  755. "report.account_financial_report.trial_balance"
  756. ]._get_report_values(trial_balance, data)
  757. trial_balance = res_data["trial_balance"]
  758. # The unaffected earnings account affected by a journal entry
  759. # made to the unaffected earnings in the current fiscal year.
  760. check_unaffected_account = self.check_account_in_report(
  761. self.unaffected_account.id, trial_balance
  762. )
  763. self.assertTrue(check_unaffected_account)
  764. unaffected_lines = self._get_account_lines(
  765. self.unaffected_account.id, trial_balance
  766. )
  767. self.assertEqual(unaffected_lines["initial_balance"], -1000)
  768. self.assertEqual(unaffected_lines["debit"], 0)
  769. self.assertEqual(unaffected_lines["credit"], 1000)
  770. self.assertEqual(unaffected_lines["final_balance"], -2000)
  771. # The totals for the Trial Balance are zero
  772. total_initial_balance = self._sum_all_accounts(trial_balance, "initial_balance")
  773. total_final_balance = self._sum_all_accounts(trial_balance, "ending_balance")
  774. total_debit = self._sum_all_accounts(trial_balance, "debit")
  775. total_credit = self._sum_all_accounts(trial_balance, "credit")
  776. self.assertEqual(total_initial_balance, 0)
  777. self.assertEqual(total_final_balance, 0)
  778. self.assertEqual(total_debit, total_credit)