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.

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