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