test_edi_xml.py 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. # coding: utf-8
  2. from .common import TestEsEdiCommon
  3. import json
  4. from freezegun import freeze_time
  5. from unittest.mock import patch
  6. from odoo.tests import tagged
  7. def mocked_l10n_es_edi_call_web_service_sign(edi_format, invoices, info_list):
  8. return {inv: {'success': True} for inv in invoices}
  9. @tagged('post_install_l10n', 'post_install', '-at_install')
  10. class TestEdiXmls(TestEsEdiCommon):
  11. @classmethod
  12. def setUpClass(cls):
  13. super().setUpClass()
  14. cls.certificate.write({
  15. 'date_start': '2019-01-01 01:00:00',
  16. 'date_end': '2021-01-01 01:00:00',
  17. })
  18. def test_010_out_invoice_s_iva10b_s_iva21s(self):
  19. with freeze_time(self.frozen_today), \
  20. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  21. new=mocked_l10n_es_edi_call_web_service_sign):
  22. invoice = self.create_invoice(
  23. partner_id=self.partner_a.id,
  24. invoice_line_ids=[
  25. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva10b').ids)]},
  26. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva21s').ids)]},
  27. ],
  28. )
  29. invoice.action_post()
  30. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  31. self.assertTrue(generated_files)
  32. json_file = json.loads(generated_files[0].decode())[0]
  33. self.assertEqual(json_file, {
  34. 'IDFactura': {
  35. 'IDEmisorFactura': {'NIF': '59962470K'},
  36. 'NumSerieFacturaEmisor': 'INV/2019/00001',
  37. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  38. },
  39. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  40. 'FacturaExpedida': {
  41. 'TipoFactura': 'F1',
  42. 'ClaveRegimenEspecialOTrascendencia': '01',
  43. 'DescripcionOperacion': 'manual',
  44. 'TipoDesglose': {
  45. 'DesgloseTipoOperacion': {
  46. 'PrestacionServicios': {
  47. 'Sujeta': {
  48. 'NoExenta': {
  49. 'TipoNoExenta': 'S1',
  50. 'DesgloseIVA': {
  51. 'DetalleIVA': [
  52. {
  53. 'TipoImpositivo': 21.0,
  54. 'BaseImponible': 200.0,
  55. 'CuotaRepercutida': 42.0,
  56. },
  57. ],
  58. },
  59. },
  60. },
  61. },
  62. 'Entrega': {
  63. 'Sujeta': {
  64. 'NoExenta': {
  65. 'TipoNoExenta': 'S1',
  66. 'DesgloseIVA': {
  67. 'DetalleIVA': [
  68. {
  69. 'TipoImpositivo': 10.0,
  70. 'BaseImponible': 100.0,
  71. 'CuotaRepercutida': 10.0,
  72. },
  73. ],
  74. },
  75. },
  76. },
  77. },
  78. },
  79. },
  80. 'ImporteTotal': 352.0,
  81. 'Contraparte': {
  82. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  83. 'NombreRazon': 'partner_a',
  84. },
  85. },
  86. })
  87. def test_020_out_invoice_s_iva10b_s_iva0_ns(self):
  88. with freeze_time(self.frozen_today), \
  89. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  90. new=mocked_l10n_es_edi_call_web_service_sign):
  91. invoice = self.create_invoice(
  92. partner_id=self.partner_b.id,
  93. invoice_line_ids=[
  94. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva10b').ids)]},
  95. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_ns').ids)]},
  96. ],
  97. )
  98. invoice.action_post()
  99. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  100. self.assertTrue(generated_files)
  101. json_file = json.loads(generated_files[0].decode())[0]
  102. self.assertEqual(json_file, {
  103. 'IDFactura': {
  104. 'IDEmisorFactura': {'NIF': '59962470K'},
  105. 'NumSerieFacturaEmisor': 'INV/2019/00001',
  106. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  107. },
  108. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  109. 'FacturaExpedida': {
  110. 'TipoFactura': 'F1',
  111. 'ClaveRegimenEspecialOTrascendencia': '01',
  112. 'DescripcionOperacion': 'manual',
  113. 'TipoDesglose': {
  114. 'DesgloseFactura': {
  115. 'Sujeta': {
  116. 'NoExenta': {
  117. 'TipoNoExenta': 'S1',
  118. 'DesgloseIVA': {
  119. 'DetalleIVA': [
  120. {
  121. 'TipoImpositivo': 10.0,
  122. 'BaseImponible': 100.0,
  123. 'CuotaRepercutida': 10.0
  124. },
  125. ],
  126. },
  127. },
  128. },
  129. },
  130. },
  131. 'ImporteTotal': 110.0,
  132. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  133. },
  134. })
  135. def test_030_out_invoice_s_iva10b_s_req014_s_iva21s_s_req52(self):
  136. with freeze_time(self.frozen_today), \
  137. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  138. new=mocked_l10n_es_edi_call_web_service_sign):
  139. invoice = self.create_invoice(
  140. partner_id=self.partner_a.id,
  141. invoice_line_ids=[
  142. {
  143. 'price_unit': 100.0,
  144. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('s_iva10b') + self._get_tax_by_xml_id('s_req014')).ids)],
  145. },
  146. {
  147. 'price_unit': 200.0,
  148. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('s_iva21s') + self._get_tax_by_xml_id('s_req52')).ids)],
  149. },
  150. ],
  151. )
  152. invoice.action_post()
  153. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  154. self.assertTrue(generated_files)
  155. json_file = json.loads(generated_files[0].decode())[0]
  156. self.assertEqual(json_file, {
  157. 'IDFactura': {
  158. 'IDEmisorFactura': {'NIF': '59962470K'},
  159. 'NumSerieFacturaEmisor': 'INV/2019/00001',
  160. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  161. },
  162. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  163. 'FacturaExpedida': {
  164. 'TipoFactura': 'F1',
  165. 'ClaveRegimenEspecialOTrascendencia': '01',
  166. 'DescripcionOperacion': 'manual',
  167. 'TipoDesglose': {
  168. 'DesgloseTipoOperacion': {
  169. 'PrestacionServicios': {
  170. 'Sujeta': {
  171. 'NoExenta': {
  172. 'TipoNoExenta': 'S1',
  173. 'DesgloseIVA': {
  174. 'DetalleIVA': [
  175. {
  176. 'TipoImpositivo': 21.0,
  177. 'BaseImponible': 200.0,
  178. 'CuotaRepercutida': 42.0,
  179. 'CuotaRecargoEquivalencia': 10.4,
  180. 'TipoRecargoEquivalencia': 5.2
  181. }
  182. ]
  183. }
  184. }
  185. }
  186. },
  187. 'Entrega': {
  188. 'Sujeta': {
  189. 'NoExenta': {
  190. 'TipoNoExenta': 'S1',
  191. 'DesgloseIVA': {
  192. 'DetalleIVA': [
  193. {
  194. 'TipoImpositivo': 10.0,
  195. 'BaseImponible': 100.0,
  196. 'CuotaRepercutida': 10.0,
  197. 'CuotaRecargoEquivalencia': 1.4,
  198. 'TipoRecargoEquivalencia': 1.4
  199. }
  200. ]
  201. }
  202. }
  203. }
  204. }
  205. }
  206. },
  207. 'ImporteTotal': 363.8,
  208. 'Contraparte': {
  209. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  210. 'NombreRazon': 'partner_a',
  211. },
  212. },
  213. })
  214. def test_040_out_refund_s_iva10b_s_iva10b_s_iva21s(self):
  215. with freeze_time(self.frozen_today), \
  216. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  217. new=mocked_l10n_es_edi_call_web_service_sign):
  218. invoice = self.create_invoice(
  219. move_type='out_refund',
  220. partner_id=self.partner_a.id,
  221. invoice_line_ids=[
  222. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva10b').ids)]},
  223. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva10b').ids)]},
  224. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva21s').ids)]},
  225. ],
  226. )
  227. invoice.action_post()
  228. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  229. self.assertTrue(generated_files)
  230. json_file = json.loads(generated_files[0].decode())[0]
  231. self.assertEqual(json_file, {
  232. 'IDFactura': {
  233. 'IDEmisorFactura': {'NIF': '59962470K'},
  234. 'NumSerieFacturaEmisor': 'RINV/2019/00001',
  235. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  236. },
  237. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  238. 'FacturaExpedida': {
  239. 'TipoFactura': 'R1',
  240. 'TipoRectificativa': 'I',
  241. 'ClaveRegimenEspecialOTrascendencia': '01',
  242. 'DescripcionOperacion': 'manual',
  243. 'TipoDesglose': {
  244. 'DesgloseTipoOperacion': {
  245. 'PrestacionServicios': {
  246. 'Sujeta': {
  247. 'NoExenta': {
  248. 'TipoNoExenta': 'S1',
  249. 'DesgloseIVA': {
  250. 'DetalleIVA': [
  251. {
  252. 'TipoImpositivo': 21.0,
  253. 'BaseImponible': -200.0,
  254. 'CuotaRepercutida': -42.0
  255. }
  256. ]
  257. }
  258. }
  259. }
  260. },
  261. 'Entrega': {
  262. 'Sujeta': {
  263. 'NoExenta': {
  264. 'TipoNoExenta': 'S1',
  265. 'DesgloseIVA': {
  266. 'DetalleIVA': [
  267. {
  268. 'TipoImpositivo': 10.0,
  269. 'BaseImponible': -200.0,
  270. 'CuotaRepercutida': -20.0
  271. }
  272. ]
  273. }
  274. }
  275. }
  276. }
  277. }
  278. },
  279. 'ImporteTotal': -462.0,
  280. 'Contraparte': {
  281. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  282. 'NombreRazon': 'partner_a',
  283. },
  284. },
  285. })
  286. def test_050_out_invoice_s_iva0_sp_i_s_iva0_ic(self):
  287. with freeze_time(self.frozen_today), \
  288. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  289. new=mocked_l10n_es_edi_call_web_service_sign):
  290. invoice = self.create_invoice(
  291. partner_id=self.partner_a.id,
  292. invoice_line_ids=[
  293. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_sp_i').ids)]},
  294. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_ic').ids)]},
  295. ],
  296. )
  297. invoice.action_post()
  298. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  299. self.assertTrue(generated_files)
  300. json_file = json.loads(generated_files[0].decode())[0]
  301. self.assertEqual(json_file, {
  302. 'IDFactura': {
  303. 'IDEmisorFactura': {'NIF': '59962470K'},
  304. 'NumSerieFacturaEmisor': 'INV/2019/00001',
  305. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  306. },
  307. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  308. 'FacturaExpedida': {
  309. 'TipoFactura': 'F1',
  310. 'ClaveRegimenEspecialOTrascendencia': '01',
  311. 'DescripcionOperacion': 'manual',
  312. 'TipoDesglose': {
  313. 'DesgloseTipoOperacion': {
  314. 'PrestacionServicios': {
  315. 'NoSujeta': {
  316. 'ImportePorArticulos7_14_Otros': 100.0
  317. },
  318. },
  319. 'Entrega': {
  320. 'Sujeta': {
  321. 'Exenta': {
  322. 'DetalleExenta': [
  323. {
  324. 'BaseImponible': 200.0,
  325. 'CausaExencion': 'E5',
  326. },
  327. ],
  328. },
  329. },
  330. },
  331. },
  332. },
  333. 'ImporteTotal': 300.0,
  334. 'Contraparte': {
  335. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  336. 'NombreRazon': 'partner_a',
  337. },
  338. },
  339. })
  340. def test_060_out_refund_s_iva0_sp_i_s_iva0_ic(self):
  341. with freeze_time(self.frozen_today), \
  342. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  343. new=mocked_l10n_es_edi_call_web_service_sign):
  344. invoice = self.create_invoice(
  345. move_type='out_refund',
  346. partner_id=self.partner_a.id,
  347. invoice_line_ids=[
  348. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_sp_i').ids)]},
  349. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_ic').ids)]},
  350. ],
  351. )
  352. invoice.action_post()
  353. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  354. self.assertTrue(generated_files)
  355. json_file = json.loads(generated_files[0].decode())[0]
  356. self.assertEqual(json_file, {
  357. 'IDFactura': {
  358. 'IDEmisorFactura': {'NIF': '59962470K'},
  359. 'NumSerieFacturaEmisor': 'RINV/2019/00001',
  360. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  361. },
  362. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  363. 'FacturaExpedida': {
  364. 'TipoFactura': 'R1',
  365. 'TipoRectificativa': 'I',
  366. 'ClaveRegimenEspecialOTrascendencia': '01',
  367. 'DescripcionOperacion': 'manual',
  368. 'TipoDesglose': {
  369. 'DesgloseTipoOperacion': {
  370. 'PrestacionServicios': {
  371. 'NoSujeta': {
  372. 'ImportePorArticulos7_14_Otros': -100.0
  373. },
  374. },
  375. 'Entrega': {
  376. 'Sujeta': {
  377. 'Exenta': {
  378. 'DetalleExenta': [
  379. {
  380. 'BaseImponible': -200.0,
  381. 'CausaExencion': 'E5',
  382. },
  383. ],
  384. },
  385. },
  386. },
  387. },
  388. },
  389. 'ImporteTotal': -300.0,
  390. 'Contraparte': {
  391. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  392. 'NombreRazon': 'partner_a',
  393. },
  394. },
  395. })
  396. def test_070_out_invoice_s_iva_e_s_iva0_e(self):
  397. with freeze_time(self.frozen_today), \
  398. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  399. new=mocked_l10n_es_edi_call_web_service_sign):
  400. invoice = self.create_invoice(
  401. partner_id=self.partner_a.id,
  402. invoice_line_ids=[
  403. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva_e').ids)]},
  404. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_e').ids)]},
  405. ],
  406. )
  407. invoice.action_post()
  408. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  409. self.assertTrue(generated_files)
  410. json_file = json.loads(generated_files[0].decode())[0]
  411. self.assertEqual(json_file, {
  412. 'IDFactura': {
  413. 'IDEmisorFactura': {'NIF': '59962470K'},
  414. 'NumSerieFacturaEmisor': 'INV/2019/00001',
  415. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  416. },
  417. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  418. 'FacturaExpedida': {
  419. 'TipoFactura': 'F1',
  420. 'ClaveRegimenEspecialOTrascendencia': '02',
  421. 'DescripcionOperacion': 'manual',
  422. 'TipoDesglose': {
  423. 'DesgloseTipoOperacion': {
  424. 'PrestacionServicios': {
  425. 'NoSujeta': {
  426. 'ImporteTAIReglasLocalizacion': 100.0,
  427. },
  428. },
  429. 'Entrega': {
  430. 'Sujeta': {
  431. 'Exenta': {
  432. 'DetalleExenta': [
  433. {
  434. 'BaseImponible': 200.0,
  435. 'CausaExencion': 'E2',
  436. },
  437. ],
  438. },
  439. },
  440. },
  441. },
  442. },
  443. 'ImporteTotal': 300.0,
  444. 'Contraparte': {
  445. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  446. 'NombreRazon': 'partner_a',
  447. },
  448. },
  449. })
  450. def test_080_out_refund_s_iva0_sp_i_s_iva0_ic(self):
  451. with freeze_time(self.frozen_today), \
  452. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  453. new=mocked_l10n_es_edi_call_web_service_sign):
  454. invoice = self.create_invoice(
  455. move_type='out_refund',
  456. partner_id=self.partner_a.id,
  457. invoice_line_ids=[
  458. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_sp_i').ids)]},
  459. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_ic').ids)]},
  460. ],
  461. )
  462. invoice.action_post()
  463. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  464. self.assertTrue(generated_files)
  465. json_file = json.loads(generated_files[0].decode())[0]
  466. self.assertEqual(json_file, {
  467. 'IDFactura': {
  468. 'IDEmisorFactura': {'NIF': '59962470K'},
  469. 'NumSerieFacturaEmisor': 'RINV/2019/00001',
  470. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  471. },
  472. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  473. 'FacturaExpedida': {
  474. 'TipoFactura': 'R1',
  475. 'TipoRectificativa': 'I',
  476. 'ClaveRegimenEspecialOTrascendencia': '01',
  477. 'DescripcionOperacion': 'manual',
  478. 'TipoDesglose': {
  479. 'DesgloseTipoOperacion': {
  480. 'PrestacionServicios': {
  481. 'NoSujeta': {
  482. 'ImportePorArticulos7_14_Otros': -100.0,
  483. },
  484. },
  485. 'Entrega': {
  486. 'Sujeta': {
  487. 'Exenta': {
  488. 'DetalleExenta': [
  489. {
  490. 'BaseImponible': -200.0,
  491. 'CausaExencion': 'E5',
  492. },
  493. ],
  494. },
  495. },
  496. },
  497. },
  498. },
  499. 'ImporteTotal': -300.0,
  500. 'Contraparte': {
  501. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  502. 'NombreRazon': 'partner_a',
  503. },
  504. },
  505. })
  506. def test_085_out_refund_s_iva0_sp_i_s_iva0_ic_multi_currency(self):
  507. with freeze_time(self.frozen_today), \
  508. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  509. new=mocked_l10n_es_edi_call_web_service_sign):
  510. invoice = self.create_invoice(
  511. move_type='out_refund',
  512. partner_id=self.partner_a.id,
  513. currency_id=self.currency_data['currency'].id,
  514. invoice_line_ids=[
  515. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_sp_i').ids)]},
  516. {'price_unit': 400.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('s_iva0_ic').ids)]},
  517. ],
  518. )
  519. invoice.action_post()
  520. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  521. self.assertTrue(generated_files)
  522. json_file = json.loads(generated_files[0].decode())[0]
  523. self.assertEqual(json_file, {
  524. 'IDFactura': {
  525. 'IDEmisorFactura': {'NIF': '59962470K'},
  526. 'NumSerieFacturaEmisor': 'RINV/2019/00001',
  527. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  528. },
  529. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  530. 'FacturaExpedida': {
  531. 'TipoFactura': 'R1',
  532. 'TipoRectificativa': 'I',
  533. 'ClaveRegimenEspecialOTrascendencia': '01',
  534. 'DescripcionOperacion': 'manual',
  535. 'TipoDesglose': {
  536. 'DesgloseTipoOperacion': {
  537. 'PrestacionServicios': {
  538. 'NoSujeta': {
  539. 'ImportePorArticulos7_14_Otros': -100.0,
  540. },
  541. },
  542. 'Entrega': {
  543. 'Sujeta': {
  544. 'Exenta': {
  545. 'DetalleExenta': [
  546. {
  547. 'BaseImponible': -200.0,
  548. 'CausaExencion': 'E5',
  549. },
  550. ],
  551. },
  552. },
  553. },
  554. },
  555. },
  556. 'ImporteTotal': -300.0,
  557. 'Contraparte': {
  558. 'IDOtro': {'ID': 'BE0477472701', 'IDType': '02'},
  559. 'NombreRazon': 'partner_a',
  560. },
  561. },
  562. })
  563. def test_090_in_invoice_p_iva10_bc_p_irpf19_p_iva21_sc_p_irpf19(self):
  564. with freeze_time(self.frozen_today), \
  565. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  566. new=mocked_l10n_es_edi_call_web_service_sign):
  567. invoice = self.create_invoice(
  568. move_type='in_invoice',
  569. ref='sup0001',
  570. partner_id=self.partner_b.id,
  571. l10n_es_registration_date='2019-01-02',
  572. invoice_line_ids=[
  573. {
  574. 'price_unit': 100.0,
  575. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('p_iva10_bc') + self._get_tax_by_xml_id('p_irpf19')).ids)],
  576. },
  577. {
  578. 'price_unit': 200.0,
  579. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('p_iva21_sc') + self._get_tax_by_xml_id('p_irpf19')).ids)],
  580. },
  581. ],
  582. )
  583. invoice.action_post()
  584. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  585. self.assertTrue(generated_files)
  586. json_file = json.loads(generated_files[0].decode())[0]
  587. self.assertEqual(json_file, {
  588. 'IDFactura': {
  589. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  590. 'NumSerieFacturaEmisor': 'sup0001',
  591. 'IDEmisorFactura': {'NIF': 'F35999705'}
  592. },
  593. 'FacturaRecibida': {
  594. 'TipoFactura': 'F1',
  595. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  596. 'DescripcionOperacion': 'manual',
  597. 'ClaveRegimenEspecialOTrascendencia': '01',
  598. 'ImporteTotal': 352.0,
  599. 'FechaRegContable': '02-01-2019',
  600. 'DesgloseFactura': {
  601. 'DesgloseIVA': {
  602. 'DetalleIVA': [
  603. {'BaseImponible': 100.0, 'CuotaSoportada': 10.0, 'TipoImpositivo': 10.0},
  604. {'BaseImponible': 200.0, 'CuotaSoportada': 42.0, 'TipoImpositivo': 21.0}
  605. ]
  606. }
  607. },
  608. 'CuotaDeducible': 52.0
  609. },
  610. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'}
  611. })
  612. def test_100_in_refund_p_iva10_bc(self):
  613. with freeze_time(self.frozen_today), \
  614. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  615. new=mocked_l10n_es_edi_call_web_service_sign):
  616. invoice = self.create_invoice(
  617. move_type='in_refund',
  618. ref='sup0001',
  619. partner_id=self.partner_b.id,
  620. l10n_es_registration_date='2019-01-02',
  621. invoice_line_ids=[{'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('p_iva10_bc').ids)]}],
  622. )
  623. invoice.action_post()
  624. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  625. self.assertTrue(generated_files)
  626. json_file = json.loads(generated_files[0].decode())[0]
  627. self.assertEqual(json_file, {
  628. 'IDFactura': {
  629. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  630. 'NumSerieFacturaEmisor': 'sup0001',
  631. 'IDEmisorFactura': {'NIF': 'F35999705'},
  632. },
  633. 'FacturaRecibida': {
  634. 'TipoFactura': 'R4',
  635. 'TipoRectificativa': 'I',
  636. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  637. 'DescripcionOperacion': 'manual',
  638. 'ClaveRegimenEspecialOTrascendencia': '01',
  639. 'ImporteTotal': -110.0,
  640. 'FechaRegContable': '02-01-2019',
  641. 'DesgloseFactura': {
  642. 'DesgloseIVA': {
  643. 'DetalleIVA': [
  644. {'BaseImponible': -100.0, 'CuotaSoportada': -10.0, 'TipoImpositivo': 10.0},
  645. ],
  646. },
  647. },
  648. 'CuotaDeducible': -10.0,
  649. },
  650. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'},
  651. })
  652. def test_110_in_invoice_p_iva10_bc_p_req014_p_iva21_sc_p_req52(self):
  653. with freeze_time(self.frozen_today), \
  654. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  655. new=mocked_l10n_es_edi_call_web_service_sign):
  656. invoice = self.create_invoice(
  657. move_type='in_invoice',
  658. ref='sup0001',
  659. partner_id=self.partner_b.id,
  660. l10n_es_registration_date='2019-01-02',
  661. invoice_line_ids=[
  662. {
  663. 'price_unit': 100.0,
  664. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('p_iva10_bc') + self._get_tax_by_xml_id('p_req014')).ids)],
  665. },
  666. {
  667. 'price_unit': 200.0,
  668. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('p_iva21_sc') + self._get_tax_by_xml_id('p_req52')).ids)],
  669. },
  670. ],
  671. )
  672. invoice.action_post()
  673. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  674. self.assertTrue(generated_files)
  675. json_file = json.loads(generated_files[0].decode())[0]
  676. self.assertEqual(json_file, {
  677. 'IDFactura': {
  678. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  679. 'NumSerieFacturaEmisor': 'sup0001',
  680. 'IDEmisorFactura': {'NIF': 'F35999705'},
  681. },
  682. 'FacturaRecibida': {
  683. 'TipoFactura': 'F1',
  684. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  685. 'DescripcionOperacion': 'manual',
  686. 'ClaveRegimenEspecialOTrascendencia': '01',
  687. 'ImporteTotal': 363.8,
  688. 'FechaRegContable': '02-01-2019',
  689. 'DesgloseFactura': {
  690. 'DesgloseIVA': {
  691. 'DetalleIVA': [
  692. {
  693. 'BaseImponible': 100.0,
  694. 'CuotaSoportada': 10.0,
  695. 'TipoImpositivo': 10.0,
  696. 'CuotaRecargoEquivalencia': 1.4,
  697. 'TipoRecargoEquivalencia': 1.4,
  698. },
  699. {
  700. 'BaseImponible': 200.0,
  701. 'CuotaSoportada': 42.0,
  702. 'TipoImpositivo': 21.0,
  703. 'CuotaRecargoEquivalencia': 10.4,
  704. 'TipoRecargoEquivalencia': 5.2,
  705. },
  706. ],
  707. },
  708. },
  709. 'CuotaDeducible': 52.0,
  710. },
  711. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'},
  712. })
  713. def test_120_in_invoice_p_iva21_sp_ex(self):
  714. with freeze_time(self.frozen_today), \
  715. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  716. new=mocked_l10n_es_edi_call_web_service_sign):
  717. invoice = self.create_invoice(
  718. move_type='in_invoice',
  719. ref='sup0001',
  720. partner_id=self.partner_b.id,
  721. l10n_es_registration_date='2019-01-02',
  722. invoice_line_ids=[{'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('p_iva21_sp_ex').ids)]}],
  723. )
  724. invoice.action_post()
  725. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  726. self.assertTrue(generated_files)
  727. json_file = json.loads(generated_files[0].decode())[0]
  728. self.assertEqual(json_file, {
  729. 'IDFactura': {
  730. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  731. 'NumSerieFacturaEmisor': 'sup0001',
  732. 'IDEmisorFactura': {'NIF': 'F35999705'},
  733. },
  734. 'FacturaRecibida': {
  735. 'TipoFactura': 'F1',
  736. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  737. 'DescripcionOperacion': 'manual',
  738. 'ClaveRegimenEspecialOTrascendencia': '01',
  739. 'ImporteTotal': 121.0,
  740. 'FechaRegContable': '02-01-2019',
  741. 'DesgloseFactura': {
  742. 'InversionSujetoPasivo': {
  743. 'DetalleIVA': [{
  744. 'BaseImponible': 100.0,
  745. 'CuotaSoportada': 21.0,
  746. 'TipoImpositivo': 21.0,
  747. }],
  748. },
  749. },
  750. 'CuotaDeducible': 21.0,
  751. },
  752. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'},
  753. })
  754. def test_130_in_invoice_p_iva0_ns_p_iva10_bc(self):
  755. # TODO make it work
  756. with freeze_time(self.frozen_today), \
  757. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  758. new=mocked_l10n_es_edi_call_web_service_sign):
  759. invoice = self.create_invoice(
  760. move_type='in_invoice',
  761. ref='sup0001',
  762. partner_id=self.partner_b.id,
  763. l10n_es_registration_date='2019-01-02',
  764. invoice_line_ids=[
  765. {'price_unit': 100.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('p_iva0_ns').ids)]},
  766. {'price_unit': 200.0, 'tax_ids': [(6, 0, self._get_tax_by_xml_id('p_iva10_bc').ids)]},
  767. ],
  768. )
  769. invoice.action_post()
  770. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  771. self.assertTrue(generated_files)
  772. json_file = json.loads(generated_files[0].decode())[0]
  773. self.assertEqual(json_file, {
  774. 'IDFactura': {
  775. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  776. 'NumSerieFacturaEmisor': 'sup0001',
  777. 'IDEmisorFactura': {'NIF': 'F35999705'},
  778. },
  779. 'FacturaRecibida': {
  780. 'TipoFactura': 'F1',
  781. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  782. 'DescripcionOperacion': 'manual',
  783. 'ClaveRegimenEspecialOTrascendencia': '01',
  784. 'ImporteTotal': 320.0,
  785. 'FechaRegContable': '02-01-2019',
  786. 'DesgloseFactura': {
  787. 'DesgloseIVA': {
  788. 'DetalleIVA': [
  789. {'BaseImponible': 100.0},
  790. {'BaseImponible': 200.0, 'TipoImpositivo': 10.0, 'CuotaSoportada': 20.0},
  791. ],
  792. },
  793. },
  794. 'CuotaDeducible': 20.0,
  795. },
  796. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'},
  797. })
  798. def test_140_out_invoice_s_iva10b_s_irpf1(self):
  799. # TODO: debug
  800. with freeze_time(self.frozen_today), \
  801. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  802. new=mocked_l10n_es_edi_call_web_service_sign):
  803. invoice = self.create_invoice(
  804. partner_id=self.partner_b.id,
  805. invoice_line_ids=[
  806. {
  807. 'price_unit': 100.0,
  808. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('s_iva10b') + self._get_tax_by_xml_id('s_irpf1')).ids)],
  809. },
  810. ],
  811. )
  812. invoice.action_post()
  813. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  814. self.assertTrue(generated_files)
  815. json_file = json.loads(generated_files[0].decode())[0]
  816. self.assertEqual(json_file, {
  817. 'IDFactura': {
  818. 'IDEmisorFactura': {'NIF': '59962470K'},
  819. 'NumSerieFacturaEmisor': 'INV/2019/00001',
  820. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  821. },
  822. 'PeriodoLiquidacion': {'Ejercicio': '2019', 'Periodo': '01'},
  823. 'FacturaExpedida': {
  824. 'TipoFactura': 'F1',
  825. 'ClaveRegimenEspecialOTrascendencia': '01',
  826. 'DescripcionOperacion': 'manual',
  827. 'TipoDesglose': {
  828. 'DesgloseFactura': {
  829. 'Sujeta': {
  830. 'NoExenta': {
  831. 'TipoNoExenta': 'S1',
  832. 'DesgloseIVA': {
  833. 'DetalleIVA': [
  834. {
  835. 'TipoImpositivo': 10.0,
  836. 'BaseImponible': 100.0,
  837. 'CuotaRepercutida': 10.0,
  838. },
  839. ],
  840. },
  841. },
  842. },
  843. },
  844. },
  845. 'ImporteTotal': 110.0,
  846. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  847. },
  848. })
  849. def test_150_in_invoice_p_iva10_bc_p_irpf1(self):
  850. with freeze_time(self.frozen_today), \
  851. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  852. new=mocked_l10n_es_edi_call_web_service_sign):
  853. invoice = self.create_invoice(
  854. move_type='in_invoice',
  855. ref='sup0001',
  856. partner_id=self.partner_b.id,
  857. l10n_es_registration_date='2019-01-02',
  858. invoice_line_ids=[
  859. {
  860. 'price_unit': 100.0,
  861. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('p_iva10_bc') + self._get_tax_by_xml_id('p_irpf1')).ids)],
  862. },
  863. ],
  864. )
  865. invoice.action_post()
  866. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  867. self.assertTrue(generated_files)
  868. json_file = json.loads(generated_files[0].decode())[0]
  869. self.assertEqual(json_file, {
  870. 'IDFactura': {
  871. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  872. 'NumSerieFacturaEmisor': 'sup0001',
  873. 'IDEmisorFactura': {'NIF': 'F35999705'},
  874. },
  875. 'FacturaRecibida': {
  876. 'TipoFactura': 'F1',
  877. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  878. 'DescripcionOperacion': 'manual',
  879. 'ClaveRegimenEspecialOTrascendencia': '01',
  880. 'ImporteTotal': 110.0,
  881. 'FechaRegContable': '02-01-2019',
  882. 'DesgloseFactura': {
  883. 'DesgloseIVA': {
  884. 'DetalleIVA': [
  885. {
  886. 'BaseImponible': 100.0,
  887. 'CuotaSoportada': 10.0,
  888. 'TipoImpositivo': 10.0,
  889. },
  890. ],
  891. },
  892. },
  893. 'CuotaDeducible': 10.0,
  894. },
  895. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'},
  896. })
  897. def test_160_in_refund_p_iva10_bc_p_irpf1(self):
  898. with freeze_time(self.frozen_today), \
  899. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  900. new=mocked_l10n_es_edi_call_web_service_sign):
  901. invoice = self.create_invoice(
  902. move_type='in_refund',
  903. ref='sup0001',
  904. partner_id=self.partner_b.id,
  905. l10n_es_registration_date='2019-01-02',
  906. invoice_line_ids=[
  907. {
  908. 'price_unit': 100.0,
  909. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('p_iva10_bc') + self._get_tax_by_xml_id('p_irpf1')).ids)],
  910. },
  911. ],
  912. )
  913. invoice.action_post()
  914. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  915. self.assertTrue(generated_files)
  916. json_file = json.loads(generated_files[0].decode())[0]
  917. self.assertEqual(json_file, {
  918. 'IDFactura': {
  919. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  920. 'NumSerieFacturaEmisor': 'sup0001',
  921. 'IDEmisorFactura': {'NIF': 'F35999705'},
  922. },
  923. 'FacturaRecibida': {
  924. 'TipoFactura': 'R4',
  925. 'TipoRectificativa': 'I',
  926. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  927. 'DescripcionOperacion': 'manual',
  928. 'ClaveRegimenEspecialOTrascendencia': '01',
  929. 'ImporteTotal': -110.0,
  930. 'FechaRegContable': '02-01-2019',
  931. 'DesgloseFactura': {
  932. 'DesgloseIVA': {
  933. 'DetalleIVA': [
  934. {
  935. 'BaseImponible': -100.0,
  936. 'CuotaSoportada': -10.0,
  937. 'TipoImpositivo': 10.0,
  938. },
  939. ],
  940. },
  941. },
  942. 'CuotaDeducible': -10.0,
  943. },
  944. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'},
  945. })
  946. def test_165_in_refund_p_iva10_bc_p_irpf1_multi_currency(self):
  947. with freeze_time(self.frozen_today), \
  948. patch('odoo.addons.l10n_es_edi_sii.models.account_edi_format.AccountEdiFormat._l10n_es_edi_call_web_service_sign',
  949. new=mocked_l10n_es_edi_call_web_service_sign):
  950. invoice = self.create_invoice(
  951. move_type='in_refund',
  952. ref='sup0001',
  953. partner_id=self.partner_b.id,
  954. currency_id=self.currency_data['currency'].id,
  955. l10n_es_registration_date='2019-01-02',
  956. invoice_line_ids=[
  957. {
  958. 'price_unit': 200.0,
  959. 'tax_ids': [(6, 0, (self._get_tax_by_xml_id('p_iva10_bc') + self._get_tax_by_xml_id('p_irpf1')).ids)],
  960. },
  961. ],
  962. )
  963. invoice.action_post()
  964. generated_files = self._process_documents_web_services(invoice, {'es_sii'})
  965. self.assertTrue(generated_files)
  966. json_file = json.loads(generated_files[0].decode())[0]
  967. self.assertEqual(json_file, {
  968. 'IDFactura': {
  969. 'FechaExpedicionFacturaEmisor': '01-01-2019',
  970. 'NumSerieFacturaEmisor': 'sup0001',
  971. 'IDEmisorFactura': {'NIF': 'F35999705'},
  972. },
  973. 'FacturaRecibida': {
  974. 'TipoFactura': 'R4',
  975. 'TipoRectificativa': 'I',
  976. 'Contraparte': {'NombreRazon': 'partner_b', 'NIF': 'F35999705'},
  977. 'DescripcionOperacion': 'manual',
  978. 'ClaveRegimenEspecialOTrascendencia': '01',
  979. 'ImporteTotal': -110.0,
  980. 'FechaRegContable': '02-01-2019',
  981. 'DesgloseFactura': {
  982. 'DesgloseIVA': {
  983. 'DetalleIVA': [
  984. {
  985. 'BaseImponible': -100.0,
  986. 'CuotaSoportada': -10.0,
  987. 'TipoImpositivo': 10.0,
  988. },
  989. ],
  990. },
  991. },
  992. 'CuotaDeducible': -10.0,
  993. },
  994. 'PeriodoLiquidacion': {'Periodo': '01', 'Ejercicio': '2019'},
  995. })