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.

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