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.

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