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.

702 lines
27 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):
  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. "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. # Add a move at the previous day of the first day of fiscal year
  168. # to check the initial balance
  169. self._add_move(
  170. date=self.previous_fy_date_end,
  171. receivable_debit=1000,
  172. receivable_credit=0,
  173. income_debit=0,
  174. income_credit=1000,
  175. )
  176. # Re Generate the general ledger line
  177. res_data = self._get_report_lines()
  178. general_ledger = res_data["general_ledger"]
  179. check_receivable_account = self.check_account_in_report(
  180. self.receivable_account.id, general_ledger
  181. )
  182. self.assertTrue(check_receivable_account)
  183. check_income_account = self.check_account_in_report(
  184. self.income_account.id, general_ledger
  185. )
  186. self.assertFalse(check_income_account)
  187. # Check the initial and final balance
  188. receivable_init_balance = self._get_initial_balance(
  189. self.receivable_account.id, general_ledger
  190. )
  191. receivable_fin_balance = self._get_final_balance(
  192. self.receivable_account.id, general_ledger
  193. )
  194. self.assertEqual(receivable_init_balance["debit"], 1000)
  195. self.assertEqual(receivable_init_balance["credit"], 0)
  196. self.assertEqual(receivable_init_balance["balance"], 1000)
  197. self.assertEqual(receivable_fin_balance["debit"], 1000)
  198. self.assertEqual(receivable_fin_balance["credit"], 0)
  199. self.assertEqual(receivable_fin_balance["balance"], 1000)
  200. # Add reversale move of the initial move the first day of fiscal year
  201. # to check the first day of fiscal year is not used
  202. # to compute the initial balance
  203. self._add_move(
  204. date=self.fy_date_start,
  205. receivable_debit=0,
  206. receivable_credit=1000,
  207. income_debit=1000,
  208. income_credit=0,
  209. )
  210. # Re Generate the general ledger line
  211. res_data = self._get_report_lines()
  212. general_ledger = res_data["general_ledger"]
  213. check_receivable_account = self.check_account_in_report(
  214. self.receivable_account.id, general_ledger
  215. )
  216. self.assertTrue(check_receivable_account)
  217. check_income_account = self.check_account_in_report(
  218. self.income_account.id, general_ledger
  219. )
  220. self.assertTrue(check_income_account)
  221. # Check the initial and final balance
  222. receivable_init_balance = self._get_initial_balance(
  223. self.receivable_account.id, general_ledger
  224. )
  225. receivable_fin_balance = self._get_final_balance(
  226. self.receivable_account.id, general_ledger
  227. )
  228. income_init_balance = self._get_initial_balance(
  229. self.income_account.id, general_ledger
  230. )
  231. income_fin_balance = self._get_final_balance(
  232. self.income_account.id, general_ledger
  233. )
  234. self.assertEqual(receivable_init_balance["debit"], 1000)
  235. self.assertEqual(receivable_init_balance["credit"], 0)
  236. self.assertEqual(receivable_init_balance["balance"], 1000)
  237. self.assertEqual(receivable_fin_balance["debit"], 1000)
  238. self.assertEqual(receivable_fin_balance["credit"], 1000)
  239. self.assertEqual(receivable_fin_balance["balance"], 0)
  240. self.assertEqual(income_init_balance["debit"], 0)
  241. self.assertEqual(income_init_balance["credit"], 0)
  242. self.assertEqual(income_init_balance["balance"], 0)
  243. self.assertEqual(income_fin_balance["debit"], 1000)
  244. self.assertEqual(income_fin_balance["credit"], 0)
  245. self.assertEqual(income_fin_balance["balance"], 1000)
  246. # Add another move at the end day of fiscal year
  247. # to check that it correctly used on report
  248. self._add_move(
  249. date=self.fy_date_end,
  250. receivable_debit=0,
  251. receivable_credit=1000,
  252. income_debit=1000,
  253. income_credit=0,
  254. )
  255. # Re Generate the general ledger line
  256. res_data = self._get_report_lines()
  257. general_ledger = res_data["general_ledger"]
  258. check_receivable_account = self.check_account_in_report(
  259. self.receivable_account.id, general_ledger
  260. )
  261. self.assertTrue(check_receivable_account)
  262. check_income_account = self.check_account_in_report(
  263. self.income_account.id, general_ledger
  264. )
  265. self.assertTrue(check_income_account)
  266. # Check the initial and final balance
  267. receivable_init_balance = self._get_initial_balance(
  268. self.receivable_account.id, general_ledger
  269. )
  270. receivable_fin_balance = self._get_final_balance(
  271. self.receivable_account.id, general_ledger
  272. )
  273. income_init_balance = self._get_initial_balance(
  274. self.income_account.id, general_ledger
  275. )
  276. income_fin_balance = self._get_final_balance(
  277. self.income_account.id, general_ledger
  278. )
  279. self.assertEqual(receivable_init_balance["debit"], 1000)
  280. self.assertEqual(receivable_init_balance["credit"], 0)
  281. self.assertEqual(receivable_init_balance["balance"], 1000)
  282. self.assertEqual(receivable_fin_balance["debit"], 1000)
  283. self.assertEqual(receivable_fin_balance["credit"], 2000)
  284. self.assertEqual(receivable_fin_balance["balance"], -1000)
  285. self.assertEqual(income_init_balance["debit"], 0)
  286. self.assertEqual(income_init_balance["credit"], 0)
  287. self.assertEqual(income_init_balance["balance"], 0)
  288. self.assertEqual(income_fin_balance["debit"], 2000)
  289. self.assertEqual(income_fin_balance["credit"], 0)
  290. self.assertEqual(income_fin_balance["balance"], 2000)
  291. def test_02_partner_balance(self):
  292. # Generate the general ledger line
  293. res_data = self._get_report_lines(with_partners=True)
  294. general_ledger = res_data["general_ledger"]
  295. check_partner = self.check_partner_in_report(
  296. self.receivable_account.id, self.partner.id, general_ledger
  297. )
  298. self.assertFalse(check_partner)
  299. # Add a move at the previous day of the first day of fiscal year
  300. # to check the initial balance
  301. self._add_move(
  302. date=self.previous_fy_date_end,
  303. receivable_debit=1000,
  304. receivable_credit=0,
  305. income_debit=0,
  306. income_credit=1000,
  307. )
  308. # Re Generate the general ledger line
  309. res_data = self._get_report_lines(with_partners=True)
  310. general_ledger = res_data["general_ledger"]
  311. check_partner = self.check_partner_in_report(
  312. self.receivable_account.id, self.partner.id, general_ledger
  313. )
  314. self.assertTrue(check_partner)
  315. # Check the initial and final balance
  316. partner_initial_balance = self._get_partner_initial_balance(
  317. self.receivable_account.id, self.partner.id, general_ledger
  318. )
  319. partner_final_balance = self._get_partner_final_balance(
  320. self.receivable_account.id, self.partner.id, general_ledger
  321. )
  322. self.assertEqual(partner_initial_balance["debit"], 1000)
  323. self.assertEqual(partner_initial_balance["credit"], 0)
  324. self.assertEqual(partner_initial_balance["balance"], 1000)
  325. self.assertEqual(partner_final_balance["debit"], 1000)
  326. self.assertEqual(partner_final_balance["credit"], 0)
  327. self.assertEqual(partner_final_balance["balance"], 1000)
  328. # Add reversale move of the initial move the first day of fiscal year
  329. # to check the first day of fiscal year is not used
  330. # to compute the initial balance
  331. self._add_move(
  332. date=self.fy_date_start,
  333. receivable_debit=0,
  334. receivable_credit=1000,
  335. income_debit=1000,
  336. income_credit=0,
  337. )
  338. # Re Generate the general ledger line
  339. res_data = self._get_report_lines(with_partners=True)
  340. general_ledger = res_data["general_ledger"]
  341. check_partner = self.check_partner_in_report(
  342. self.receivable_account.id, self.partner.id, general_ledger
  343. )
  344. self.assertTrue(check_partner)
  345. # Check the initial and final balance
  346. partner_initial_balance = self._get_partner_initial_balance(
  347. self.receivable_account.id, self.partner.id, general_ledger
  348. )
  349. partner_final_balance = self._get_partner_final_balance(
  350. self.receivable_account.id, self.partner.id, general_ledger
  351. )
  352. self.assertEqual(partner_initial_balance["debit"], 1000)
  353. self.assertEqual(partner_initial_balance["credit"], 0)
  354. self.assertEqual(partner_initial_balance["balance"], 1000)
  355. self.assertEqual(partner_final_balance["debit"], 1000)
  356. self.assertEqual(partner_final_balance["credit"], 1000)
  357. self.assertEqual(partner_final_balance["balance"], 0)
  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 general ledger line
  368. res_data = self._get_report_lines(with_partners=True)
  369. general_ledger = res_data["general_ledger"]
  370. check_partner = self.check_partner_in_report(
  371. self.receivable_account.id, self.partner.id, general_ledger
  372. )
  373. self.assertTrue(check_partner)
  374. # Check the initial and final balance
  375. partner_initial_balance = self._get_partner_initial_balance(
  376. self.receivable_account.id, self.partner.id, general_ledger
  377. )
  378. partner_final_balance = self._get_partner_final_balance(
  379. self.receivable_account.id, self.partner.id, general_ledger
  380. )
  381. self.assertEqual(partner_initial_balance["debit"], 1000)
  382. self.assertEqual(partner_initial_balance["credit"], 0)
  383. self.assertEqual(partner_initial_balance["balance"], 1000)
  384. self.assertEqual(partner_final_balance["debit"], 1000)
  385. self.assertEqual(partner_final_balance["credit"], 2000)
  386. self.assertEqual(partner_final_balance["balance"], -1000)
  387. def test_03_unaffected_account_balance(self):
  388. # Generate the general ledger line
  389. res_data = self._get_report_lines()
  390. general_ledger = res_data["general_ledger"]
  391. check_unaffected_account = self.check_account_in_report(
  392. self.unaffected_account.id, general_ledger
  393. )
  394. self.assertTrue(check_unaffected_account)
  395. # Check the initial and final balance
  396. unaffected_init_balance = self._get_initial_balance(
  397. self.unaffected_account.id, general_ledger
  398. )
  399. unaffected_fin_balance = self._get_final_balance(
  400. self.unaffected_account.id, general_ledger
  401. )
  402. self.assertEqual(unaffected_init_balance["debit"], 0)
  403. self.assertEqual(unaffected_init_balance["credit"], 0)
  404. self.assertEqual(unaffected_init_balance["balance"], 0)
  405. self.assertEqual(unaffected_fin_balance["debit"], 0)
  406. self.assertEqual(unaffected_fin_balance["credit"], 0)
  407. self.assertEqual(unaffected_fin_balance["balance"], 0)
  408. # Add a move at the previous day of the first day of fiscal year
  409. # to check the initial balance
  410. self._add_move(
  411. date=self.previous_fy_date_end,
  412. receivable_debit=1000,
  413. receivable_credit=0,
  414. income_debit=0,
  415. income_credit=1000,
  416. )
  417. # Re Generate the general ledger line
  418. res_data = self._get_report_lines()
  419. general_ledger = res_data["general_ledger"]
  420. check_unaffected_account = self.check_account_in_report(
  421. self.unaffected_account.id, general_ledger
  422. )
  423. self.assertTrue(check_unaffected_account)
  424. # Check the initial and final balance
  425. unaffected_init_balance = self._get_initial_balance(
  426. self.unaffected_account.id, general_ledger
  427. )
  428. unaffected_fin_balance = self._get_final_balance(
  429. self.unaffected_account.id, general_ledger
  430. )
  431. self.assertEqual(unaffected_init_balance["debit"], 0)
  432. self.assertEqual(unaffected_init_balance["credit"], 1000)
  433. self.assertEqual(unaffected_init_balance["balance"], -1000)
  434. self.assertEqual(unaffected_fin_balance["debit"], 0)
  435. self.assertEqual(unaffected_fin_balance["credit"], 1000)
  436. self.assertEqual(unaffected_fin_balance["balance"], -1000)
  437. # Add reversale move of the initial move the first day of fiscal year
  438. # to check the first day of fiscal year is not used
  439. # to compute the initial balance
  440. self._add_move(
  441. date=self.fy_date_start,
  442. receivable_debit=0,
  443. receivable_credit=0,
  444. income_debit=0,
  445. income_credit=1000,
  446. unaffected_debit=1000,
  447. unaffected_credit=0,
  448. )
  449. # Re Generate the general ledger line
  450. res_data = self._get_report_lines()
  451. general_ledger = res_data["general_ledger"]
  452. check_unaffected_account = self.check_account_in_report(
  453. self.unaffected_account.id, general_ledger
  454. )
  455. self.assertTrue(check_unaffected_account)
  456. # Check the initial and final balance
  457. unaffected_init_balance = self._get_initial_balance(
  458. self.unaffected_account.id, general_ledger
  459. )
  460. unaffected_fin_balance = self._get_final_balance(
  461. self.unaffected_account.id, general_ledger
  462. )
  463. self.assertEqual(unaffected_init_balance["debit"], 0)
  464. self.assertEqual(unaffected_init_balance["credit"], 1000)
  465. self.assertEqual(unaffected_init_balance["balance"], -1000)
  466. self.assertEqual(unaffected_fin_balance["debit"], 1000)
  467. self.assertEqual(unaffected_fin_balance["credit"], 1000)
  468. self.assertEqual(unaffected_fin_balance["balance"], 0)
  469. # Add another move at the end day of fiscal year
  470. # to check that it correctly used on report
  471. self._add_move(
  472. date=self.fy_date_end,
  473. receivable_debit=3000,
  474. receivable_credit=0,
  475. income_debit=0,
  476. income_credit=0,
  477. unaffected_debit=0,
  478. unaffected_credit=3000,
  479. )
  480. # Re Generate the general ledger line
  481. res_data = self._get_report_lines()
  482. general_ledger = res_data["general_ledger"]
  483. check_unaffected_account = self.check_account_in_report(
  484. self.unaffected_account.id, general_ledger
  485. )
  486. self.assertTrue(check_unaffected_account)
  487. # Check the initial and final balance
  488. unaffected_init_balance = self._get_initial_balance(
  489. self.unaffected_account.id, general_ledger
  490. )
  491. unaffected_fin_balance = self._get_final_balance(
  492. self.unaffected_account.id, general_ledger
  493. )
  494. self.assertEqual(unaffected_init_balance["debit"], 0)
  495. self.assertEqual(unaffected_init_balance["credit"], 1000)
  496. self.assertEqual(unaffected_init_balance["balance"], -1000)
  497. self.assertEqual(unaffected_fin_balance["debit"], 1000)
  498. self.assertEqual(unaffected_fin_balance["credit"], 4000)
  499. self.assertEqual(unaffected_fin_balance["balance"], -3000)
  500. def test_04_unaffected_account_balance_2_years(self):
  501. # Generate the general ledger line
  502. res_data = self._get_report_lines()
  503. general_ledger = res_data["general_ledger"]
  504. check_unaffected_account = self.check_account_in_report(
  505. self.unaffected_account.id, general_ledger
  506. )
  507. self.assertTrue(check_unaffected_account)
  508. # Check the initial and final balance
  509. unaffected_init_balance = self._get_initial_balance(
  510. self.unaffected_account.id, general_ledger
  511. )
  512. unaffected_fin_balance = self._get_final_balance(
  513. self.unaffected_account.id, general_ledger
  514. )
  515. self.assertEqual(unaffected_init_balance["debit"], 0)
  516. self.assertEqual(unaffected_init_balance["credit"], 0)
  517. self.assertEqual(unaffected_init_balance["balance"], 0)
  518. self.assertEqual(unaffected_fin_balance["debit"], 0)
  519. self.assertEqual(unaffected_fin_balance["credit"], 0)
  520. self.assertEqual(unaffected_fin_balance["balance"], 0)
  521. # Add a move at any date 2 years before the balance
  522. # (to create an historic)
  523. self._add_move(
  524. date=self.before_previous_fy_year,
  525. receivable_debit=0,
  526. receivable_credit=1000,
  527. income_debit=1000,
  528. income_credit=0,
  529. )
  530. # Re Generate the general ledger line
  531. res_data = self._get_report_lines()
  532. general_ledger = res_data["general_ledger"]
  533. check_unaffected_account = self.check_account_in_report(
  534. self.unaffected_account.id, general_ledger
  535. )
  536. self.assertTrue(check_unaffected_account)
  537. # Check the initial and final balance
  538. unaffected_init_balance = self._get_initial_balance(
  539. self.unaffected_account.id, general_ledger
  540. )
  541. unaffected_fin_balance = self._get_final_balance(
  542. self.unaffected_account.id, general_ledger
  543. )
  544. self.assertEqual(unaffected_init_balance["debit"], 1000)
  545. self.assertEqual(unaffected_init_balance["credit"], 0)
  546. self.assertEqual(unaffected_init_balance["balance"], 1000)
  547. self.assertEqual(unaffected_fin_balance["debit"], 1000)
  548. self.assertEqual(unaffected_fin_balance["credit"], 0)
  549. self.assertEqual(unaffected_fin_balance["balance"], 1000)
  550. # Affect the company's result last year
  551. self._add_move(
  552. date=self.previous_fy_date_start,
  553. receivable_debit=1000,
  554. receivable_credit=0,
  555. income_debit=0,
  556. income_credit=0,
  557. unaffected_debit=0,
  558. unaffected_credit=1000,
  559. )
  560. # Add another move last year to test the initial balance this year
  561. self._add_move(
  562. date=self.previous_fy_date_start,
  563. receivable_debit=0,
  564. receivable_credit=500,
  565. income_debit=500,
  566. income_credit=0,
  567. unaffected_debit=0,
  568. unaffected_credit=0,
  569. )
  570. # Re Generate the general ledger line
  571. res_data = self._get_report_lines()
  572. general_ledger = res_data["general_ledger"]
  573. check_unaffected_account = self.check_account_in_report(
  574. self.unaffected_account.id, general_ledger
  575. )
  576. self.assertTrue(check_unaffected_account)
  577. # Check the initial and final balance
  578. unaffected_init_balance = self._get_initial_balance(
  579. self.unaffected_account.id, general_ledger
  580. )
  581. unaffected_fin_balance = self._get_final_balance(
  582. self.unaffected_account.id, general_ledger
  583. )
  584. self.assertEqual(unaffected_init_balance["debit"], 1500)
  585. self.assertEqual(unaffected_init_balance["credit"], 1000)
  586. self.assertEqual(unaffected_init_balance["balance"], 500)
  587. self.assertEqual(unaffected_fin_balance["debit"], 1500)
  588. self.assertEqual(unaffected_fin_balance["credit"], 1000)
  589. self.assertEqual(unaffected_fin_balance["balance"], 500)
  590. def test_partner_filter(self):
  591. partner_1 = self.env.ref("base.res_partner_1")
  592. partner_2 = self.env.ref("base.res_partner_2")
  593. partner_3 = self.env.ref("base.res_partner_3")
  594. partner_4 = self.env.ref("base.res_partner_4")
  595. partner_1.write({"is_company": False, "parent_id": partner_2.id})
  596. partner_3.write({"is_company": False})
  597. expected_list = [partner_2.id, partner_3.id, partner_4.id]
  598. context = {
  599. "active_ids": [partner_1.id, partner_2.id, partner_3.id, partner_4.id],
  600. "active_model": "res.partner",
  601. }
  602. wizard = self.env["general.ledger.report.wizard"].with_context(context)
  603. self.assertEqual(wizard._default_partners(), expected_list)
  604. def test_validate_date(self):
  605. company_id = self.env.user.company_id
  606. company_id.write({"fiscalyear_last_day": 31, "fiscalyear_last_month": "12"})
  607. user = self.env.ref("base.user_root").with_context(company_id=company_id.id)
  608. wizard = self.env["general.ledger.report.wizard"].with_context(user=user.id)
  609. self.assertEqual(wizard._init_date_from(), time.strftime("%Y") + "-01-01")
  610. def test_validate_date_range(self):
  611. data_type = self.env["date.range.type"].create(
  612. {"name": "Fiscal year", "company_id": False, "allow_overlap": False}
  613. )
  614. dr = self.env["date.range"].create(
  615. {
  616. "name": "FS2015",
  617. "date_start": "2018-01-01",
  618. "date_end": "2018-12-31",
  619. "type_id": data_type.id,
  620. }
  621. )
  622. wizard = self.env["general.ledger.report.wizard"].create(
  623. {"date_range_id": dr.id}
  624. )
  625. wizard.onchange_date_range_id()
  626. self.assertEqual(wizard.date_from, date(2018, 1, 1))
  627. self.assertEqual(wizard.date_to, date(2018, 12, 31))