forked from elmau/empresa-libre
Fix - impuestos en prefactura
This commit is contained in:
parent
f4863db8ea
commit
a946a1aa9a
|
@ -129,8 +129,9 @@ def import_invoice():
|
||||||
obj = Productos.get(Productos.clave==row[0])
|
obj = Productos.get(Productos.clave==row[0])
|
||||||
if obj.id in products:
|
if obj.id in products:
|
||||||
vu = round(row[2], 2)
|
vu = round(row[2], 2)
|
||||||
cant = round(row[3], 2)
|
descuento = round(row[3], 2)
|
||||||
pf = products[obj.id]['valor_unitario'] - float(obj.descuento)
|
cant = round(row[4], 2)
|
||||||
|
pf = products[obj.id]['valor_unitario'] - descuento
|
||||||
products[obj.id]['cantidad'] += cant
|
products[obj.id]['cantidad'] += cant
|
||||||
products[obj.id]['importe'] = round(
|
products[obj.id]['importe'] = round(
|
||||||
pf * products[obj.id]['cantidad'], DECIMALES)
|
pf * products[obj.id]['cantidad'], DECIMALES)
|
||||||
|
@ -139,8 +140,9 @@ def import_invoice():
|
||||||
return {'ok': False, 'msg': msg}
|
return {'ok': False, 'msg': msg}
|
||||||
else:
|
else:
|
||||||
vu = round(row[2], 2)
|
vu = round(row[2], 2)
|
||||||
cant = round(row[3], 2)
|
descuento = round(row[3], 2)
|
||||||
pf = vu - float(obj.descuento)
|
cant = round(row[4], 2)
|
||||||
|
pf = vu - descuento
|
||||||
p = {
|
p = {
|
||||||
'id': obj.id,
|
'id': obj.id,
|
||||||
'delete': '-',
|
'delete': '-',
|
||||||
|
@ -3074,7 +3076,6 @@ class Facturas(BaseModel):
|
||||||
totals_tax = {}
|
totals_tax = {}
|
||||||
total_trasladados = None
|
total_trasladados = None
|
||||||
total_retenciones = None
|
total_retenciones = None
|
||||||
# ~ total_iva = 0
|
|
||||||
locales_traslados = 0
|
locales_traslados = 0
|
||||||
locales_retenciones = 0
|
locales_retenciones = 0
|
||||||
|
|
||||||
|
@ -3134,7 +3135,6 @@ class Facturas(BaseModel):
|
||||||
if tax.tipo == 'E':
|
if tax.tipo == 'E':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
invoice_tax = {
|
invoice_tax = {
|
||||||
'factura': invoice.id,
|
'factura': invoice.id,
|
||||||
'impuesto': tax.id,
|
'impuesto': tax.id,
|
||||||
|
@ -3811,12 +3811,14 @@ class PreFacturas(BaseModel):
|
||||||
return inicio
|
return inicio
|
||||||
|
|
||||||
def _calculate_totals(self, invoice, products):
|
def _calculate_totals(self, invoice, products):
|
||||||
|
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
|
||||||
subtotal = 0
|
subtotal = 0
|
||||||
descuento_cfdi = 0
|
descuento_cfdi = 0
|
||||||
totals_tax = {}
|
totals_tax = {}
|
||||||
total_trasladados = None
|
total_trasladados = None
|
||||||
total_retenciones = None
|
total_retenciones = None
|
||||||
# ~ total_iva = 0
|
locales_traslados = 0
|
||||||
|
locales_retenciones = 0
|
||||||
|
|
||||||
for product in products:
|
for product in products:
|
||||||
id_product = product.pop('id')
|
id_product = product.pop('id')
|
||||||
|
@ -3846,47 +3848,45 @@ class PreFacturas(BaseModel):
|
||||||
subtotal += importe
|
subtotal += importe
|
||||||
|
|
||||||
PreFacturasDetalle.create(**product)
|
PreFacturasDetalle.create(**product)
|
||||||
|
|
||||||
|
base = product['importe'] - product['descuento']
|
||||||
for tax in p.impuestos:
|
for tax in p.impuestos:
|
||||||
|
if tax_locales and tax.tipo == 'R' and tax.key == '000':
|
||||||
|
base = product['importe']
|
||||||
|
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
|
||||||
|
if tax.tipo == 'T' and tax.key != '000':
|
||||||
|
total_trasladados = (total_trasladados or 0) + impuesto_producto
|
||||||
|
elif tax.tipo == 'R' and tax.key != '000':
|
||||||
|
total_retenciones = (total_retenciones or 0) + impuesto_producto
|
||||||
|
elif tax.tipo == 'T' and tax.key == '000':
|
||||||
|
locales_traslados += impuesto_producto
|
||||||
|
elif tax.tipo == 'R' and tax.key == '000':
|
||||||
|
locales_retenciones += impuesto_producto
|
||||||
|
|
||||||
if tax.id in totals_tax:
|
if tax.id in totals_tax:
|
||||||
totals_tax[tax.id].importe += importe
|
totals_tax[tax.id].base += base
|
||||||
|
totals_tax[tax.id].suma_impuestos += impuesto_producto
|
||||||
else:
|
else:
|
||||||
tax.importe = importe
|
tax.base = base
|
||||||
|
tax.suma_impuestos = impuesto_producto
|
||||||
totals_tax[tax.id] = tax
|
totals_tax[tax.id] = tax
|
||||||
|
|
||||||
for tax in totals_tax.values():
|
for tax in totals_tax.values():
|
||||||
if tax.tipo == 'E' or tax.tipo == 'R':
|
if tax.tipo == 'E':
|
||||||
continue
|
continue
|
||||||
import_tax = round(float(tax.tasa) * tax.importe, DECIMALES)
|
|
||||||
total_trasladados = (total_trasladados or 0) + import_tax
|
|
||||||
# ~ if tax.name == 'IVA':
|
|
||||||
# ~ total_iva += import_tax
|
|
||||||
|
|
||||||
invoice_tax = {
|
invoice_tax = {
|
||||||
'factura': invoice.id,
|
'factura': invoice.id,
|
||||||
'impuesto': tax.id,
|
'impuesto': tax.id,
|
||||||
'base': tax.importe,
|
'base': tax.base,
|
||||||
'importe': import_tax,
|
'importe': tax.suma_impuestos,
|
||||||
}
|
}
|
||||||
PreFacturasImpuestos.create(**invoice_tax)
|
PreFacturasImpuestos.create(**invoice_tax)
|
||||||
|
|
||||||
for tax in totals_tax.values():
|
# ~ total = subtotal + (total_trasladados or 0) - (total_retenciones or 0)
|
||||||
if tax.tipo == 'E' or tax.tipo == 'T':
|
total = subtotal - descuento_cfdi + \
|
||||||
continue
|
(total_trasladados or 0) - (total_retenciones or 0) \
|
||||||
# ~ if tax.tasa == round(Decimal(2/3), 6):
|
+ locales_traslados - locales_retenciones
|
||||||
# ~ import_tax = round(float(tax.tasa) * total_iva, DECIMALES)
|
|
||||||
# ~ else:
|
|
||||||
import_tax = round(float(tax.tasa) * tax.importe, DECIMALES)
|
|
||||||
total_retenciones = (total_retenciones or 0) + import_tax
|
|
||||||
|
|
||||||
invoice_tax = {
|
|
||||||
'factura': invoice.id,
|
|
||||||
'impuesto': tax.id,
|
|
||||||
'base': tax.importe,
|
|
||||||
'importe': import_tax,
|
|
||||||
}
|
|
||||||
PreFacturasImpuestos.create(**invoice_tax)
|
|
||||||
|
|
||||||
total = subtotal + (total_trasladados or 0) - (total_retenciones or 0)
|
|
||||||
total_mn = round(total * invoice.tipo_cambio, DECIMALES)
|
total_mn = round(total * invoice.tipo_cambio, DECIMALES)
|
||||||
data = {
|
data = {
|
||||||
'subtotal': subtotal + descuento,
|
'subtotal': subtotal + descuento,
|
||||||
|
|
Loading…
Reference in New Issue