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.

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