Skip to content

Commit

Permalink
Merge pull request #180 from gisce/fix_fecha_operacion_only_tax_unava…
Browse files Browse the repository at this point in the history
…ilables

Añadir Fecha operación cuando haya un tipo impositivo que no sea vigente
  • Loading branch information
guilleJB authored Oct 24, 2024
2 parents c2f3a28 + 38072cf commit 4e231cc
Show file tree
Hide file tree
Showing 3 changed files with 455 additions and 30 deletions.
33 changes: 24 additions & 9 deletions sii/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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

TIPO_IMPOSITIVA_NO_VIGENTES = {'5.00': '2024-09-30'}

def is_inversion_sujeto_pasivo(tax_name):
regex_isp = r'inv.*sujeto pasivo'
Expand Down Expand Up @@ -342,10 +343,6 @@ def get_fact_rect_sustitucion_fields(invoice, opcion=False):
rectificativa_fields = {
'TipoRectificativa': 'S' # Por sustitución
}

if 'out_' in invoice.type:
pass
#rectificativa_fields['FechaOperacion'] = get_fecha_operacion_rec(invoice)

if opcion == 1:
factura_rectificada = invoice.rectifying_id
Expand Down Expand Up @@ -434,19 +431,37 @@ def get_factura_emitida(invoice, rect_sust_opc1=False, rect_sust_opc2=False):
factura_expedida['DatosInmueble'] = {
'DetalleInmueble': detalle_inmueble
}

DetalleIVA = factura_expedida['TipoDesglose'].get(
'DesgloseFactura', {}).get('Sujeta', {}).get('NoExenta', {}).get(
'DesgloseIVA', {}).get('DetalleIVA', [])
tipo_impositivo_no_vigente = False
if DetalleIVA:
for detalle in DetalleIVA:
tipo_imp_detalle = '{}'.format(detalle.get('TipoImpositivo', None))
if tipo_imp_detalle in TIPO_IMPOSITIVA_NO_VIGENTES:
tipo_impositivo_no_vigente = TIPO_IMPOSITIVA_NO_VIGENTES[tipo_imp_detalle]
break

if invoice.rectificative_type in ('A', 'B'):
pass
# factura_expedida.update(
# {'FechaOperacion': get_fecha_operacion_rec(invoice)}
# )
if tipo_impositivo_no_vigente:
if invoice.date_invoice > tipo_impositivo_no_vigente:
factura_expedida.update(
{'FechaOperacion': get_fecha_operacion_rec(invoice)}
)
if rectificativa:
opcion = 0
if rect_sust_opc1:
opcion = 1
elif rect_sust_opc2:
opcion = 2
vals = get_fact_rect_sustitucion_fields(invoice, opcion=opcion)

if opcion == 2:
if tipo_impositivo_no_vigente:
if invoice.date_invoice > tipo_impositivo_no_vigente:
factura_expedida.update(
{'FechaOperacion': get_fecha_operacion_rec(invoice)}
)
fact_rect = invoice.rectifying_id
if fact_rect and fact_rect.sii_registered:
numero_factura = fact_rect.number
Expand Down
209 changes: 190 additions & 19 deletions spec/serialization_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,22 +929,20 @@ def group_by_tax_rate(iva_values, in_invoice):
['RegistroLRFacturasEmitidas']
)
with context('en los datos de abonadora'):
with it('la FechaOperacion debe ser por factura original'):
pass
# expect(
# self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
# ).to(equal('31-12-2016'))
with it('la FechaOperacion NO debe ser informado'):
expect(
self.fact_refund_emit['FacturaExpedida'].get('FechaOperacion', False)
).to(equal(False))
with context('en los datos de rectificación'):
with it('el TipoRectificativa debe ser por sustitución (S)'):
expect(
self.fact_rect_emit['FacturaExpedida']['TipoRectificativa']
).to(equal('S'))

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

with before.all:
self.importe_rectificacion = (
Expand Down Expand Up @@ -992,6 +990,181 @@ def group_by_tax_rate(iva_values, in_invoice):
self.out_refund.tax_line[0].tax_id.amount * 100
))

with description('en los datos de una factura rectificativa emitida con IVA 5% fecha postrior vigencia'):
with before.all:
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_invoice_iva5()
self.out_refund_obj = SII(self.out_refund).generate_object()
self.out_b_inovice_obj = SII(self.out_b_inovice).generate_object()
self.fact_rect_emit = (
self.out_refund_obj['SuministroLRFacturasEmitidas']
['RegistroLRFacturasEmitidas']
)
self.fact_refund_emit = (
self.out_b_inovice_obj['SuministroLRFacturasEmitidas']
['RegistroLRFacturasEmitidas']
)
with context('en los datos de abonadora'):
with it('la FechaOperacion debe ser por factura original'):
expect(
self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
).to(equal('01-01-2023'))
with context('en los datos de rectificación'):
with it('el TipoRectificativa debe ser por sustitución (S)'):
expect(
self.fact_rect_emit['FacturaExpedida']['TipoRectificativa']
).to(equal('S'))

with it('la FechaOperacion debe ser por factura original'):
expect(
self.fact_rect_emit['FacturaExpedida']['FechaOperacion']
).to(equal('01-01-2023'))

with before.all:
self.importe_rectificacion = (
self.fact_rect_emit['FacturaExpedida']
['ImporteRectificacion']
)

with it('la BaseRectificada debe ser 0'):
expect(
self.importe_rectificacion['BaseRectificada']
).to(equal(0))

with it('la CuotaRectificada debe ser 0'):
expect(
self.importe_rectificacion['CuotaRectificada']
).to(equal(0))

with context('en los detalles del IVA'):
with before.all:
detalle_iva = (
self.fact_rect_emit['FacturaExpedida']['TipoDesglose']
['DesgloseFactura']['Sujeta']['NoExenta']['DesgloseIVA']
['DetalleIVA']
)
self.grouped_detalle_iva = group_by_tax_rate(
detalle_iva, in_invoice=False
)

with it('la BaseImponible debe ser la original'):
expect(
self.grouped_detalle_iva[5.0]['BaseImponible']
).to(equal(
self.out_refund.tax_line[0].base
))
with it('la CuotaRepercutida debe ser la original'):
expect(
self.grouped_detalle_iva[5.0]['CuotaRepercutida']
).to(equal(
-1 * abs(self.out_refund.tax_line[0].tax_amount)
))
with it('el TipoImpositivo debe ser la original'):
expect(
self.grouped_detalle_iva[5.0]['TipoImpositivo']
).to(equal(
self.out_refund.tax_line[0].tax_id.amount * 100
))

with description('en los datos de una factura rectificativa emitida con IVA 5% fecha en vigencia'):
with before.all:
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_invoice_iva5(fecha_facturas_recti='2024-03-18')
self.out_refund_obj = SII(self.out_refund).generate_object()
self.out_b_inovice_obj = SII(self.out_b_inovice).generate_object()
self.fact_rect_emit = (
self.out_refund_obj['SuministroLRFacturasEmitidas']
['RegistroLRFacturasEmitidas']
)
self.fact_refund_emit = (
self.out_b_inovice_obj['SuministroLRFacturasEmitidas']
['RegistroLRFacturasEmitidas']
)
with context('en los datos de abonadora'):
with it('la FechaOperacion debe ser por factura original'):
expect(
self.fact_refund_emit['FacturaExpedida'].get(
'FechaOperacion', False)
).to(equal(False))
with context('en los datos de rectificación'):
with it('el TipoRectificativa debe ser por sustitución (S)'):
expect(
self.fact_rect_emit['FacturaExpedida']['TipoRectificativa']
).to(equal('S'))

with it('la FechaOperacion no debe existir'):
expect(
self.fact_rect_emit['FacturaExpedida'].get('FechaOperacion', False)
).to(equal(False))

with before.all:
self.importe_rectificacion = (
self.fact_rect_emit['FacturaExpedida']
['ImporteRectificacion']
)

with it('la BaseRectificada debe ser 0'):
expect(
self.importe_rectificacion['BaseRectificada']
).to(equal(0))

with it('la CuotaRectificada debe ser 0'):
expect(
self.importe_rectificacion['CuotaRectificada']
).to(equal(0))

with context('en los detalles del IVA'):
with before.all:
detalle_iva = (
self.fact_rect_emit['FacturaExpedida']['TipoDesglose']
['DesgloseFactura']['Sujeta']['NoExenta']['DesgloseIVA']
['DetalleIVA']
)
self.grouped_detalle_iva = group_by_tax_rate(
detalle_iva, in_invoice=False
)

with it('la BaseImponible debe ser la original'):
expect(
self.grouped_detalle_iva[5.0]['BaseImponible']
).to(equal(
self.out_refund.tax_line[0].base
))
with it('la CuotaRepercutida debe ser la original'):
expect(
self.grouped_detalle_iva[5.0]['CuotaRepercutida']
).to(equal(
-1 * abs(self.out_refund.tax_line[0].tax_amount)
))
with it('el TipoImpositivo debe ser la original'):
expect(
self.grouped_detalle_iva[5.0]['TipoImpositivo']
).to(equal(
self.out_refund.tax_line[0].tax_id.amount * 100
))

with description('en los datos de una factura rectificativa de una rectificativa emitida iva 5%'):
with before.all:
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_invoice_iva5_multi()
self.out_refund_obj = SII(self.out_refund).generate_object()
self.out_b_inovice_obj = SII(self.out_b_inovice).generate_object()
self.fact_rect_emit = (
self.out_refund_obj['SuministroLRFacturasEmitidas']
['RegistroLRFacturasEmitidas']
)
self.fact_refund_emit = (
self.out_b_inovice_obj['SuministroLRFacturasEmitidas']
['RegistroLRFacturasEmitidas']
)
with context('en los datos de abonadora'):
with it('la FechaOperacion debe ser por factura original'):
expect(
self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
).to(equal('01-01-2023'))
with context('en los datos de rectificación'):
with it('la FechaOperacion debe ser por factura original'):
expect(
self.fact_rect_emit['FacturaExpedida']['FechaOperacion']
).to(equal('01-01-2023'))

with description('en los datos de una factura rectificativa de una rectificativa emitida'):
with before.all:
self.out_refund, self.out_b_inovice = self.data_gen.get_out_refund_mulitple_invoice()
Expand All @@ -1007,16 +1180,14 @@ def group_by_tax_rate(iva_values, in_invoice):
)
with context('en los datos de abonadora'):
with it('la FechaOperacion debe ser por factura original'):
pass
# expect(
# self.fact_refund_emit['FacturaExpedida']['FechaOperacion']
# ).to(equal('07-12-2023'))
expect(
self.fact_refund_emit['FacturaExpedida'].get('FechaOperacion', False)
).to(equal(False))
with context('en los datos de rectificación'):
with it('la FechaOperacion debe ser por factura original'):
pass
# expect(
# self.fact_rect_emit['FacturaExpedida']['FechaOperacion']
# ).to(equal('07-12-2023'))
with it('la FechaOperacion NO debe existir'):
expect(
self.fact_rect_emit['FacturaExpedida'].get('FechaOperacion', False)
).to(equal(False))

with description('en los datos de una factura rectificativa recibida'):
with before.all:
Expand Down
Loading

0 comments on commit 4e231cc

Please sign in to comment.