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.

744 lines
28 KiB

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