test_account_move_line_tax_details.py 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. # -*- coding: utf-8 -*-
  2. #pylint: disable=too-many-lines
  3. from odoo.addons.account.tests.common import AccountTestInvoicingCommon
  4. from odoo.tests import tagged
  5. from odoo import Command
  6. @tagged('post_install', '-at_install')
  7. class TestAccountTaxDetailsReport(AccountTestInvoicingCommon):
  8. def _dispatch_move_lines(self, moves):
  9. base_lines = moves.line_ids\
  10. .filtered(lambda x: x.tax_ids and not x.tax_line_id)\
  11. .sorted(lambda x: (x.move_id.id, x.id, -abs(x.amount_currency)))
  12. tax_lines = moves.line_ids\
  13. .filtered(lambda x: x.tax_line_id)\
  14. .sorted(lambda x: (x.move_id.id, x.tax_line_id.id, x.tax_ids.ids, x.tax_repartition_line_id.id))
  15. return base_lines, tax_lines
  16. def _get_tax_details(self, fallback=False, extra_domain=None):
  17. domain = [('company_id', '=', self.env.company.id)] + (extra_domain or [])
  18. tax_details_query, tax_details_params = self.env['account.move.line']._get_query_tax_details_from_domain(domain, fallback=fallback)
  19. self.env['account.move.line'].flush_model()
  20. self.cr.execute(tax_details_query, tax_details_params)
  21. tax_details_res = self.cr.dictfetchall()
  22. return sorted(tax_details_res, key=lambda x: (x['base_line_id'], abs(x['base_amount']), abs(x['tax_amount'])))
  23. def assertTaxDetailsValues(self, tax_details, expected_values_list):
  24. self.assertEqual(len(tax_details), len(expected_values_list))
  25. for i, expected_values in enumerate(expected_values_list):
  26. keys = set(expected_values.keys())
  27. tax_detail = tax_details[i]
  28. self.assertDictEqual({k: v for k, v in tax_detail.items() if k in keys}, expected_values)
  29. def assertTotalAmounts(self, moves, tax_details):
  30. tax_lines = moves.line_ids.filtered('tax_line_id')
  31. taxes = tax_lines.mapped(lambda x: x.group_tax_id or x.tax_line_id)
  32. for tax in taxes:
  33. lines = tax_lines.filtered(lambda x: (x.group_tax_id or x.tax_line_id) == tax)
  34. tax_amount = sum(lines.mapped('balance'))
  35. tax_details_amount = sum(x['tax_amount']
  36. for x in tax_details
  37. if (x['group_tax_id'] or x['tax_id']) == tax.id)
  38. self.assertAlmostEqual(tax_amount, tax_details_amount)
  39. def test_affect_base_amount_1(self):
  40. tax_20_affect = self.env['account.tax'].create({
  41. 'name': "tax_20_affect",
  42. 'amount_type': 'percent',
  43. 'amount': 20.0,
  44. 'include_base_amount': True,
  45. })
  46. tax_10 = self.env['account.tax'].create({
  47. 'name': "tax_10",
  48. 'amount_type': 'percent',
  49. 'amount': 10.0,
  50. })
  51. tax_5 = self.env['account.tax'].create({
  52. 'name': "tax_5",
  53. 'amount_type': 'percent',
  54. 'amount': 5.0,
  55. })
  56. invoice_create_values = {
  57. 'move_type': 'out_invoice',
  58. 'partner_id': self.partner_a.id,
  59. 'invoice_date': '2019-01-01',
  60. 'invoice_line_ids': [
  61. Command.create({
  62. 'name': 'line1',
  63. 'account_id': self.company_data['default_account_revenue'].id,
  64. 'price_unit': 1000.0,
  65. 'tax_ids': [Command.set((tax_20_affect + tax_10 + tax_5).ids)],
  66. }),
  67. Command.create({
  68. 'name': 'line2',
  69. 'account_id': self.company_data['default_account_revenue'].id,
  70. 'price_unit': 1000.0,
  71. 'tax_ids': [Command.set(tax_10.ids)],
  72. }),
  73. Command.create({
  74. 'name': 'line3',
  75. 'account_id': self.company_data['default_account_revenue'].id,
  76. 'price_unit': 1000.0,
  77. 'tax_ids': [Command.set(tax_10.ids)],
  78. }),
  79. Command.create({
  80. 'name': 'line4',
  81. 'account_id': self.company_data['default_account_revenue'].id,
  82. 'price_unit': 2000.0,
  83. 'tax_ids': [Command.set((tax_20_affect + tax_10).ids)],
  84. }),
  85. ]
  86. }
  87. invoice = self.env['account.move'].create(invoice_create_values)
  88. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  89. tax_details = self._get_tax_details()
  90. self.assertTaxDetailsValues(tax_details, [
  91. {
  92. 'base_line_id': base_lines[0].id,
  93. 'tax_line_id': tax_lines[3].id,
  94. 'base_amount': -200.0,
  95. 'tax_amount': -10.0,
  96. },
  97. {
  98. 'base_line_id': base_lines[0].id,
  99. 'tax_line_id': tax_lines[2].id,
  100. 'base_amount': -200.0,
  101. 'tax_amount': -20.0,
  102. },
  103. {
  104. 'base_line_id': base_lines[0].id,
  105. 'tax_line_id': tax_lines[3].id,
  106. 'base_amount': -1000.0,
  107. 'tax_amount': -50.0,
  108. },
  109. {
  110. 'base_line_id': base_lines[0].id,
  111. 'tax_line_id': tax_lines[2].id,
  112. 'base_amount': -1000.0,
  113. 'tax_amount': -100.0,
  114. },
  115. {
  116. 'base_line_id': base_lines[0].id,
  117. 'tax_line_id': tax_lines[1].id,
  118. 'base_amount': -1000.0,
  119. 'tax_amount': -200.0,
  120. },
  121. {
  122. 'base_line_id': base_lines[1].id,
  123. 'tax_line_id': tax_lines[2].id,
  124. 'base_amount': -1000.0,
  125. 'tax_amount': -100.0,
  126. },
  127. {
  128. 'base_line_id': base_lines[2].id,
  129. 'tax_line_id': tax_lines[2].id,
  130. 'base_amount': -1000.0,
  131. 'tax_amount': -100.0,
  132. },
  133. {
  134. 'base_line_id': base_lines[3].id,
  135. 'tax_line_id': tax_lines[2].id,
  136. 'base_amount': -400.0,
  137. 'tax_amount': -40.0,
  138. },
  139. {
  140. 'base_line_id': base_lines[3].id,
  141. 'tax_line_id': tax_lines[2].id,
  142. 'base_amount': -2000.0,
  143. 'tax_amount': -200.0,
  144. },
  145. {
  146. 'base_line_id': base_lines[3].id,
  147. 'tax_line_id': tax_lines[0].id,
  148. 'base_amount': -2000.0,
  149. 'tax_amount': -400.0,
  150. },
  151. ])
  152. self.assertTotalAmounts(invoice, tax_details)
  153. # Same with a group of taxes
  154. tax_group = self.env['account.tax'].create({
  155. 'name': "tax_group",
  156. 'amount_type': 'group',
  157. 'children_tax_ids': [Command.set((tax_20_affect + tax_10 + tax_5).ids)],
  158. })
  159. invoice_create_values['invoice_line_ids'][0][2]['tax_ids'] = [Command.set(tax_group.ids)]
  160. invoice = self.env['account.move'].create(invoice_create_values)
  161. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  162. tax_details = self._get_tax_details(extra_domain=[('move_id', '=', invoice.id)])
  163. self.assertTaxDetailsValues(tax_details, [
  164. {
  165. 'base_line_id': base_lines[0].id,
  166. 'tax_line_id': tax_lines[4].id,
  167. 'base_amount': -200.0,
  168. 'tax_amount': -10.0,
  169. },
  170. {
  171. 'base_line_id': base_lines[0].id,
  172. 'tax_line_id': tax_lines[2].id,
  173. 'base_amount': -200.0,
  174. 'tax_amount': -20.0,
  175. },
  176. {
  177. 'base_line_id': base_lines[0].id,
  178. 'tax_line_id': tax_lines[4].id,
  179. 'base_amount': -1000.0,
  180. 'tax_amount': -50.0,
  181. },
  182. {
  183. 'base_line_id': base_lines[0].id,
  184. 'tax_line_id': tax_lines[2].id,
  185. 'base_amount': -1000.0,
  186. 'tax_amount': -100.0,
  187. },
  188. {
  189. 'base_line_id': base_lines[0].id,
  190. 'tax_line_id': tax_lines[1].id,
  191. 'base_amount': -1000.0,
  192. 'tax_amount': -200.0,
  193. },
  194. {
  195. 'base_line_id': base_lines[1].id,
  196. 'tax_line_id': tax_lines[3].id,
  197. 'base_amount': -1000.0,
  198. 'tax_amount': -100.0,
  199. },
  200. {
  201. 'base_line_id': base_lines[2].id,
  202. 'tax_line_id': tax_lines[3].id,
  203. 'base_amount': -1000.0,
  204. 'tax_amount': -100.0,
  205. },
  206. {
  207. 'base_line_id': base_lines[3].id,
  208. 'tax_line_id': tax_lines[3].id,
  209. 'base_amount': -400.0,
  210. 'tax_amount': -40.0,
  211. },
  212. {
  213. 'base_line_id': base_lines[3].id,
  214. 'tax_line_id': tax_lines[3].id,
  215. 'base_amount': -2000.0,
  216. 'tax_amount': -200.0,
  217. },
  218. {
  219. 'base_line_id': base_lines[3].id,
  220. 'tax_line_id': tax_lines[0].id,
  221. 'base_amount': -2000.0,
  222. 'tax_amount': -400.0,
  223. },
  224. ])
  225. self.assertTotalAmounts(invoice, tax_details)
  226. def test_affect_base_amount_2(self):
  227. taxes_10_affect = self.env['account.tax'].create([{
  228. 'name': "tax_10_affect_%s" % i,
  229. 'amount_type': 'percent',
  230. 'amount': 10.0,
  231. 'include_base_amount': True,
  232. } for i in range(3)])
  233. invoice = self.env['account.move'].create({
  234. 'move_type': 'out_invoice',
  235. 'partner_id': self.partner_a.id,
  236. 'invoice_date': '2019-01-01',
  237. 'invoice_line_ids': [
  238. Command.create({
  239. 'name': 'line1',
  240. 'account_id': self.company_data['default_account_revenue'].id,
  241. 'price_unit': 1000.0,
  242. 'tax_ids': [Command.set(taxes_10_affect.ids)],
  243. }),
  244. Command.create({
  245. 'name': 'line2',
  246. 'account_id': self.company_data['default_account_revenue'].id,
  247. 'price_unit': 1000.0,
  248. 'tax_ids': [Command.set((taxes_10_affect[0] + taxes_10_affect[2]).ids)],
  249. }),
  250. ]
  251. })
  252. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  253. tax_details = self._get_tax_details()
  254. self.assertTaxDetailsValues(
  255. tax_details,
  256. [
  257. {
  258. 'base_line_id': base_lines[0].id,
  259. 'tax_line_id': tax_lines[2].id,
  260. 'base_amount': -100.0,
  261. 'tax_amount': -10.0,
  262. },
  263. {
  264. 'base_line_id': base_lines[0].id,
  265. 'tax_line_id': tax_lines[3].id,
  266. 'base_amount': -100.0,
  267. 'tax_amount': -10.0,
  268. },
  269. {
  270. 'base_line_id': base_lines[0].id,
  271. 'tax_line_id': tax_lines[3].id,
  272. 'base_amount': -110.0,
  273. 'tax_amount': -11.0,
  274. },
  275. {
  276. 'base_line_id': base_lines[0].id,
  277. 'tax_line_id': tax_lines[0].id,
  278. 'base_amount': -1000.0,
  279. 'tax_amount': -100.0,
  280. },
  281. {
  282. 'base_line_id': base_lines[0].id,
  283. 'tax_line_id': tax_lines[2].id,
  284. 'base_amount': -1000.0,
  285. 'tax_amount': -100.0,
  286. },
  287. {
  288. 'base_line_id': base_lines[0].id,
  289. 'tax_line_id': tax_lines[3].id,
  290. 'base_amount': -1000.0,
  291. 'tax_amount': -100.0,
  292. },
  293. {
  294. 'base_line_id': base_lines[1].id,
  295. 'tax_line_id': tax_lines[3].id,
  296. 'base_amount': -100.0,
  297. 'tax_amount': -10.0,
  298. },
  299. {
  300. 'base_line_id': base_lines[1].id,
  301. 'tax_line_id': tax_lines[3].id,
  302. 'base_amount': -1000.0,
  303. 'tax_amount': -100.0,
  304. },
  305. {
  306. 'base_line_id': base_lines[1].id,
  307. 'tax_line_id': tax_lines[1].id,
  308. 'base_amount': -1000.0,
  309. 'tax_amount': -100.0,
  310. },
  311. ],
  312. )
  313. self.assertTotalAmounts(invoice, tax_details)
  314. def test_affect_base_amount_3(self):
  315. eco_tax = self.env['account.tax'].create({
  316. 'name': "eco_tax",
  317. 'amount_type': 'fixed',
  318. 'amount': 5.0,
  319. 'include_base_amount': True,
  320. })
  321. tax_20 = self.env['account.tax'].create({
  322. 'name': "tax_20",
  323. 'amount_type': 'percent',
  324. 'amount': 20.0,
  325. })
  326. invoice = self.env['account.move'].create({
  327. 'move_type': 'out_invoice',
  328. 'partner_id': self.partner_a.id,
  329. 'invoice_date': '2019-01-01',
  330. 'invoice_line_ids': [
  331. Command.create({
  332. 'name': 'line1',
  333. 'account_id': self.company_data['default_account_revenue'].id,
  334. 'price_unit': 95.0,
  335. 'tax_ids': [Command.set((eco_tax + tax_20).ids)],
  336. }),
  337. ]
  338. })
  339. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  340. tax_details = self._get_tax_details()
  341. self.assertTaxDetailsValues(
  342. tax_details,
  343. [
  344. {
  345. 'base_line_id': base_lines[0].id,
  346. 'tax_line_id': tax_lines[1].id,
  347. 'base_amount': -5.0,
  348. 'tax_amount': -1.0,
  349. },
  350. {
  351. 'base_line_id': base_lines[0].id,
  352. 'tax_line_id': tax_lines[0].id,
  353. 'base_amount': -95.0,
  354. 'tax_amount': -5.0,
  355. },
  356. {
  357. 'base_line_id': base_lines[0].id,
  358. 'tax_line_id': tax_lines[1].id,
  359. 'base_amount': -95.0,
  360. 'tax_amount': -19.0,
  361. },
  362. ],
  363. )
  364. self.assertTotalAmounts(invoice, tax_details)
  365. def test_affect_base_amount_4(self):
  366. tax_10 = self.env['account.tax'].create({
  367. 'name': "eco_tax",
  368. 'amount_type': 'percent',
  369. 'amount': 10.0,
  370. 'include_base_amount': True,
  371. })
  372. tax_20 = self.env['account.tax'].create({
  373. 'name': "tax_20",
  374. 'amount_type': 'percent',
  375. 'amount': 20.0,
  376. })
  377. invoice = self.env['account.move'].create({
  378. 'move_type': 'out_invoice',
  379. 'partner_id': self.partner_a.id,
  380. 'invoice_date': '2019-01-01',
  381. 'invoice_line_ids': [
  382. Command.create({
  383. 'name': 'line1',
  384. 'account_id': self.company_data['default_account_revenue'].id,
  385. 'price_unit': 100.0,
  386. 'tax_ids': [Command.set((tax_10 + tax_20).ids)],
  387. }),
  388. Command.create({
  389. 'name': 'line1',
  390. 'account_id': self.company_data['default_account_revenue'].id,
  391. 'price_unit': 100.0,
  392. 'tax_ids': [Command.set(tax_10.ids)],
  393. }),
  394. ]
  395. })
  396. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  397. tax_details = self._get_tax_details()
  398. self.assertTaxDetailsValues(
  399. tax_details,
  400. [
  401. {
  402. 'base_line_id': base_lines[0].id,
  403. 'tax_line_id': tax_lines[2].id,
  404. 'base_amount': -10.0,
  405. 'tax_amount': -2.0,
  406. },
  407. {
  408. 'base_line_id': base_lines[0].id,
  409. 'tax_line_id': tax_lines[1].id,
  410. 'base_amount': -100.0,
  411. 'tax_amount': -10.0,
  412. },
  413. {
  414. 'base_line_id': base_lines[0].id,
  415. 'tax_line_id': tax_lines[2].id,
  416. 'base_amount': -100.0,
  417. 'tax_amount': -20.0,
  418. },
  419. {
  420. 'base_line_id': base_lines[1].id,
  421. 'tax_line_id': tax_lines[0].id,
  422. 'base_amount': -100.0,
  423. 'tax_amount': -10.0,
  424. },
  425. ],
  426. )
  427. self.assertTotalAmounts(invoice, tax_details)
  428. def test_affect_base_amount_5(self):
  429. affecting_tax = self.env['account.tax'].create({
  430. 'name': 'Affecting',
  431. 'amount': 42,
  432. 'amount_type': 'percent',
  433. 'type_tax_use': 'sale',
  434. 'include_base_amount': True,
  435. 'sequence': 0,
  436. })
  437. affected_tax = self.env['account.tax'].create({
  438. 'name': 'Affected',
  439. 'amount': 10,
  440. 'amount_type': 'percent',
  441. 'type_tax_use': 'sale',
  442. 'sequence': 1
  443. })
  444. invoice = self.env['account.move'].create({
  445. 'move_type': 'out_invoice',
  446. 'partner_id': self.partner_a.id,
  447. 'invoice_date': '2021-08-01',
  448. 'invoice_line_ids': [
  449. Command.create({
  450. 'name': "affecting",
  451. 'account_id': self.company_data['default_account_revenue'].id,
  452. 'quantity': 1.0,
  453. 'price_unit': 100.0,
  454. 'tax_ids': affecting_tax.ids,
  455. }),
  456. Command.create({
  457. 'name': "affected",
  458. 'account_id': self.company_data['default_account_revenue'].id,
  459. 'quantity': 1.0,
  460. 'price_unit': 100.0,
  461. 'tax_ids': affected_tax.ids,
  462. }),
  463. Command.create({
  464. 'name': "affecting + affected",
  465. 'account_id': self.company_data['default_account_revenue'].id,
  466. 'quantity': 1.0,
  467. 'price_unit': 100.0,
  468. 'tax_ids': (affecting_tax + affected_tax).ids,
  469. }),
  470. ]
  471. })
  472. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  473. tax_details = self._get_tax_details()
  474. self.assertTaxDetailsValues(
  475. tax_details,
  476. [
  477. {
  478. 'base_line_id': base_lines[0].id,
  479. 'tax_line_id': tax_lines[0].id,
  480. 'base_amount': -100.0,
  481. 'tax_amount': -42.0,
  482. },
  483. {
  484. 'base_line_id': base_lines[1].id,
  485. 'tax_line_id': tax_lines[2].id,
  486. 'base_amount': -100.0,
  487. 'tax_amount': -10.0,
  488. },
  489. {
  490. 'base_line_id': base_lines[2].id,
  491. 'tax_line_id': tax_lines[2].id,
  492. 'base_amount': -42.0,
  493. 'tax_amount': -4.2,
  494. },
  495. {
  496. 'base_line_id': base_lines[2].id,
  497. 'tax_line_id': tax_lines[2].id,
  498. 'base_amount': -100.0,
  499. 'tax_amount': -10.0,
  500. },
  501. {
  502. 'base_line_id': base_lines[2].id,
  503. 'tax_line_id': tax_lines[1].id,
  504. 'base_amount': -100.0,
  505. 'tax_amount': -42.0,
  506. },
  507. ],
  508. )
  509. self.assertTotalAmounts(invoice, tax_details)
  510. def test_affect_base_amount_6(self):
  511. affecting_tax = self.env['account.tax'].create({
  512. 'name': 'Affecting',
  513. 'amount': 42,
  514. 'amount_type': 'percent',
  515. 'type_tax_use': 'sale',
  516. 'include_base_amount': True,
  517. 'sequence': 0,
  518. })
  519. affected_tax = self.env['account.tax'].create({
  520. 'name': 'Affected',
  521. 'amount': 10,
  522. 'amount_type': 'percent',
  523. 'type_tax_use': 'sale',
  524. 'sequence': 1
  525. })
  526. invoice = self.env['account.move'].create({
  527. 'move_type': 'out_invoice',
  528. 'partner_id': self.partner_a.id,
  529. 'invoice_date': '2021-08-01',
  530. 'invoice_line_ids': [
  531. Command.create({
  532. 'name': "affecting + affected",
  533. 'account_id': self.company_data['default_account_revenue'].id,
  534. 'quantity': 1.0,
  535. 'price_unit': 100.0,
  536. 'tax_ids': (affecting_tax + affected_tax).ids,
  537. }),
  538. ]
  539. })
  540. invoice.write({'invoice_line_ids': [Command.delete(invoice.invoice_line_ids.id)]})
  541. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  542. self.assertFalse(base_lines)
  543. self.assertFalse(tax_lines)
  544. tax_details = self._get_tax_details()
  545. self.assertFalse(tax_details)
  546. def test_round_globally_rounding(self):
  547. self.env.company.tax_calculation_rounding_method = 'round_globally'
  548. tax_50 = self.env['account.tax'].create({
  549. 'name': "tax_50",
  550. 'amount_type': 'percent',
  551. 'amount': 50.0,
  552. })
  553. invoice = self.env['account.move'].create({
  554. 'move_type': 'out_invoice',
  555. 'partner_id': self.partner_a.id,
  556. 'invoice_date': '2019-01-01',
  557. 'invoice_line_ids': [
  558. Command.create({
  559. 'name': 'line%s' % i,
  560. 'account_id': self.company_data['default_account_revenue'].id,
  561. 'price_unit': 0.01,
  562. 'tax_ids': [Command.set(tax_50.ids)],
  563. })
  564. for i in range(7)]
  565. })
  566. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  567. tax_details = self._get_tax_details()
  568. self.assertTaxDetailsValues(
  569. tax_details,
  570. [
  571. {
  572. 'base_line_id': base_lines[0].id,
  573. 'tax_line_id': tax_lines.id,
  574. 'base_amount': -0.01,
  575. 'tax_amount': -0.01,
  576. },
  577. {
  578. 'base_line_id': base_lines[1].id,
  579. 'tax_line_id': tax_lines.id,
  580. 'base_amount': -0.01,
  581. 'tax_amount': 0.0,
  582. },
  583. {
  584. 'base_line_id': base_lines[2].id,
  585. 'tax_line_id': tax_lines.id,
  586. 'base_amount': -0.01,
  587. 'tax_amount': -0.01,
  588. },
  589. {
  590. 'base_line_id': base_lines[3].id,
  591. 'tax_line_id': tax_lines.id,
  592. 'base_amount': -0.01,
  593. 'tax_amount': 0.00,
  594. },
  595. {
  596. 'base_line_id': base_lines[4].id,
  597. 'tax_line_id': tax_lines.id,
  598. 'base_amount': -0.01,
  599. 'tax_amount': -0.01,
  600. },
  601. {
  602. 'base_line_id': base_lines[5].id,
  603. 'tax_line_id': tax_lines.id,
  604. 'base_amount': -0.01,
  605. 'tax_amount': 0.0,
  606. },
  607. {
  608. 'base_line_id': base_lines[6].id,
  609. 'tax_line_id': tax_lines.id,
  610. 'base_amount': -0.01,
  611. 'tax_amount': -0.01,
  612. },
  613. ],
  614. )
  615. self.assertTotalAmounts(invoice, tax_details)
  616. def test_round_per_line_update(self):
  617. self.env.company.tax_calculation_rounding_method = 'round_per_line'
  618. tax_8 = self.env['account.tax'].create({
  619. 'name': "tax_8",
  620. 'amount_type': 'percent',
  621. 'amount': 8.0,
  622. })
  623. invoice = self.env['account.move'].create({
  624. 'move_type': 'out_invoice',
  625. 'partner_id': self.partner_a.id,
  626. 'invoice_date': '2019-01-01',
  627. 'invoice_cash_rounding_id': self.cash_rounding_b.id,
  628. 'invoice_line_ids': [
  629. Command.create({
  630. 'name': 'line1',
  631. 'account_id': self.company_data['default_account_revenue'].id,
  632. 'price_unit': 45.45,
  633. 'tax_ids': [Command.set(tax_8.ids)],
  634. })
  635. ]
  636. })
  637. invoice.invoice_line_ids.write({"price_unit": 4545})
  638. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  639. tax_details = self._get_tax_details()
  640. self.assertTaxDetailsValues(
  641. tax_details,
  642. [
  643. {
  644. 'base_line_id': base_lines[0].id,
  645. 'tax_line_id': tax_lines[0].id,
  646. 'base_amount': -4545.0,
  647. 'tax_amount': -363.6,
  648. },
  649. ],
  650. )
  651. self.assertTotalAmounts(invoice, tax_details)
  652. def test_partitioning_lines_by_moves(self):
  653. tax_20_affect = self.env['account.tax'].create({
  654. 'name': "tax_20_affect",
  655. 'amount_type': 'percent',
  656. 'amount': 20.0,
  657. 'include_base_amount': True,
  658. })
  659. tax_10 = self.env['account.tax'].create({
  660. 'name': "tax_10",
  661. 'amount_type': 'percent',
  662. 'amount': 10.0,
  663. })
  664. invoices = self.env['account.move']
  665. expected_values_list = []
  666. for i in range(1, 6):
  667. invoice = invoices.create({
  668. 'move_type': 'out_invoice',
  669. 'partner_id': self.partner_a.id,
  670. 'invoice_date': '2019-01-01',
  671. 'invoice_line_ids': [
  672. Command.create({
  673. 'name': 'line1',
  674. 'account_id': self.company_data['default_account_revenue'].id,
  675. 'price_unit': i * 1000.0,
  676. 'tax_ids': [Command.set((tax_20_affect + tax_10).ids)],
  677. }),
  678. ]
  679. })
  680. invoices |= invoice
  681. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  682. expected_values_list += [
  683. {
  684. 'base_line_id': base_lines[0].id,
  685. 'tax_line_id': tax_lines[1].id,
  686. 'base_amount': -200.0 * i,
  687. 'tax_amount': -20.0 * i,
  688. },
  689. {
  690. 'base_line_id': base_lines[0].id,
  691. 'tax_line_id': tax_lines[1].id,
  692. 'base_amount': -1000.0 * i,
  693. 'tax_amount': -100.0 * i,
  694. },
  695. {
  696. 'base_line_id': base_lines[0].id,
  697. 'tax_line_id': tax_lines[0].id,
  698. 'base_amount': -1000.0 * i,
  699. 'tax_amount': -200.0 * i,
  700. },
  701. ]
  702. tax_details = self._get_tax_details()
  703. self.assertTaxDetailsValues(tax_details, expected_values_list)
  704. self.assertTotalAmounts(invoices, tax_details)
  705. def test_fixed_tax_with_negative_quantity(self):
  706. fixed_tax = self.env['account.tax'].create({
  707. 'name': "fixed_tax",
  708. 'amount_type': 'fixed',
  709. 'amount': 10.0,
  710. })
  711. invoice = self.env['account.move'].create({
  712. 'move_type': 'out_invoice',
  713. 'partner_id': self.partner_a.id,
  714. 'invoice_date': '2019-01-01',
  715. 'invoice_line_ids': [
  716. Command.create({
  717. 'name': 'line1',
  718. 'account_id': self.company_data['default_account_revenue'].id,
  719. 'price_unit': 100.0,
  720. 'quantity': 5,
  721. 'tax_ids': [Command.set(fixed_tax.ids)],
  722. }),
  723. Command.create({
  724. 'name': 'line2',
  725. 'account_id': self.company_data['default_account_revenue'].id,
  726. 'price_unit': 100.0,
  727. 'quantity': 9,
  728. 'tax_ids': [Command.set(fixed_tax.ids)],
  729. }),
  730. Command.create({
  731. 'name': 'line3',
  732. 'account_id': self.company_data['default_account_revenue'].id,
  733. 'price_unit': 100.0,
  734. 'quantity': -4,
  735. 'tax_ids': [Command.set(fixed_tax.ids)],
  736. }),
  737. ]
  738. })
  739. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  740. tax_details = self._get_tax_details()
  741. self.assertTaxDetailsValues(
  742. tax_details,
  743. [
  744. {
  745. 'base_line_id': base_lines[0].id,
  746. 'tax_line_id': tax_lines[0].id,
  747. 'base_amount': -500.0,
  748. 'tax_amount': -50.0,
  749. },
  750. {
  751. 'base_line_id': base_lines[1].id,
  752. 'tax_line_id': tax_lines[0].id,
  753. 'base_amount': -900.0,
  754. 'tax_amount': -90.0,
  755. },
  756. {
  757. 'base_line_id': base_lines[2].id,
  758. 'tax_line_id': tax_lines[0].id,
  759. 'base_amount': 400.0,
  760. 'tax_amount': 40.0,
  761. },
  762. ],
  763. )
  764. self.assertTotalAmounts(invoice, tax_details)
  765. def test_percent_tax_with_negative_balance(self):
  766. percent_tax = self.env['account.tax'].create({
  767. 'name': "percent_tax",
  768. 'amount_type': 'percent',
  769. 'amount': 10.0,
  770. })
  771. invoice = self.env['account.move'].create({
  772. 'move_type': 'out_invoice',
  773. 'partner_id': self.partner_a.id,
  774. 'invoice_date': '2019-01-01',
  775. 'invoice_line_ids': [
  776. Command.create({
  777. 'name': 'line1',
  778. 'account_id': self.company_data['default_account_revenue'].id,
  779. 'price_unit': 500.0,
  780. 'tax_ids': [Command.set(percent_tax.ids)],
  781. }),
  782. Command.create({
  783. 'name': 'line2',
  784. 'account_id': self.company_data['default_account_revenue'].id,
  785. 'price_unit': 900.0,
  786. 'tax_ids': [Command.set(percent_tax.ids)],
  787. }),
  788. Command.create({
  789. 'name': 'line3',
  790. 'account_id': self.company_data['default_account_revenue'].id,
  791. 'price_unit': -400.0,
  792. 'tax_ids': [Command.set(percent_tax.ids)],
  793. }),
  794. ]
  795. })
  796. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  797. tax_details = self._get_tax_details()
  798. self.assertTaxDetailsValues(
  799. tax_details,
  800. [
  801. {
  802. 'base_line_id': base_lines[0].id,
  803. 'tax_line_id': tax_lines[0].id,
  804. 'base_amount': -500.0,
  805. 'tax_amount': -50.0,
  806. },
  807. {
  808. 'base_line_id': base_lines[1].id,
  809. 'tax_line_id': tax_lines[0].id,
  810. 'base_amount': -900.0,
  811. 'tax_amount': -90.0,
  812. },
  813. {
  814. 'base_line_id': base_lines[2].id,
  815. 'tax_line_id': tax_lines[0].id,
  816. 'base_amount': 400.0,
  817. 'tax_amount': 40.0,
  818. },
  819. ],
  820. )
  821. self.assertTotalAmounts(invoice, tax_details)
  822. def test_fixed_tax_with_negative_balance(self):
  823. fixed_tax = self.env['account.tax'].create({
  824. 'name': "fixed_tax",
  825. 'amount_type': 'fixed',
  826. 'amount': 10.0,
  827. })
  828. invoice = self.env['account.move'].create({
  829. 'move_type': 'out_invoice',
  830. 'partner_id': self.partner_a.id,
  831. 'invoice_date': '2019-01-01',
  832. 'invoice_line_ids': [
  833. Command.create({
  834. 'name': 'line1',
  835. 'account_id': self.company_data['default_account_revenue'].id,
  836. 'price_unit': 500.0,
  837. 'tax_ids': [Command.set(fixed_tax.ids)],
  838. }),
  839. Command.create({
  840. 'name': 'line2',
  841. 'account_id': self.company_data['default_account_revenue'].id,
  842. 'price_unit': 900.0,
  843. 'tax_ids': [Command.set(fixed_tax.ids)],
  844. }),
  845. Command.create({
  846. 'name': 'line3',
  847. 'account_id': self.company_data['default_account_revenue'].id,
  848. 'price_unit': -400.0,
  849. 'tax_ids': [Command.set(fixed_tax.ids)],
  850. }),
  851. ]
  852. })
  853. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  854. tax_details = self._get_tax_details()
  855. self.assertTaxDetailsValues(
  856. tax_details,
  857. [
  858. {
  859. 'base_line_id': base_lines[0].id,
  860. 'tax_line_id': tax_lines[0].id,
  861. 'base_amount': -500.0,
  862. 'tax_amount': -10.0,
  863. },
  864. {
  865. 'base_line_id': base_lines[1].id,
  866. 'tax_line_id': tax_lines[0].id,
  867. 'base_amount': -900.0,
  868. 'tax_amount': -10.0,
  869. },
  870. {
  871. 'base_line_id': base_lines[2].id,
  872. 'tax_line_id': tax_lines[0].id,
  873. 'base_amount': 400.0,
  874. 'tax_amount': 10.0,
  875. },
  876. ],
  877. )
  878. self.assertTotalAmounts(invoice, tax_details)
  879. def test_multiple_same_tax_lines(self):
  880. """ In expense, the same tax line could be generated multiple times. """
  881. percent_tax = self.env['account.tax'].create({
  882. 'name': "percent_tax",
  883. 'amount_type': 'percent',
  884. 'amount': 10.0,
  885. })
  886. tax_rep = percent_tax.refund_repartition_line_ids.filtered(lambda x: x.repartition_type == 'tax')
  887. move = self.env['account.move'].with_context(skip_invoice_sync=True).create({
  888. 'date': '2019-01-01',
  889. 'line_ids': [
  890. # Base lines
  891. Command.create({
  892. 'name': 'base1',
  893. 'debit': 1000.0,
  894. 'credit': 0.0,
  895. 'account_id': self.company_data['default_account_revenue'].id,
  896. 'tax_ids': [Command.set(percent_tax.ids)],
  897. }),
  898. Command.create({
  899. 'name': 'base2',
  900. 'debit': 10000.0,
  901. 'credit': 0.0,
  902. 'account_id': self.company_data['default_account_revenue'].id,
  903. 'tax_ids': [Command.set(percent_tax.ids)],
  904. }),
  905. # Tax lines
  906. Command.create({
  907. 'name': 'tax1',
  908. 'debit': 100.0,
  909. 'credit': 0.0,
  910. 'account_id': self.company_data['default_account_revenue'].id,
  911. 'tax_repartition_line_id': tax_rep.id,
  912. }),
  913. Command.create({
  914. 'name': 'tax1',
  915. 'debit': 1000.0,
  916. 'credit': 0.0,
  917. 'account_id': self.company_data['default_account_revenue'].id,
  918. 'tax_repartition_line_id': tax_rep.id,
  919. }),
  920. # Balance
  921. Command.create({
  922. 'name': 'balance',
  923. 'debit': 0.0,
  924. 'credit': 12100.0,
  925. 'account_id': self.company_data['default_account_receivable'].id,
  926. }),
  927. ],
  928. })
  929. base_lines, tax_lines = self._dispatch_move_lines(move)
  930. tax_details = self._get_tax_details()
  931. self.assertTaxDetailsValues(
  932. tax_details,
  933. [
  934. {
  935. 'base_line_id': base_lines[0].id,
  936. 'tax_line_id': tax_lines[0].id,
  937. 'base_amount': 1000.0,
  938. 'tax_amount': 9.09,
  939. },
  940. {
  941. 'base_line_id': base_lines[0].id,
  942. 'tax_line_id': tax_lines[1].id,
  943. 'base_amount': 1000.0,
  944. 'tax_amount': 90.91,
  945. },
  946. {
  947. 'base_line_id': base_lines[1].id,
  948. 'tax_line_id': tax_lines[0].id,
  949. 'base_amount': 10000.0,
  950. 'tax_amount': 90.91,
  951. },
  952. {
  953. 'base_line_id': base_lines[1].id,
  954. 'tax_line_id': tax_lines[1].id,
  955. 'base_amount': 10000.0,
  956. 'tax_amount': 909.09,
  957. },
  958. ],
  959. )
  960. self.assertTotalAmounts(move, tax_details)
  961. def test_multiple_same_tax_lines_multi_currencies_manual_edition(self):
  962. percent_tax = self.env['account.tax'].create({
  963. 'name': "percent_tax",
  964. 'amount_type': 'percent',
  965. 'amount': 10.0,
  966. })
  967. tax_rep = percent_tax.refund_repartition_line_ids.filtered(lambda x: x.repartition_type == 'tax')
  968. move = self.env['account.move'].with_context(skip_invoice_sync=True).create({
  969. 'date': '2019-01-01',
  970. 'line_ids': [
  971. # Base lines
  972. Command.create({
  973. 'name': 'base1',
  974. 'debit': 1200.0,
  975. 'credit': 0.0,
  976. 'amount_currency': 2400.0,
  977. 'account_id': self.company_data['default_account_revenue'].id,
  978. 'currency_id': self.currency_data['currency'].id,
  979. 'tax_ids': [Command.set(percent_tax.ids)],
  980. }),
  981. Command.create({
  982. 'name': 'base2',
  983. 'debit': 12000.0,
  984. 'credit': 0.0,
  985. 'amount_currency': 6000.0,
  986. 'account_id': self.company_data['default_account_revenue'].id,
  987. 'currency_id': self.currency_data['currency'].id,
  988. 'tax_ids': [Command.set(percent_tax.ids)],
  989. }),
  990. # Tax lines
  991. Command.create({
  992. 'name': 'tax1',
  993. 'debit': 120.0,
  994. 'credit': 0.0,
  995. 'amount_currency': 360.0,
  996. 'account_id': self.company_data['default_account_revenue'].id,
  997. 'currency_id': self.currency_data['currency'].id,
  998. 'tax_repartition_line_id': tax_rep.id,
  999. }),
  1000. Command.create({
  1001. 'name': 'tax1',
  1002. 'debit': 1200.0,
  1003. 'credit': 0.0,
  1004. 'amount_currency': 200.0,
  1005. 'account_id': self.company_data['default_account_revenue'].id,
  1006. 'currency_id': self.currency_data['currency'].id,
  1007. 'tax_repartition_line_id': tax_rep.id,
  1008. }),
  1009. # Balance
  1010. Command.create({
  1011. 'name': 'balance',
  1012. 'debit': 0.0,
  1013. 'credit': 14520.0,
  1014. 'account_id': self.company_data['default_account_receivable'].id,
  1015. }),
  1016. ],
  1017. })
  1018. base_lines, tax_lines = self._dispatch_move_lines(move)
  1019. tax_details = self._get_tax_details()
  1020. self.assertTaxDetailsValues(
  1021. tax_details,
  1022. [
  1023. {
  1024. 'base_line_id': base_lines[0].id,
  1025. 'tax_line_id': tax_lines[0].id,
  1026. 'base_amount': 1200.0,
  1027. 'tax_amount': 10.91,
  1028. 'base_amount_currency': 2400.0,
  1029. 'tax_amount_currency': 102.857, # (2400.0 / 8400.0) * (360.0 / 560.0) * 560.0
  1030. },
  1031. {
  1032. 'base_line_id': base_lines[0].id,
  1033. 'tax_line_id': tax_lines[1].id,
  1034. 'base_amount': 1200.0,
  1035. 'tax_amount': 109.09,
  1036. 'base_amount_currency': 2400.0,
  1037. 'tax_amount_currency': 57.143, # (2400.0 / 8400.0) * (200.0 / 560.0) * 560.0
  1038. },
  1039. {
  1040. 'base_line_id': base_lines[1].id,
  1041. 'tax_line_id': tax_lines[0].id,
  1042. 'base_amount': 12000.0,
  1043. 'tax_amount': 109.09,
  1044. 'base_amount_currency': 6000.0,
  1045. 'tax_amount_currency': 257.143, # (6000.0 / 8400.0) * (360.0 / 560.0) * 560.0
  1046. },
  1047. {
  1048. 'base_line_id': base_lines[1].id,
  1049. 'tax_line_id': tax_lines[1].id,
  1050. 'base_amount': 12000.0,
  1051. 'tax_amount': 1090.91,
  1052. 'base_amount_currency': 6000.0,
  1053. 'tax_amount_currency': 142.857, # (6000.0 / 8400.0) * (200.0 / 560.0) * 560.0
  1054. },
  1055. ],
  1056. )
  1057. self.assertTotalAmounts(move, tax_details)
  1058. def test_mixing_tax_inside_and_outside_a_group_of_taxes(self):
  1059. percent_tax = self.env['account.tax'].create({
  1060. 'name': "percent_tax",
  1061. 'amount_type': 'percent',
  1062. 'amount': 10.0,
  1063. })
  1064. tax_group = self.env['account.tax'].create({
  1065. 'name': "tax_group",
  1066. 'amount_type': 'group',
  1067. 'children_tax_ids': [Command.set(percent_tax.ids)],
  1068. })
  1069. invoice = self.env['account.move'].create({
  1070. 'move_type': 'out_invoice',
  1071. 'partner_id': self.partner_a.id,
  1072. 'invoice_date': '2019-01-01',
  1073. 'invoice_line_ids': [
  1074. Command.create({
  1075. 'name': 'line1',
  1076. 'account_id': self.company_data['default_account_revenue'].id,
  1077. 'price_unit': 1000.0,
  1078. 'tax_ids': [Command.set(percent_tax.ids)],
  1079. }),
  1080. Command.create({
  1081. 'name': 'line2',
  1082. 'account_id': self.company_data['default_account_revenue'].id,
  1083. 'price_unit': 1000.0,
  1084. 'tax_ids': [Command.set(tax_group.ids)],
  1085. }),
  1086. ]
  1087. })
  1088. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  1089. tax_details = self._get_tax_details()
  1090. self.assertTaxDetailsValues(
  1091. tax_details,
  1092. [
  1093. {
  1094. 'base_line_id': base_lines[0].id,
  1095. 'tax_line_id': tax_lines[0].id,
  1096. 'base_amount': -1000.0,
  1097. 'tax_amount': -100.0,
  1098. },
  1099. {
  1100. 'base_line_id': base_lines[1].id,
  1101. 'tax_line_id': tax_lines[1].id,
  1102. 'base_amount': -1000.0,
  1103. 'tax_amount': -100.0,
  1104. },
  1105. ],
  1106. )
  1107. self.assertTotalAmounts(invoice, tax_details)
  1108. def test_broken_configuration(self):
  1109. percent_tax = self.env['account.tax'].create({
  1110. 'name': "percent_tax",
  1111. 'amount_type': 'percent',
  1112. 'amount': 10.0,
  1113. })
  1114. invoice = self.env['account.move'].create({
  1115. 'move_type': 'out_invoice',
  1116. 'partner_id': self.partner_a.id,
  1117. 'invoice_date': '2019-01-01',
  1118. 'invoice_line_ids': [
  1119. Command.create({
  1120. 'name': 'line1',
  1121. 'account_id': self.company_data['default_account_revenue'].id,
  1122. 'price_unit': 1000.0,
  1123. 'tax_ids': [Command.set(percent_tax.ids)],
  1124. }),
  1125. ]
  1126. })
  1127. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  1128. # Break the configuration
  1129. tax_lines.account_id = self.company_data['default_account_assets']
  1130. tax_details = self._get_tax_details(fallback=True)
  1131. self.assertTaxDetailsValues(
  1132. tax_details,
  1133. [
  1134. {
  1135. 'base_line_id': base_lines[0].id,
  1136. 'tax_line_id': tax_lines[0].id,
  1137. 'base_amount': -1000.0,
  1138. 'tax_amount': -100.0,
  1139. },
  1140. ],
  1141. )
  1142. self.assertTotalAmounts(invoice, tax_details)
  1143. def test_tax_on_payment(self):
  1144. percent_tax = self.env['account.tax'].create({
  1145. 'name': "percent_tax",
  1146. 'amount_type': 'percent',
  1147. 'amount': 10.0,
  1148. 'tax_exigibility': 'on_payment',
  1149. 'cash_basis_transition_account_id': self.company_data['default_account_assets'].id,
  1150. })
  1151. invoice = self.env['account.move'].create({
  1152. 'move_type': 'out_invoice',
  1153. 'partner_id': self.partner_a.id,
  1154. 'invoice_date': '2019-01-01',
  1155. 'invoice_line_ids': [
  1156. Command.create({
  1157. 'name': 'line1',
  1158. 'account_id': self.company_data['default_account_revenue'].id,
  1159. 'price_unit': 1000.0,
  1160. 'tax_ids': [Command.set(percent_tax.ids)],
  1161. }),
  1162. ]
  1163. })
  1164. base_lines, tax_lines = self._dispatch_move_lines(invoice)
  1165. tax_details = self._get_tax_details()
  1166. self.assertTaxDetailsValues(
  1167. tax_details,
  1168. [
  1169. {
  1170. 'base_line_id': base_lines[0].id,
  1171. 'tax_line_id': tax_lines[0].id,
  1172. 'base_amount': -1000.0,
  1173. 'tax_amount': -100.0,
  1174. },
  1175. ],
  1176. )
  1177. self.assertTotalAmounts(invoice, tax_details)
  1178. def test_amounts_sign(self):
  1179. for tax_sign in (1, -1):
  1180. tax = self.env['account.tax'].create({
  1181. 'name': "tax",
  1182. 'amount_type': 'percent',
  1183. 'amount': tax_sign * 10.0,
  1184. })
  1185. amounts_list = [
  1186. (-1000.0, 7000.0, -2000.0),
  1187. (1000.0, -7000.0, 2000.0),
  1188. (-1000.0, -7000.0, 2000.0),
  1189. (1000.0, 7000.0, -2000.0),
  1190. ]
  1191. for amounts in amounts_list:
  1192. with self.subTest(tax_sign=tax_sign, amounts=amounts):
  1193. invoice = self.env['account.move'].create({
  1194. 'move_type': 'in_invoice',
  1195. 'partner_id': self.partner_a.id,
  1196. 'invoice_date': '2019-01-01',
  1197. 'invoice_line_ids': [
  1198. Command.create({
  1199. 'name': 'line2',
  1200. 'account_id': self.company_data['default_account_revenue'].id,
  1201. 'price_unit': amount,
  1202. 'tax_ids': [Command.set(tax.ids)],
  1203. })
  1204. for amount in amounts],
  1205. })
  1206. _base_lines, tax_lines = self._dispatch_move_lines(invoice)
  1207. tax_details = self._get_tax_details(extra_domain=[('move_id', '=', invoice.id)])
  1208. self.assertTaxDetailsValues(
  1209. tax_details,
  1210. [
  1211. {
  1212. 'tax_line_id': tax_lines[0].id,
  1213. 'base_amount': amount,
  1214. 'tax_amount': tax_sign * amount * 0.1,
  1215. }
  1216. for amount in amounts],
  1217. )
  1218. self.assertTotalAmounts(invoice, tax_details)