Skip to content

Commit 4e231cc

Browse files
authored
Merge pull request #180 from gisce/fix_fecha_operacion_only_tax_unavailables
Añadir Fecha operación cuando haya un tipo impositivo que no sea vigente
2 parents c2f3a28 + 38072cf commit 4e231cc

File tree

3 files changed

+455
-30
lines changed

3 files changed

+455
-30
lines changed

sii/resource.py

+24-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
SIGN = {'N': 1, 'R': 1, 'A': -1, 'B': -1, 'RA': 1, 'C': 1, 'G': 1} # 'BRA': -1
1212

13+
TIPO_IMPOSITIVA_NO_VIGENTES = {'5.00': '2024-09-30'}
1314

1415
def is_inversion_sujeto_pasivo(tax_name):
1516
regex_isp = r'inv.*sujeto pasivo'
@@ -342,10 +343,6 @@ def get_fact_rect_sustitucion_fields(invoice, opcion=False):
342343
rectificativa_fields = {
343344
'TipoRectificativa': 'S' # Por sustitución
344345
}
345-
346-
if 'out_' in invoice.type:
347-
pass
348-
#rectificativa_fields['FechaOperacion'] = get_fecha_operacion_rec(invoice)
349346

350347
if opcion == 1:
351348
factura_rectificada = invoice.rectifying_id
@@ -434,19 +431,37 @@ def get_factura_emitida(invoice, rect_sust_opc1=False, rect_sust_opc2=False):
434431
factura_expedida['DatosInmueble'] = {
435432
'DetalleInmueble': detalle_inmueble
436433
}
434+
435+
DetalleIVA = factura_expedida['TipoDesglose'].get(
436+
'DesgloseFactura', {}).get('Sujeta', {}).get('NoExenta', {}).get(
437+
'DesgloseIVA', {}).get('DetalleIVA', [])
438+
tipo_impositivo_no_vigente = False
439+
if DetalleIVA:
440+
for detalle in DetalleIVA:
441+
tipo_imp_detalle = '{}'.format(detalle.get('TipoImpositivo', None))
442+
if tipo_imp_detalle in TIPO_IMPOSITIVA_NO_VIGENTES:
443+
tipo_impositivo_no_vigente = TIPO_IMPOSITIVA_NO_VIGENTES[tipo_imp_detalle]
444+
break
445+
437446
if invoice.rectificative_type in ('A', 'B'):
438-
pass
439-
# factura_expedida.update(
440-
# {'FechaOperacion': get_fecha_operacion_rec(invoice)}
441-
# )
447+
if tipo_impositivo_no_vigente:
448+
if invoice.date_invoice > tipo_impositivo_no_vigente:
449+
factura_expedida.update(
450+
{'FechaOperacion': get_fecha_operacion_rec(invoice)}
451+
)
442452
if rectificativa:
443453
opcion = 0
444454
if rect_sust_opc1:
445455
opcion = 1
446456
elif rect_sust_opc2:
447457
opcion = 2
448458
vals = get_fact_rect_sustitucion_fields(invoice, opcion=opcion)
449-
459+
if opcion == 2:
460+
if tipo_impositivo_no_vigente:
461+
if invoice.date_invoice > tipo_impositivo_no_vigente:
462+
factura_expedida.update(
463+
{'FechaOperacion': get_fecha_operacion_rec(invoice)}
464+
)
450465
fact_rect = invoice.rectifying_id
451466
if fact_rect and fact_rect.sii_registered:
452467
numero_factura = fact_rect.number

spec/serialization_spec.py

+190-19
Original file line numberDiff line numberDiff line change
@@ -929,22 +929,20 @@ def group_by_tax_rate(iva_values, in_invoice):
929929
['RegistroLRFacturasEmitidas']
930930
)
931931
with context('en los datos de abonadora'):
932-
with it('la FechaOperacion debe ser por factura original'):
933-
pass
934-
# expect(
935-
# self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
936-
# ).to(equal('31-12-2016'))
932+
with it('la FechaOperacion NO debe ser informado'):
933+
expect(
934+
self.fact_refund_emit['FacturaExpedida'].get('FechaOperacion', False)
935+
).to(equal(False))
937936
with context('en los datos de rectificación'):
938937
with it('el TipoRectificativa debe ser por sustitución (S)'):
939938
expect(
940939
self.fact_rect_emit['FacturaExpedida']['TipoRectificativa']
941940
).to(equal('S'))
942941

943-
with it('la FechaOperacion debe ser por factura original'):
944-
pass
945-
# expect(
946-
# self.fact_rect_emit['FacturaExpedida']['FechaOperacion']
947-
# ).to(equal('31-12-2016'))
942+
with it('la FechaOperacion NO debe ser informado'):
943+
expect(
944+
self.fact_rect_emit['FacturaExpedida'].get('FechaOperacion', False)
945+
).to(equal(False))
948946

949947
with before.all:
950948
self.importe_rectificacion = (
@@ -992,6 +990,181 @@ def group_by_tax_rate(iva_values, in_invoice):
992990
self.out_refund.tax_line[0].tax_id.amount * 100
993991
))
994992

993+
with description('en los datos de una factura rectificativa emitida con IVA 5% fecha postrior vigencia'):
994+
with before.all:
995+
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_invoice_iva5()
996+
self.out_refund_obj = SII(self.out_refund).generate_object()
997+
self.out_b_inovice_obj = SII(self.out_b_inovice).generate_object()
998+
self.fact_rect_emit = (
999+
self.out_refund_obj['SuministroLRFacturasEmitidas']
1000+
['RegistroLRFacturasEmitidas']
1001+
)
1002+
self.fact_refund_emit = (
1003+
self.out_b_inovice_obj['SuministroLRFacturasEmitidas']
1004+
['RegistroLRFacturasEmitidas']
1005+
)
1006+
with context('en los datos de abonadora'):
1007+
with it('la FechaOperacion debe ser por factura original'):
1008+
expect(
1009+
self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
1010+
).to(equal('01-01-2023'))
1011+
with context('en los datos de rectificación'):
1012+
with it('el TipoRectificativa debe ser por sustitución (S)'):
1013+
expect(
1014+
self.fact_rect_emit['FacturaExpedida']['TipoRectificativa']
1015+
).to(equal('S'))
1016+
1017+
with it('la FechaOperacion debe ser por factura original'):
1018+
expect(
1019+
self.fact_rect_emit['FacturaExpedida']['FechaOperacion']
1020+
).to(equal('01-01-2023'))
1021+
1022+
with before.all:
1023+
self.importe_rectificacion = (
1024+
self.fact_rect_emit['FacturaExpedida']
1025+
['ImporteRectificacion']
1026+
)
1027+
1028+
with it('la BaseRectificada debe ser 0'):
1029+
expect(
1030+
self.importe_rectificacion['BaseRectificada']
1031+
).to(equal(0))
1032+
1033+
with it('la CuotaRectificada debe ser 0'):
1034+
expect(
1035+
self.importe_rectificacion['CuotaRectificada']
1036+
).to(equal(0))
1037+
1038+
with context('en los detalles del IVA'):
1039+
with before.all:
1040+
detalle_iva = (
1041+
self.fact_rect_emit['FacturaExpedida']['TipoDesglose']
1042+
['DesgloseFactura']['Sujeta']['NoExenta']['DesgloseIVA']
1043+
['DetalleIVA']
1044+
)
1045+
self.grouped_detalle_iva = group_by_tax_rate(
1046+
detalle_iva, in_invoice=False
1047+
)
1048+
1049+
with it('la BaseImponible debe ser la original'):
1050+
expect(
1051+
self.grouped_detalle_iva[5.0]['BaseImponible']
1052+
).to(equal(
1053+
self.out_refund.tax_line[0].base
1054+
))
1055+
with it('la CuotaRepercutida debe ser la original'):
1056+
expect(
1057+
self.grouped_detalle_iva[5.0]['CuotaRepercutida']
1058+
).to(equal(
1059+
-1 * abs(self.out_refund.tax_line[0].tax_amount)
1060+
))
1061+
with it('el TipoImpositivo debe ser la original'):
1062+
expect(
1063+
self.grouped_detalle_iva[5.0]['TipoImpositivo']
1064+
).to(equal(
1065+
self.out_refund.tax_line[0].tax_id.amount * 100
1066+
))
1067+
1068+
with description('en los datos de una factura rectificativa emitida con IVA 5% fecha en vigencia'):
1069+
with before.all:
1070+
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_invoice_iva5(fecha_facturas_recti='2024-03-18')
1071+
self.out_refund_obj = SII(self.out_refund).generate_object()
1072+
self.out_b_inovice_obj = SII(self.out_b_inovice).generate_object()
1073+
self.fact_rect_emit = (
1074+
self.out_refund_obj['SuministroLRFacturasEmitidas']
1075+
['RegistroLRFacturasEmitidas']
1076+
)
1077+
self.fact_refund_emit = (
1078+
self.out_b_inovice_obj['SuministroLRFacturasEmitidas']
1079+
['RegistroLRFacturasEmitidas']
1080+
)
1081+
with context('en los datos de abonadora'):
1082+
with it('la FechaOperacion debe ser por factura original'):
1083+
expect(
1084+
self.fact_refund_emit['FacturaExpedida'].get(
1085+
'FechaOperacion', False)
1086+
).to(equal(False))
1087+
with context('en los datos de rectificación'):
1088+
with it('el TipoRectificativa debe ser por sustitución (S)'):
1089+
expect(
1090+
self.fact_rect_emit['FacturaExpedida']['TipoRectificativa']
1091+
).to(equal('S'))
1092+
1093+
with it('la FechaOperacion no debe existir'):
1094+
expect(
1095+
self.fact_rect_emit['FacturaExpedida'].get('FechaOperacion', False)
1096+
).to(equal(False))
1097+
1098+
with before.all:
1099+
self.importe_rectificacion = (
1100+
self.fact_rect_emit['FacturaExpedida']
1101+
['ImporteRectificacion']
1102+
)
1103+
1104+
with it('la BaseRectificada debe ser 0'):
1105+
expect(
1106+
self.importe_rectificacion['BaseRectificada']
1107+
).to(equal(0))
1108+
1109+
with it('la CuotaRectificada debe ser 0'):
1110+
expect(
1111+
self.importe_rectificacion['CuotaRectificada']
1112+
).to(equal(0))
1113+
1114+
with context('en los detalles del IVA'):
1115+
with before.all:
1116+
detalle_iva = (
1117+
self.fact_rect_emit['FacturaExpedida']['TipoDesglose']
1118+
['DesgloseFactura']['Sujeta']['NoExenta']['DesgloseIVA']
1119+
['DetalleIVA']
1120+
)
1121+
self.grouped_detalle_iva = group_by_tax_rate(
1122+
detalle_iva, in_invoice=False
1123+
)
1124+
1125+
with it('la BaseImponible debe ser la original'):
1126+
expect(
1127+
self.grouped_detalle_iva[5.0]['BaseImponible']
1128+
).to(equal(
1129+
self.out_refund.tax_line[0].base
1130+
))
1131+
with it('la CuotaRepercutida debe ser la original'):
1132+
expect(
1133+
self.grouped_detalle_iva[5.0]['CuotaRepercutida']
1134+
).to(equal(
1135+
-1 * abs(self.out_refund.tax_line[0].tax_amount)
1136+
))
1137+
with it('el TipoImpositivo debe ser la original'):
1138+
expect(
1139+
self.grouped_detalle_iva[5.0]['TipoImpositivo']
1140+
).to(equal(
1141+
self.out_refund.tax_line[0].tax_id.amount * 100
1142+
))
1143+
1144+
with description('en los datos de una factura rectificativa de una rectificativa emitida iva 5%'):
1145+
with before.all:
1146+
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_invoice_iva5_multi()
1147+
self.out_refund_obj = SII(self.out_refund).generate_object()
1148+
self.out_b_inovice_obj = SII(self.out_b_inovice).generate_object()
1149+
self.fact_rect_emit = (
1150+
self.out_refund_obj['SuministroLRFacturasEmitidas']
1151+
['RegistroLRFacturasEmitidas']
1152+
)
1153+
self.fact_refund_emit = (
1154+
self.out_b_inovice_obj['SuministroLRFacturasEmitidas']
1155+
['RegistroLRFacturasEmitidas']
1156+
)
1157+
with context('en los datos de abonadora'):
1158+
with it('la FechaOperacion debe ser por factura original'):
1159+
expect(
1160+
self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
1161+
).to(equal('01-01-2023'))
1162+
with context('en los datos de rectificación'):
1163+
with it('la FechaOperacion debe ser por factura original'):
1164+
expect(
1165+
self.fact_rect_emit['FacturaExpedida']['FechaOperacion']
1166+
).to(equal('01-01-2023'))
1167+
9951168
with description('en los datos de una factura rectificativa de una rectificativa emitida'):
9961169
with before.all:
9971170
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_mulitple_invoice()
@@ -1007,16 +1180,14 @@ def group_by_tax_rate(iva_values, in_invoice):
10071180
)
10081181
with context('en los datos de abonadora'):
10091182
with it('la FechaOperacion debe ser por factura original'):
1010-
pass
1011-
# expect(
1012-
# self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
1013-
# ).to(equal('07-12-2023'))
1183+
expect(
1184+
self.fact_refund_emit['FacturaExpedida'].get('FechaOperacion', False)
1185+
).to(equal(False))
10141186
with context('en los datos de rectificación'):
1015-
with it('la FechaOperacion debe ser por factura original'):
1016-
pass
1017-
# expect(
1018-
# self.fact_rect_emit['FacturaExpedida']['FechaOperacion']
1019-
# ).to(equal('07-12-2023'))
1187+
with it('la FechaOperacion NO debe existir'):
1188+
expect(
1189+
self.fact_rect_emit['FacturaExpedida'].get('FechaOperacion', False)
1190+
).to(equal(False))
10201191

10211192
with description('en los datos de una factura rectificativa recibida'):
10221193
with before.all:

0 commit comments

Comments
 (0)