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.

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