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.

720 lines
28 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. import time
  6. from datetime import date
  7. from odoo import api, fields
  8. from odoo.tests import common
  9. class TestGeneralLedgerReport(common.TransactionCase):
  10. def setUp(self):
  11. super(TestGeneralLedgerReport, self).setUp()
  12. self.before_previous_fy_year = fields.Date.from_string("2014-05-05")
  13. self.previous_fy_date_start = fields.Date.from_string("2015-01-01")
  14. self.previous_fy_date_end = fields.Date.from_string("2015-12-31")
  15. self.fy_date_start = fields.Date.from_string("2016-01-01")
  16. self.fy_date_end = fields.Date.from_string("2016-12-31")
  17. self.receivable_account = self.env["account.account"].search(
  18. [("user_type_id.name", "=", "Receivable")], limit=1
  19. )
  20. self.income_account = self.env["account.account"].search(
  21. [("user_type_id.name", "=", "Income")], limit=1
  22. )
  23. self.unaffected_account = self.env["account.account"].search(
  24. [
  25. (
  26. "user_type_id",
  27. "=",
  28. self.env.ref("account.data_unaffected_earnings").id,
  29. )
  30. ],
  31. limit=1,
  32. )
  33. self.partner = self.env.ref("base.res_partner_12")
  34. def _add_move(
  35. self,
  36. date,
  37. receivable_debit,
  38. receivable_credit,
  39. income_debit,
  40. income_credit,
  41. unaffected_debit=0,
  42. unaffected_credit=0,
  43. ):
  44. journal = self.env["account.journal"].search([], limit=1)
  45. partner = self.env.ref("base.res_partner_12")
  46. move_vals = {
  47. "journal_id": journal.id,
  48. "date": date,
  49. "line_ids": [
  50. (
  51. 0,
  52. 0,
  53. {
  54. "debit": receivable_debit,
  55. "credit": receivable_credit,
  56. "account_id": self.receivable_account.id,
  57. "partner_id": partner.id,
  58. },
  59. ),
  60. (
  61. 0,
  62. 0,
  63. {
  64. "debit": income_debit,
  65. "credit": income_credit,
  66. "account_id": self.income_account.id,
  67. "partner_id": partner.id,
  68. },
  69. ),
  70. (
  71. 0,
  72. 0,
  73. {
  74. "debit": unaffected_debit,
  75. "credit": unaffected_credit,
  76. "account_id": self.unaffected_account.id,
  77. "partner_id": partner.id,
  78. },
  79. ),
  80. ],
  81. }
  82. move = self.env["account.move"].create(move_vals)
  83. move.post()
  84. def _get_report_lines(self, with_partners=False, account_ids=False):
  85. centralize = True
  86. if with_partners:
  87. centralize = False
  88. company = self.env.ref("base.main_company")
  89. general_ledger = self.env["general.ledger.report.wizard"].create(
  90. {
  91. "date_from": self.fy_date_start,
  92. "date_to": self.fy_date_end,
  93. "target_move": "posted",
  94. "hide_account_at_0": False,
  95. "company_id": company.id,
  96. "account_ids": account_ids,
  97. "fy_start_date": self.fy_date_start,
  98. "centralize": centralize,
  99. }
  100. )
  101. data = general_ledger._prepare_report_general_ledger()
  102. res_data = self.env[
  103. "report.account_financial_report.general_ledger"
  104. ]._get_report_values(general_ledger, data)
  105. return res_data
  106. @api.model
  107. def check_account_in_report(self, account_id, general_ledger):
  108. account_in_report = False
  109. for account in general_ledger:
  110. if account["id"] == account_id:
  111. account_in_report = True
  112. break
  113. return account_in_report
  114. @api.model
  115. def check_partner_in_report(self, account_id, partner_id, general_ledger):
  116. partner_in_report = False
  117. for account in general_ledger:
  118. if account["id"] == account_id and account["partners"]:
  119. for partner in account["list_partner"]:
  120. if partner["id"] == partner_id:
  121. partner_in_report = True
  122. return partner_in_report
  123. @api.model
  124. def _get_initial_balance(self, account_id, general_ledger):
  125. initial_balance = False
  126. for account in general_ledger:
  127. if account["id"] == account_id:
  128. initial_balance = account["init_bal"]
  129. return initial_balance
  130. @api.model
  131. def _get_partner_initial_balance(self, account_id, partner_id, general_ledger):
  132. initial_balance = False
  133. for account in general_ledger:
  134. if account["id"] == account_id and account["partners"]:
  135. for partner in account["list_partner"]:
  136. if partner["id"] == partner_id:
  137. initial_balance = partner["init_bal"]
  138. return initial_balance
  139. @api.model
  140. def _get_final_balance(self, account_id, general_ledger):
  141. final_balance = False
  142. for account in general_ledger:
  143. if account["id"] == account_id:
  144. final_balance = account["fin_bal"]
  145. return final_balance
  146. @api.model
  147. def _get_partner_final_balance(self, account_id, partner_id, general_ledger):
  148. final_balance = False
  149. for account in general_ledger:
  150. if account["id"] == account_id and account["partners"]:
  151. for partner in account["list_partner"]:
  152. if partner["id"] == partner_id:
  153. final_balance = partner["fin_bal"]
  154. return final_balance
  155. def test_01_account_balance(self):
  156. # Generate the general ledger line
  157. res_data = self._get_report_lines()
  158. general_ledger = res_data["general_ledger"]
  159. check_receivable_account = self.check_account_in_report(
  160. self.receivable_account.id, general_ledger
  161. )
  162. self.assertFalse(check_receivable_account)
  163. check_income_account = self.check_account_in_report(
  164. self.income_account.id, general_ledger
  165. )
  166. self.assertFalse(check_income_account)
  167. self.assertTrue(
  168. self.check_account_in_report(self.unaffected_account.id, general_ledger)
  169. )
  170. # Add a move at the previous day of the first day of fiscal year
  171. # to check the initial balance
  172. self._add_move(
  173. date=self.previous_fy_date_end,
  174. receivable_debit=1000,
  175. receivable_credit=0,
  176. income_debit=0,
  177. income_credit=1000,
  178. )
  179. # Re Generate the general ledger line
  180. res_data = self._get_report_lines()
  181. general_ledger = res_data["general_ledger"]
  182. check_receivable_account = self.check_account_in_report(
  183. self.receivable_account.id, general_ledger
  184. )
  185. self.assertTrue(check_receivable_account)
  186. check_income_account = self.check_account_in_report(
  187. self.income_account.id, general_ledger
  188. )
  189. self.assertFalse(check_income_account)
  190. # Check the initial and final balance
  191. receivable_init_balance = self._get_initial_balance(
  192. self.receivable_account.id, general_ledger
  193. )
  194. receivable_fin_balance = self._get_final_balance(
  195. self.receivable_account.id, general_ledger
  196. )
  197. self.assertEqual(receivable_init_balance["debit"], 1000)
  198. self.assertEqual(receivable_init_balance["credit"], 0)
  199. self.assertEqual(receivable_init_balance["balance"], 1000)
  200. self.assertEqual(receivable_fin_balance["debit"], 1000)
  201. self.assertEqual(receivable_fin_balance["credit"], 0)
  202. self.assertEqual(receivable_fin_balance["balance"], 1000)
  203. # Add reversale move of the initial move the first day of fiscal year
  204. # to check the first day of fiscal year is not used
  205. # to compute the initial balance
  206. self._add_move(
  207. date=self.fy_date_start,
  208. receivable_debit=0,
  209. receivable_credit=1000,
  210. income_debit=1000,
  211. income_credit=0,
  212. )
  213. # Re Generate the general ledger line
  214. res_data = self._get_report_lines()
  215. general_ledger = res_data["general_ledger"]
  216. check_receivable_account = self.check_account_in_report(
  217. self.receivable_account.id, general_ledger
  218. )
  219. self.assertTrue(check_receivable_account)
  220. check_income_account = self.check_account_in_report(
  221. self.income_account.id, general_ledger
  222. )
  223. self.assertTrue(check_income_account)
  224. # Check the initial and final balance
  225. receivable_init_balance = self._get_initial_balance(
  226. self.receivable_account.id, general_ledger
  227. )
  228. receivable_fin_balance = self._get_final_balance(
  229. self.receivable_account.id, general_ledger
  230. )
  231. income_init_balance = self._get_initial_balance(
  232. self.income_account.id, general_ledger
  233. )
  234. income_fin_balance = self._get_final_balance(
  235. self.income_account.id, general_ledger
  236. )
  237. self.assertEqual(receivable_init_balance["debit"], 1000)
  238. self.assertEqual(receivable_init_balance["credit"], 0)
  239. self.assertEqual(receivable_init_balance["balance"], 1000)
  240. self.assertEqual(receivable_fin_balance["debit"], 1000)
  241. self.assertEqual(receivable_fin_balance["credit"], 1000)
  242. self.assertEqual(receivable_fin_balance["balance"], 0)
  243. self.assertEqual(income_init_balance["debit"], 0)
  244. self.assertEqual(income_init_balance["credit"], 0)
  245. self.assertEqual(income_init_balance["balance"], 0)
  246. self.assertEqual(income_fin_balance["debit"], 1000)
  247. self.assertEqual(income_fin_balance["credit"], 0)
  248. self.assertEqual(income_fin_balance["balance"], 1000)
  249. # Re Generate the general ledger line
  250. res_data = self._get_report_lines(
  251. account_ids=(self.receivable_account + self.income_account).ids
  252. )
  253. general_ledger = res_data["general_ledger"]
  254. self.assertTrue(
  255. self.check_account_in_report(self.receivable_account.id, general_ledger)
  256. )
  257. self.assertTrue(
  258. self.check_account_in_report(self.income_account.id, general_ledger)
  259. )
  260. self.assertFalse(
  261. self.check_account_in_report(self.unaffected_account.id, general_ledger)
  262. )
  263. # Add another move at the end day of fiscal year
  264. # to check that it correctly used on report
  265. self._add_move(
  266. date=self.fy_date_end,
  267. receivable_debit=0,
  268. receivable_credit=1000,
  269. income_debit=1000,
  270. income_credit=0,
  271. )
  272. # Re Generate the general ledger line
  273. res_data = self._get_report_lines()
  274. general_ledger = res_data["general_ledger"]
  275. check_receivable_account = self.check_account_in_report(
  276. self.receivable_account.id, general_ledger
  277. )
  278. self.assertTrue(check_receivable_account)
  279. check_income_account = self.check_account_in_report(
  280. self.income_account.id, general_ledger
  281. )
  282. self.assertTrue(check_income_account)
  283. # Check the initial and final balance
  284. receivable_init_balance = self._get_initial_balance(
  285. self.receivable_account.id, general_ledger
  286. )
  287. receivable_fin_balance = self._get_final_balance(
  288. self.receivable_account.id, general_ledger
  289. )
  290. income_init_balance = self._get_initial_balance(
  291. self.income_account.id, general_ledger
  292. )
  293. income_fin_balance = self._get_final_balance(
  294. self.income_account.id, general_ledger
  295. )
  296. self.assertEqual(receivable_init_balance["debit"], 1000)
  297. self.assertEqual(receivable_init_balance["credit"], 0)
  298. self.assertEqual(receivable_init_balance["balance"], 1000)
  299. self.assertEqual(receivable_fin_balance["debit"], 1000)
  300. self.assertEqual(receivable_fin_balance["credit"], 2000)
  301. self.assertEqual(receivable_fin_balance["balance"], -1000)
  302. self.assertEqual(income_init_balance["debit"], 0)
  303. self.assertEqual(income_init_balance["credit"], 0)
  304. self.assertEqual(income_init_balance["balance"], 0)
  305. self.assertEqual(income_fin_balance["debit"], 2000)
  306. self.assertEqual(income_fin_balance["credit"], 0)
  307. self.assertEqual(income_fin_balance["balance"], 2000)
  308. def test_02_partner_balance(self):
  309. # Generate the general ledger line
  310. res_data = self._get_report_lines(with_partners=True)
  311. general_ledger = res_data["general_ledger"]
  312. check_partner = self.check_partner_in_report(
  313. self.receivable_account.id, self.partner.id, general_ledger
  314. )
  315. self.assertFalse(check_partner)
  316. # Add a move at the previous day of the first day of fiscal year
  317. # to check the initial balance
  318. self._add_move(
  319. date=self.previous_fy_date_end,
  320. receivable_debit=1000,
  321. receivable_credit=0,
  322. income_debit=0,
  323. income_credit=1000,
  324. )
  325. # Re Generate the general ledger line
  326. res_data = self._get_report_lines(with_partners=True)
  327. general_ledger = res_data["general_ledger"]
  328. check_partner = self.check_partner_in_report(
  329. self.receivable_account.id, self.partner.id, general_ledger
  330. )
  331. self.assertTrue(check_partner)
  332. # Check the initial and final balance
  333. partner_initial_balance = self._get_partner_initial_balance(
  334. self.receivable_account.id, self.partner.id, general_ledger
  335. )
  336. partner_final_balance = self._get_partner_final_balance(
  337. self.receivable_account.id, self.partner.id, general_ledger
  338. )
  339. self.assertEqual(partner_initial_balance["debit"], 1000)
  340. self.assertEqual(partner_initial_balance["credit"], 0)
  341. self.assertEqual(partner_initial_balance["balance"], 1000)
  342. self.assertEqual(partner_final_balance["debit"], 1000)
  343. self.assertEqual(partner_final_balance["credit"], 0)
  344. self.assertEqual(partner_final_balance["balance"], 1000)
  345. # Add reversale move of the initial move the first day of fiscal year
  346. # to check the first day of fiscal year is not used
  347. # to compute the initial balance
  348. self._add_move(
  349. date=self.fy_date_start,
  350. receivable_debit=0,
  351. receivable_credit=1000,
  352. income_debit=1000,
  353. income_credit=0,
  354. )
  355. # Re Generate the general ledger line
  356. res_data = self._get_report_lines(with_partners=True)
  357. general_ledger = res_data["general_ledger"]
  358. check_partner = self.check_partner_in_report(
  359. self.receivable_account.id, self.partner.id, general_ledger
  360. )
  361. self.assertTrue(check_partner)
  362. # Check the initial and final balance
  363. partner_initial_balance = self._get_partner_initial_balance(
  364. self.receivable_account.id, self.partner.id, general_ledger
  365. )
  366. partner_final_balance = self._get_partner_final_balance(
  367. self.receivable_account.id, self.partner.id, general_ledger
  368. )
  369. self.assertEqual(partner_initial_balance["debit"], 1000)
  370. self.assertEqual(partner_initial_balance["credit"], 0)
  371. self.assertEqual(partner_initial_balance["balance"], 1000)
  372. self.assertEqual(partner_final_balance["debit"], 1000)
  373. self.assertEqual(partner_final_balance["credit"], 1000)
  374. self.assertEqual(partner_final_balance["balance"], 0)
  375. # Add another move at the end day of fiscal year
  376. # to check that it correctly used on report
  377. self._add_move(
  378. date=self.fy_date_end,
  379. receivable_debit=0,
  380. receivable_credit=1000,
  381. income_debit=1000,
  382. income_credit=0,
  383. )
  384. # Re Generate the general ledger line
  385. res_data = self._get_report_lines(with_partners=True)
  386. general_ledger = res_data["general_ledger"]
  387. check_partner = self.check_partner_in_report(
  388. self.receivable_account.id, self.partner.id, general_ledger
  389. )
  390. self.assertTrue(check_partner)
  391. # Check the initial and final balance
  392. partner_initial_balance = self._get_partner_initial_balance(
  393. self.receivable_account.id, self.partner.id, general_ledger
  394. )
  395. partner_final_balance = self._get_partner_final_balance(
  396. self.receivable_account.id, self.partner.id, general_ledger
  397. )
  398. self.assertEqual(partner_initial_balance["debit"], 1000)
  399. self.assertEqual(partner_initial_balance["credit"], 0)
  400. self.assertEqual(partner_initial_balance["balance"], 1000)
  401. self.assertEqual(partner_final_balance["debit"], 1000)
  402. self.assertEqual(partner_final_balance["credit"], 2000)
  403. self.assertEqual(partner_final_balance["balance"], -1000)
  404. def test_03_unaffected_account_balance(self):
  405. # Generate the general ledger line
  406. res_data = self._get_report_lines()
  407. general_ledger = res_data["general_ledger"]
  408. check_unaffected_account = self.check_account_in_report(
  409. self.unaffected_account.id, general_ledger
  410. )
  411. self.assertTrue(check_unaffected_account)
  412. # Check the initial and final balance
  413. unaffected_init_balance = self._get_initial_balance(
  414. self.unaffected_account.id, general_ledger
  415. )
  416. unaffected_fin_balance = self._get_final_balance(
  417. self.unaffected_account.id, general_ledger
  418. )
  419. self.assertEqual(unaffected_init_balance["debit"], 0)
  420. self.assertEqual(unaffected_init_balance["credit"], 0)
  421. self.assertEqual(unaffected_init_balance["balance"], 0)
  422. self.assertEqual(unaffected_fin_balance["debit"], 0)
  423. self.assertEqual(unaffected_fin_balance["credit"], 0)
  424. self.assertEqual(unaffected_fin_balance["balance"], 0)
  425. # Add a move at the previous day of the first day of fiscal year
  426. # to check the initial balance
  427. self._add_move(
  428. date=self.previous_fy_date_end,
  429. receivable_debit=1000,
  430. receivable_credit=0,
  431. income_debit=0,
  432. income_credit=1000,
  433. )
  434. # Re Generate the general ledger line
  435. res_data = self._get_report_lines()
  436. general_ledger = res_data["general_ledger"]
  437. check_unaffected_account = self.check_account_in_report(
  438. self.unaffected_account.id, general_ledger
  439. )
  440. self.assertTrue(check_unaffected_account)
  441. # Check the initial and final balance
  442. unaffected_init_balance = self._get_initial_balance(
  443. self.unaffected_account.id, general_ledger
  444. )
  445. unaffected_fin_balance = self._get_final_balance(
  446. self.unaffected_account.id, general_ledger
  447. )
  448. self.assertEqual(unaffected_init_balance["debit"], 0)
  449. self.assertEqual(unaffected_init_balance["credit"], 1000)
  450. self.assertEqual(unaffected_init_balance["balance"], -1000)
  451. self.assertEqual(unaffected_fin_balance["debit"], 0)
  452. self.assertEqual(unaffected_fin_balance["credit"], 1000)
  453. self.assertEqual(unaffected_fin_balance["balance"], -1000)
  454. # Add reversale move of the initial move the first day of fiscal year
  455. # to check the first day of fiscal year is not used
  456. # to compute the initial balance
  457. self._add_move(
  458. date=self.fy_date_start,
  459. receivable_debit=0,
  460. receivable_credit=0,
  461. income_debit=0,
  462. income_credit=1000,
  463. unaffected_debit=1000,
  464. unaffected_credit=0,
  465. )
  466. # Re Generate the general ledger line
  467. res_data = self._get_report_lines()
  468. general_ledger = res_data["general_ledger"]
  469. check_unaffected_account = self.check_account_in_report(
  470. self.unaffected_account.id, general_ledger
  471. )
  472. self.assertTrue(check_unaffected_account)
  473. # Check the initial and final balance
  474. unaffected_init_balance = self._get_initial_balance(
  475. self.unaffected_account.id, general_ledger
  476. )
  477. unaffected_fin_balance = self._get_final_balance(
  478. self.unaffected_account.id, general_ledger
  479. )
  480. self.assertEqual(unaffected_init_balance["debit"], 0)
  481. self.assertEqual(unaffected_init_balance["credit"], 1000)
  482. self.assertEqual(unaffected_init_balance["balance"], -1000)
  483. self.assertEqual(unaffected_fin_balance["debit"], 1000)
  484. self.assertEqual(unaffected_fin_balance["credit"], 1000)
  485. self.assertEqual(unaffected_fin_balance["balance"], 0)
  486. # Add another move at the end day of fiscal year
  487. # to check that it correctly used on report
  488. self._add_move(
  489. date=self.fy_date_end,
  490. receivable_debit=3000,
  491. receivable_credit=0,
  492. income_debit=0,
  493. income_credit=0,
  494. unaffected_debit=0,
  495. unaffected_credit=3000,
  496. )
  497. # Re Generate the general ledger line
  498. res_data = self._get_report_lines()
  499. general_ledger = res_data["general_ledger"]
  500. check_unaffected_account = self.check_account_in_report(
  501. self.unaffected_account.id, general_ledger
  502. )
  503. self.assertTrue(check_unaffected_account)
  504. # Check the initial and final balance
  505. unaffected_init_balance = self._get_initial_balance(
  506. self.unaffected_account.id, general_ledger
  507. )
  508. unaffected_fin_balance = self._get_final_balance(
  509. self.unaffected_account.id, general_ledger
  510. )
  511. self.assertEqual(unaffected_init_balance["debit"], 0)
  512. self.assertEqual(unaffected_init_balance["credit"], 1000)
  513. self.assertEqual(unaffected_init_balance["balance"], -1000)
  514. self.assertEqual(unaffected_fin_balance["debit"], 1000)
  515. self.assertEqual(unaffected_fin_balance["credit"], 4000)
  516. self.assertEqual(unaffected_fin_balance["balance"], -3000)
  517. def test_04_unaffected_account_balance_2_years(self):
  518. # Generate the general ledger line
  519. res_data = self._get_report_lines()
  520. general_ledger = res_data["general_ledger"]
  521. check_unaffected_account = self.check_account_in_report(
  522. self.unaffected_account.id, general_ledger
  523. )
  524. self.assertTrue(check_unaffected_account)
  525. # Check the initial and final balance
  526. unaffected_init_balance = self._get_initial_balance(
  527. self.unaffected_account.id, general_ledger
  528. )
  529. unaffected_fin_balance = self._get_final_balance(
  530. self.unaffected_account.id, general_ledger
  531. )
  532. self.assertEqual(unaffected_init_balance["debit"], 0)
  533. self.assertEqual(unaffected_init_balance["credit"], 0)
  534. self.assertEqual(unaffected_init_balance["balance"], 0)
  535. self.assertEqual(unaffected_fin_balance["debit"], 0)
  536. self.assertEqual(unaffected_fin_balance["credit"], 0)
  537. self.assertEqual(unaffected_fin_balance["balance"], 0)
  538. # Add a move at any date 2 years before the balance
  539. # (to create an historic)
  540. self._add_move(
  541. date=self.before_previous_fy_year,
  542. receivable_debit=0,
  543. receivable_credit=1000,
  544. income_debit=1000,
  545. income_credit=0,
  546. )
  547. # Re Generate the general ledger line
  548. res_data = self._get_report_lines()
  549. general_ledger = res_data["general_ledger"]
  550. check_unaffected_account = self.check_account_in_report(
  551. self.unaffected_account.id, general_ledger
  552. )
  553. self.assertTrue(check_unaffected_account)
  554. # Check the initial and final balance
  555. unaffected_init_balance = self._get_initial_balance(
  556. self.unaffected_account.id, general_ledger
  557. )
  558. unaffected_fin_balance = self._get_final_balance(
  559. self.unaffected_account.id, general_ledger
  560. )
  561. self.assertEqual(unaffected_init_balance["debit"], 1000)
  562. self.assertEqual(unaffected_init_balance["credit"], 0)
  563. self.assertEqual(unaffected_init_balance["balance"], 1000)
  564. self.assertEqual(unaffected_fin_balance["debit"], 1000)
  565. self.assertEqual(unaffected_fin_balance["credit"], 0)
  566. self.assertEqual(unaffected_fin_balance["balance"], 1000)
  567. # Affect the company's result last year
  568. self._add_move(
  569. date=self.previous_fy_date_start,
  570. receivable_debit=1000,
  571. receivable_credit=0,
  572. income_debit=0,
  573. income_credit=0,
  574. unaffected_debit=0,
  575. unaffected_credit=1000,
  576. )
  577. # Add another move last year to test the initial balance this year
  578. self._add_move(
  579. date=self.previous_fy_date_start,
  580. receivable_debit=0,
  581. receivable_credit=500,
  582. income_debit=500,
  583. income_credit=0,
  584. unaffected_debit=0,
  585. unaffected_credit=0,
  586. )
  587. # Re Generate the general ledger line
  588. res_data = self._get_report_lines()
  589. general_ledger = res_data["general_ledger"]
  590. check_unaffected_account = self.check_account_in_report(
  591. self.unaffected_account.id, general_ledger
  592. )
  593. self.assertTrue(check_unaffected_account)
  594. # Check the initial and final balance
  595. unaffected_init_balance = self._get_initial_balance(
  596. self.unaffected_account.id, general_ledger
  597. )
  598. unaffected_fin_balance = self._get_final_balance(
  599. self.unaffected_account.id, general_ledger
  600. )
  601. self.assertEqual(unaffected_init_balance["debit"], 1500)
  602. self.assertEqual(unaffected_init_balance["credit"], 1000)
  603. self.assertEqual(unaffected_init_balance["balance"], 500)
  604. self.assertEqual(unaffected_fin_balance["debit"], 1500)
  605. self.assertEqual(unaffected_fin_balance["credit"], 1000)
  606. self.assertEqual(unaffected_fin_balance["balance"], 500)
  607. def test_partner_filter(self):
  608. partner_1 = self.env.ref("base.res_partner_1")
  609. partner_2 = self.env.ref("base.res_partner_2")
  610. partner_3 = self.env.ref("base.res_partner_3")
  611. partner_4 = self.env.ref("base.res_partner_4")
  612. partner_1.write({"is_company": False, "parent_id": partner_2.id})
  613. partner_3.write({"is_company": False})
  614. expected_list = [partner_2.id, partner_3.id, partner_4.id]
  615. context = {
  616. "active_ids": [partner_1.id, partner_2.id, partner_3.id, partner_4.id],
  617. "active_model": "res.partner",
  618. }
  619. wizard = self.env["general.ledger.report.wizard"].with_context(context)
  620. self.assertEqual(wizard._default_partners(), expected_list)
  621. def test_validate_date(self):
  622. company_id = self.env.ref("base.main_company")
  623. company_id.write({"fiscalyear_last_day": 31, "fiscalyear_last_month": "12"})
  624. user = self.env.ref("base.user_root").with_context(company_id=company_id.id)
  625. wizard = self.env["general.ledger.report.wizard"].with_context(user=user.id)
  626. self.assertEqual(wizard._init_date_from(), time.strftime("%Y") + "-01-01")
  627. def test_validate_date_range(self):
  628. data_type = self.env["date.range.type"].create(
  629. {"name": "Fiscal year", "company_id": False, "allow_overlap": False}
  630. )
  631. dr = self.env["date.range"].create(
  632. {
  633. "name": "FS2015",
  634. "date_start": "2018-01-01",
  635. "date_end": "2018-12-31",
  636. "type_id": data_type.id,
  637. }
  638. )
  639. wizard = self.env["general.ledger.report.wizard"].create(
  640. {"date_range_id": dr.id}
  641. )
  642. wizard.onchange_date_range_id()
  643. self.assertEqual(wizard.date_from, date(2018, 1, 1))
  644. self.assertEqual(wizard.date_to, date(2018, 12, 31))