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.

643 lines
26 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. {'only_posted_moves': True, 'hide_account_at_0': True,
  38. 'hierarchy_on': 'computed'},
  39. {'only_posted_moves': True, 'hide_account_at_0': True,
  40. 'hierarchy_on': 'relation'},
  41. {'only_posted_moves': True, 'hide_account_at_0': True},
  42. {'only_posted_moves': True, 'show_partner_details': True},
  43. {'hide_account_at_0': True, 'show_partner_details': True},
  44. {
  45. 'only_posted_moves': True,
  46. 'hide_account_at_0': True,
  47. 'show_partner_details': True
  48. },
  49. ]
  50. def _partner_test_is_possible(self, filters):
  51. return 'show_partner_details' in filters
  52. class TestTrialBalanceReport(common.TransactionCase):
  53. def setUp(self):
  54. super(TestTrialBalanceReport, self).setUp()
  55. group_obj = self.env['account.group']
  56. acc_obj = self.env['account.account']
  57. self.group1 = group_obj.create(
  58. {'code_prefix': '1',
  59. 'name': 'Group 1'})
  60. self.group11 = group_obj.create(
  61. {'code_prefix': '11',
  62. 'name': 'Group 11',
  63. 'parent_id': self.group1.id})
  64. self.group2 = group_obj.create(
  65. {'code_prefix': '2',
  66. 'name': 'Group 2'})
  67. self.account100 = acc_obj.create(
  68. {'code': '100',
  69. 'name': 'Account 100',
  70. 'group_id': self.group1.id,
  71. 'user_type_id': self.env.ref(
  72. 'account.data_account_type_receivable').id,
  73. 'reconcile': True})
  74. self.account110 = self.env['account.account'].search([
  75. (
  76. 'user_type_id',
  77. '=',
  78. self.env.ref('account.data_unaffected_earnings').id
  79. )], limit=1)
  80. self.account200 = acc_obj.create(
  81. {'code': '200',
  82. 'name': 'Account 200',
  83. 'group_id': self.group2.id,
  84. 'user_type_id': self.env.ref(
  85. 'account.data_account_type_other_income').id})
  86. self.account300 = acc_obj.create(
  87. {'code': '300',
  88. 'name': 'Account 300',
  89. 'user_type_id': self.env.ref(
  90. 'account.data_account_type_other_income').id})
  91. self.account301 = acc_obj.create(
  92. {'code': '301',
  93. 'name': 'Account 301',
  94. 'group_id': self.group2.id,
  95. 'user_type_id': self.env.ref(
  96. 'account.data_account_type_other_income').id})
  97. self.previous_fy_date_start = '2015-01-01'
  98. self.previous_fy_date_end = '2015-12-31'
  99. self.fy_date_start = '2016-01-01'
  100. self.fy_date_end = '2016-12-31'
  101. self.date_start = '2016-01-01'
  102. self.date_end = '2016-12-31'
  103. def _add_move(
  104. self,
  105. date,
  106. receivable_debit,
  107. receivable_credit,
  108. income_debit,
  109. income_credit,
  110. unaffected_debit=0,
  111. unaffected_credit=0
  112. ):
  113. move_name = 'expense accrual'
  114. journal = self.env['account.journal'].search([], limit=1)
  115. partner = self.env.ref('base.res_partner_12')
  116. move_vals = {
  117. 'journal_id': journal.id,
  118. 'name': move_name,
  119. 'date': date,
  120. 'line_ids': [
  121. (0, 0, {
  122. 'name': move_name,
  123. 'debit': receivable_debit,
  124. 'credit': receivable_credit,
  125. 'partner_id': partner.id,
  126. 'account_id': self.account100.id}),
  127. (0, 0, {
  128. 'name': move_name,
  129. 'debit': income_debit,
  130. 'credit': income_credit,
  131. 'partner_id': partner.id,
  132. 'account_id': self.account200.id}),
  133. (0, 0, {
  134. 'name': move_name,
  135. 'debit': unaffected_debit,
  136. 'credit': unaffected_credit,
  137. 'partner_id': partner.id,
  138. 'account_id': self.account110.id}),
  139. (0, 0, {
  140. 'name': move_name,
  141. 'debit': receivable_debit,
  142. 'credit': receivable_credit,
  143. 'partner_id': partner.id,
  144. 'account_id': self.account300.id}),
  145. (0, 0, {
  146. 'name': move_name,
  147. 'debit': receivable_credit,
  148. 'credit': receivable_debit,
  149. 'partner_id': partner.id,
  150. 'account_id': self.account301.id})
  151. ]}
  152. move = self.env['account.move'].create(move_vals)
  153. move.post()
  154. def _get_report_lines(self, with_partners=False, hierarchy_on='computed'):
  155. company = self.env.ref('base.main_company')
  156. trial_balance = self.env['report_trial_balance'].create({
  157. 'date_from': self.date_start,
  158. 'date_to': self.date_end,
  159. 'only_posted_moves': True,
  160. 'hide_account_at_0': False,
  161. 'hierarchy_on': hierarchy_on,
  162. 'company_id': company.id,
  163. 'fy_start_date': self.fy_date_start,
  164. 'show_partner_details': with_partners,
  165. })
  166. trial_balance.compute_data_for_report()
  167. lines = {}
  168. report_account_model = self.env['report_trial_balance_account']
  169. lines['receivable'] = report_account_model.search([
  170. ('report_id', '=', trial_balance.id),
  171. ('account_id', '=', self.account100.id),
  172. ])
  173. lines['income'] = report_account_model.search([
  174. ('report_id', '=', trial_balance.id),
  175. ('account_id', '=', self.account200.id),
  176. ])
  177. lines['unaffected'] = report_account_model.search([
  178. ('report_id', '=', trial_balance.id),
  179. ('account_id', '=', self.account110.id),
  180. ])
  181. lines['group1'] = report_account_model.search([
  182. ('report_id', '=', trial_balance.id),
  183. ('account_group_id', '=', self.group1.id),
  184. ])
  185. lines['group2'] = report_account_model.search([
  186. ('report_id', '=', trial_balance.id),
  187. ('account_group_id', '=', self.group2.id),
  188. ])
  189. if with_partners:
  190. report_partner_model = self.env[
  191. 'report_trial_balance_partner'
  192. ]
  193. lines['partner_receivable'] = report_partner_model.search([
  194. ('report_account_id', '=', lines['receivable'].id),
  195. ('partner_id', '=', self.env.ref('base.res_partner_12').id),
  196. ])
  197. return lines
  198. def test_00_account_group(self):
  199. self.assertGreaterEqual(len(self.group1.compute_account_ids), 19)
  200. self.assertGreaterEqual(len(self.group2.compute_account_ids), 9)
  201. def test_01_account_balance_computed(self):
  202. # Make sure there's no account of type "Current Year Earnings" in the
  203. # groups - We change the code
  204. earning_accs = self.env['account.account'].search([
  205. ('user_type_id', '=',
  206. self.env.ref('account.data_unaffected_earnings').id)
  207. ])
  208. for acc in earning_accs:
  209. if acc.code.startswith('1') or acc.code.startswith('2'):
  210. acc.code = '999' + acc.code
  211. # Generate the general ledger line
  212. lines = self._get_report_lines()
  213. self.assertEqual(len(lines['receivable']), 1)
  214. self.assertEqual(len(lines['income']), 1)
  215. # Add a move at the previous day of the first day of fiscal year
  216. # to check the initial balance
  217. self._add_move(
  218. date=self.previous_fy_date_end,
  219. receivable_debit=1000,
  220. receivable_credit=0,
  221. income_debit=0,
  222. income_credit=1000
  223. )
  224. # Re Generate the trial balance line
  225. lines = self._get_report_lines()
  226. self.assertEqual(len(lines['receivable']), 1)
  227. self.assertEqual(len(lines['income']), 1)
  228. # Check the initial and final balance
  229. self.assertEqual(lines['receivable'].initial_balance, 1000)
  230. self.assertEqual(lines['receivable'].debit, 0)
  231. self.assertEqual(lines['receivable'].credit, 0)
  232. self.assertEqual(lines['receivable'].final_balance, 1000)
  233. self.assertEqual(lines['group1'].initial_balance, 1000)
  234. self.assertEqual(lines['group1'].debit, 0)
  235. self.assertEqual(lines['group1'].credit, 0)
  236. self.assertEqual(lines['group1'].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. lines = self._get_report_lines()
  249. self.assertEqual(len(lines['receivable']), 1)
  250. self.assertEqual(len(lines['income']), 1)
  251. # Check the initial and final balance
  252. self.assertEqual(lines['receivable'].initial_balance, 1000)
  253. self.assertEqual(lines['receivable'].debit, 0)
  254. self.assertEqual(lines['receivable'].credit, 1000)
  255. self.assertEqual(lines['receivable'].final_balance, 0)
  256. self.assertEqual(lines['income'].initial_balance, 0)
  257. self.assertEqual(lines['income'].debit, 1000)
  258. self.assertEqual(lines['income'].credit, 0)
  259. self.assertEqual(lines['income'].final_balance, 1000)
  260. self.assertEqual(lines['group1'].initial_balance, 1000)
  261. self.assertEqual(lines['group1'].debit, 0)
  262. self.assertEqual(lines['group1'].credit, 1000)
  263. self.assertEqual(lines['group1'].final_balance, 0)
  264. self.assertEqual(lines['group2'].initial_balance, 0)
  265. self.assertEqual(lines['group2'].debit, 1000)
  266. self.assertEqual(lines['group2'].credit, 0)
  267. self.assertEqual(lines['group2'].final_balance, 1000)
  268. # Add another move at the end day of fiscal year
  269. # to check that it correctly used on report
  270. self._add_move(
  271. date=self.fy_date_end,
  272. receivable_debit=0,
  273. receivable_credit=1000,
  274. income_debit=1000,
  275. income_credit=0
  276. )
  277. # Re Generate the trial balance line
  278. lines = self._get_report_lines()
  279. self.assertEqual(len(lines['receivable']), 1)
  280. self.assertEqual(len(lines['income']), 1)
  281. # Check the initial and final balance
  282. self.assertEqual(lines['receivable'].initial_balance, 1000)
  283. self.assertEqual(lines['receivable'].debit, 0)
  284. self.assertEqual(lines['receivable'].credit, 2000)
  285. self.assertEqual(lines['receivable'].final_balance, -1000)
  286. self.assertEqual(lines['income'].initial_balance, 0)
  287. self.assertEqual(lines['income'].debit, 2000)
  288. self.assertEqual(lines['income'].credit, 0)
  289. self.assertEqual(lines['income'].final_balance, 2000)
  290. self.assertEqual(lines['group1'].initial_balance, 1000)
  291. self.assertEqual(lines['group1'].debit, 0)
  292. self.assertEqual(lines['group1'].credit, 2000)
  293. self.assertEqual(lines['group1'].final_balance, -1000)
  294. self.assertEqual(lines['group2'].initial_balance, 0)
  295. self.assertEqual(lines['group2'].debit, 2000)
  296. self.assertEqual(lines['group2'].credit, 0)
  297. self.assertEqual(lines['group2'].final_balance, 2000)
  298. self.assertEqual(len(lines['group2'].compute_account_ids), 9)
  299. def test_02_account_balance_hierarchy(self):
  300. # Generate the general ledger line
  301. lines = self._get_report_lines(hierarchy_on='relation')
  302. self.assertEqual(len(lines['receivable']), 1)
  303. self.assertEqual(len(lines['income']), 1)
  304. # Add a move at the previous day of the first day of fiscal year
  305. # to check the initial balance
  306. self._add_move(
  307. date=self.previous_fy_date_end,
  308. receivable_debit=1000,
  309. receivable_credit=0,
  310. income_debit=0,
  311. income_credit=1000
  312. )
  313. # Re Generate the trial balance line
  314. lines = self._get_report_lines(hierarchy_on='relation')
  315. self.assertEqual(len(lines['receivable']), 1)
  316. self.assertEqual(len(lines['income']), 1)
  317. # Check the initial and final balance
  318. self.assertEqual(lines['receivable'].initial_balance, 1000)
  319. self.assertEqual(lines['receivable'].debit, 0)
  320. self.assertEqual(lines['receivable'].credit, 0)
  321. self.assertEqual(lines['receivable'].final_balance, 1000)
  322. self.assertEqual(lines['group1'].initial_balance, 1000)
  323. self.assertEqual(lines['group1'].debit, 0)
  324. self.assertEqual(lines['group1'].credit, 0)
  325. self.assertEqual(lines['group1'].final_balance, 1000)
  326. # Add reversale move of the initial move the first day of fiscal year
  327. # to check the first day of fiscal year is not used
  328. # to compute the initial balance
  329. self._add_move(
  330. date=self.fy_date_start,
  331. receivable_debit=0,
  332. receivable_credit=1000,
  333. income_debit=1000,
  334. income_credit=0
  335. )
  336. # Re Generate the trial balance line
  337. lines = self._get_report_lines(hierarchy_on='relation')
  338. self.assertEqual(len(lines['receivable']), 1)
  339. self.assertEqual(len(lines['income']), 1)
  340. # Check the initial and final balance
  341. self.assertEqual(lines['receivable'].initial_balance, 1000)
  342. self.assertEqual(lines['receivable'].debit, 0)
  343. self.assertEqual(lines['receivable'].credit, 1000)
  344. self.assertEqual(lines['receivable'].final_balance, 0)
  345. self.assertEqual(lines['income'].initial_balance, 0)
  346. self.assertEqual(lines['income'].debit, 1000)
  347. self.assertEqual(lines['income'].credit, 0)
  348. self.assertEqual(lines['income'].final_balance, 1000)
  349. self.assertEqual(lines['group1'].initial_balance, 1000)
  350. self.assertEqual(lines['group1'].debit, 0)
  351. self.assertEqual(lines['group1'].credit, 1000)
  352. self.assertEqual(lines['group1'].final_balance, 0)
  353. self.assertEqual(lines['group2'].initial_balance, 0)
  354. self.assertEqual(lines['group2'].debit, 2000)
  355. self.assertEqual(lines['group2'].credit, 0)
  356. self.assertEqual(lines['group2'].final_balance, 2000)
  357. self.assertEqual(len(lines['group2'].compute_account_ids), 2)
  358. # Add another move at the end day of fiscal year
  359. # to check that it correctly used on report
  360. self._add_move(
  361. date=self.fy_date_end,
  362. receivable_debit=0,
  363. receivable_credit=1000,
  364. income_debit=1000,
  365. income_credit=0
  366. )
  367. # Re Generate the trial balance line
  368. lines = self._get_report_lines(hierarchy_on='relation')
  369. self.assertEqual(len(lines['receivable']), 1)
  370. self.assertEqual(len(lines['income']), 1)
  371. # Check the initial and final balance
  372. self.assertEqual(lines['receivable'].initial_balance, 1000)
  373. self.assertEqual(lines['receivable'].debit, 0)
  374. self.assertEqual(lines['receivable'].credit, 2000)
  375. self.assertEqual(lines['receivable'].final_balance, -1000)
  376. self.assertEqual(lines['income'].initial_balance, 0)
  377. self.assertEqual(lines['income'].debit, 2000)
  378. self.assertEqual(lines['income'].credit, 0)
  379. self.assertEqual(lines['income'].final_balance, 2000)
  380. self.assertEqual(lines['group1'].initial_balance, 1000)
  381. self.assertEqual(lines['group1'].debit, 0)
  382. self.assertEqual(lines['group1'].credit, 2000)
  383. self.assertEqual(lines['group1'].final_balance, -1000)
  384. self.assertEqual(lines['group2'].initial_balance, 0)
  385. self.assertEqual(lines['group2'].debit, 4000)
  386. self.assertEqual(lines['group2'].credit, 0)
  387. self.assertEqual(lines['group2'].final_balance, 4000)
  388. def test_03_partner_balance(self):
  389. # Generate the trial balance line
  390. lines = self._get_report_lines(with_partners=True)
  391. self.assertEqual(len(lines['partner_receivable']), 0)
  392. # Add a move at the previous day of the first day of fiscal year
  393. # to check the initial balance
  394. self._add_move(
  395. date=self.previous_fy_date_end,
  396. receivable_debit=1000,
  397. receivable_credit=0,
  398. income_debit=0,
  399. income_credit=1000
  400. )
  401. # Re Generate the trial balance line
  402. lines = self._get_report_lines(with_partners=True)
  403. self.assertEqual(len(lines['partner_receivable']), 1)
  404. # Check the initial and final balance
  405. self.assertEqual(lines['partner_receivable'].initial_balance, 1000)
  406. self.assertEqual(lines['partner_receivable'].debit, 0)
  407. self.assertEqual(lines['partner_receivable'].credit, 0)
  408. self.assertEqual(lines['partner_receivable'].final_balance, 1000)
  409. # Add reversale move of the initial move the first day of fiscal year
  410. # to check the first day of fiscal year is not used
  411. # to compute the initial balance
  412. self._add_move(
  413. date=self.fy_date_start,
  414. receivable_debit=0,
  415. receivable_credit=1000,
  416. income_debit=1000,
  417. income_credit=0
  418. )
  419. # Re Generate the trial balance line
  420. lines = self._get_report_lines(with_partners=True)
  421. self.assertEqual(len(lines['partner_receivable']), 1)
  422. # Check the initial and final balance
  423. self.assertEqual(lines['partner_receivable'].initial_balance, 1000)
  424. self.assertEqual(lines['partner_receivable'].debit, 0)
  425. self.assertEqual(lines['partner_receivable'].credit, 1000)
  426. self.assertEqual(lines['partner_receivable'].final_balance, 0)
  427. # Add another move at the end day of fiscal year
  428. # to check that it correctly used on report
  429. self._add_move(
  430. date=self.fy_date_end,
  431. receivable_debit=0,
  432. receivable_credit=1000,
  433. income_debit=1000,
  434. income_credit=0
  435. )
  436. # Re Generate the trial balance line
  437. lines = self._get_report_lines(with_partners=True)
  438. self.assertEqual(len(lines['partner_receivable']), 1)
  439. # Check the initial and final balance
  440. self.assertEqual(lines['partner_receivable'].initial_balance, 1000)
  441. self.assertEqual(lines['partner_receivable'].debit, 0)
  442. self.assertEqual(lines['partner_receivable'].credit, 2000)
  443. self.assertEqual(lines['partner_receivable'].final_balance, -1000)
  444. def test_04_undistributed_pl(self):
  445. # Add a P&L Move in the previous FY
  446. move_name = 'current year pl move'
  447. journal = self.env['account.journal'].search([], limit=1)
  448. move_vals = {
  449. 'journal_id': journal.id,
  450. 'name': move_name,
  451. 'date': self.previous_fy_date_end,
  452. 'line_ids': [
  453. (0, 0, {
  454. 'name': move_name,
  455. 'debit': 0.0,
  456. 'credit': 1000.0,
  457. 'account_id': self.account300.id}),
  458. (0, 0, {
  459. 'name': move_name,
  460. 'debit': 1000.0,
  461. 'credit': 0.0,
  462. 'account_id': self.account100.id})
  463. ]}
  464. move = self.env['account.move'].create(move_vals)
  465. move.post()
  466. # Generate the trial balance line
  467. report_account_model = self.env['report_trial_balance_account']
  468. company = self.env.ref('base.main_company')
  469. trial_balance = self.env['report_trial_balance'].create({
  470. 'date_from': self.date_start,
  471. 'date_to': self.date_end,
  472. 'only_posted_moves': True,
  473. 'hide_account_at_0': False,
  474. 'hierarchy_on': 'none',
  475. 'company_id': company.id,
  476. 'fy_start_date': self.fy_date_start,
  477. })
  478. trial_balance.compute_data_for_report()
  479. unaffected_balance_lines = report_account_model.search([
  480. ('report_id', '=', trial_balance.id),
  481. ('account_id', '=', self.account110.id),
  482. ])
  483. self.assertEqual(len(unaffected_balance_lines), 1)
  484. self.assertEqual(unaffected_balance_lines[0].initial_balance, -1000)
  485. self.assertEqual(unaffected_balance_lines[0].debit, 0)
  486. self.assertEqual(unaffected_balance_lines[0].credit, 0)
  487. self.assertEqual(unaffected_balance_lines[0].final_balance, -1000)
  488. # Add a P&L Move to the current FY
  489. move_name = 'current year pl move'
  490. journal = self.env['account.journal'].search([], limit=1)
  491. move_vals = {
  492. 'journal_id': journal.id,
  493. 'name': move_name,
  494. 'date': self.date_start,
  495. 'line_ids': [
  496. (0, 0, {
  497. 'name': move_name,
  498. 'debit': 0.0,
  499. 'credit': 1000.0,
  500. 'account_id': self.account300.id}),
  501. (0, 0, {
  502. 'name': move_name,
  503. 'debit': 1000.0,
  504. 'credit': 0.0,
  505. 'account_id': self.account100.id})
  506. ]}
  507. move = self.env['account.move'].create(move_vals)
  508. move.post()
  509. # Re Generate the trial balance line
  510. trial_balance = self.env['report_trial_balance'].create({
  511. 'date_from': self.date_start,
  512. 'date_to': self.date_end,
  513. 'only_posted_moves': True,
  514. 'hide_account_at_0': False,
  515. 'hierarchy_on': 'none',
  516. 'company_id': company.id,
  517. 'fy_start_date': self.fy_date_start,
  518. })
  519. trial_balance.compute_data_for_report()
  520. unaffected_balance_lines = report_account_model.search([
  521. ('report_id', '=', trial_balance.id),
  522. ('account_id', '=', self.account110.id),
  523. ])
  524. # The unaffected earnings account is not affected by a journal entry
  525. # made to the P&L in the current fiscal year.
  526. self.assertEqual(len(unaffected_balance_lines), 1)
  527. self.assertEqual(unaffected_balance_lines[0].initial_balance, -1000)
  528. self.assertEqual(unaffected_balance_lines[0].debit, 0)
  529. self.assertEqual(unaffected_balance_lines[0].credit, 0)
  530. self.assertEqual(unaffected_balance_lines[0].final_balance, -1000)
  531. # Add a Move including Unaffected Earnings to the current FY
  532. move_name = 'current year unaffected earnings move'
  533. journal = self.env['account.journal'].search([], limit=1)
  534. move_vals = {
  535. 'journal_id': journal.id,
  536. 'name': move_name,
  537. 'date': self.date_start,
  538. 'line_ids': [
  539. (0, 0, {
  540. 'name': move_name,
  541. 'debit': 0.0,
  542. 'credit': 1000.0,
  543. 'account_id': self.account110.id}),
  544. (0, 0, {
  545. 'name': move_name,
  546. 'debit': 1000.0,
  547. 'credit': 0.0,
  548. 'account_id': self.account100.id})
  549. ]}
  550. move = self.env['account.move'].create(move_vals)
  551. move.post()
  552. # Re Generate the trial balance line
  553. trial_balance = self.env['report_trial_balance'].create({
  554. 'date_from': self.date_start,
  555. 'date_to': self.date_end,
  556. 'only_posted_moves': True,
  557. 'hide_account_at_0': False,
  558. 'hierarchy_on': 'none',
  559. 'company_id': company.id,
  560. 'fy_start_date': self.fy_date_start,
  561. })
  562. trial_balance.compute_data_for_report()
  563. # The unaffected earnings account affected by a journal entry
  564. # made to the unaffected earnings in the current fiscal year.
  565. unaffected_balance_lines = report_account_model.search([
  566. ('report_id', '=', trial_balance.id),
  567. ('account_id', '=', self.account110.id),
  568. ])
  569. self.assertEqual(len(unaffected_balance_lines), 1)
  570. self.assertEqual(unaffected_balance_lines[0].initial_balance, -1000)
  571. self.assertEqual(unaffected_balance_lines[0].debit, 0)
  572. self.assertEqual(unaffected_balance_lines[0].credit, 1000)
  573. self.assertEqual(unaffected_balance_lines[0].final_balance, -2000)
  574. # The totals for the Trial Balance are zero
  575. all_lines = report_account_model.search([
  576. ('report_id', '=', trial_balance.id),
  577. ])
  578. self.assertEqual(sum(all_lines.mapped('initial_balance')), 0)
  579. self.assertEqual(sum(all_lines.mapped('final_balance')), 0)
  580. self.assertEqual(sum(all_lines.mapped('debit')),
  581. sum(all_lines.mapped('credit')))