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.

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