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])
|
||||
if obj.id in products:
|
||||
vu = round(row[2], 2)
|
||||
cant = round(row[3], 2)
|
||||
pf = products[obj.id]['valor_unitario'] - float(obj.descuento)
|
||||
descuento = round(row[3], 2)
|
||||
cant = round(row[4], 2)
|
||||
pf = products[obj.id]['valor_unitario'] - descuento
|
||||
products[obj.id]['cantidad'] += cant
|
||||
products[obj.id]['importe'] = round(
|
||||
pf * products[obj.id]['cantidad'], DECIMALES)
|
||||
|
@ -139,8 +140,9 @@ def import_invoice():
|
|||
return {'ok': False, 'msg': msg}
|
||||
else:
|
||||
vu = round(row[2], 2)
|
||||
cant = round(row[3], 2)
|
||||
pf = vu - float(obj.descuento)
|
||||
descuento = round(row[3], 2)
|
||||
cant = round(row[4], 2)
|
||||
pf = vu - descuento
|
||||
p = {
|
||||
'id': obj.id,
|
||||
'delete': '-',
|
||||
|
@ -3074,7 +3076,6 @@ class Facturas(BaseModel):
|
|||
totals_tax = {}
|
||||
total_trasladados = None
|
||||
total_retenciones = None
|
||||
# ~ total_iva = 0
|
||||
locales_traslados = 0
|
||||
locales_retenciones = 0
|
||||
|
||||
|
@ -3134,7 +3135,6 @@ class Facturas(BaseModel):
|
|||
if tax.tipo == 'E':
|
||||
continue
|
||||
|
||||
|
||||
invoice_tax = {
|
||||
'factura': invoice.id,
|
||||
'impuesto': tax.id,
|
||||
|
@ -3811,12 +3811,14 @@ class PreFacturas(BaseModel):
|
|||
return inicio
|
||||
|
||||
def _calculate_totals(self, invoice, products):
|
||||
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
|
||||
subtotal = 0
|
||||
descuento_cfdi = 0
|
||||
totals_tax = {}
|
||||
total_trasladados = None
|
||||
total_retenciones = None
|
||||
# ~ total_iva = 0
|
||||
locales_traslados = 0
|
||||
locales_retenciones = 0
|
||||
|
||||
for product in products:
|
||||
id_product = product.pop('id')
|
||||
|
@ -3846,47 +3848,45 @@ class PreFacturas(BaseModel):
|
|||
subtotal += importe
|
||||
|
||||
PreFacturasDetalle.create(**product)
|
||||
|
||||
base = product['importe'] - product['descuento']
|
||||
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:
|
||||
totals_tax[tax.id].importe += importe
|
||||
totals_tax[tax.id].base += base
|
||||
totals_tax[tax.id].suma_impuestos += impuesto_producto
|
||||
else:
|
||||
tax.importe = importe
|
||||
tax.base = base
|
||||
tax.suma_impuestos = impuesto_producto
|
||||
totals_tax[tax.id] = tax
|
||||
|
||||
for tax in totals_tax.values():
|
||||
if tax.tipo == 'E' or tax.tipo == 'R':
|
||||
if tax.tipo == 'E':
|
||||
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 = {
|
||||
'factura': invoice.id,
|
||||
'impuesto': tax.id,
|
||||
'base': tax.importe,
|
||||
'importe': import_tax,
|
||||
'base': tax.base,
|
||||
'importe': tax.suma_impuestos,
|
||||
}
|
||||
PreFacturasImpuestos.create(**invoice_tax)
|
||||
|
||||
for tax in totals_tax.values():
|
||||
if tax.tipo == 'E' or tax.tipo == 'T':
|
||||
continue
|
||||
# ~ if tax.tasa == round(Decimal(2/3), 6):
|
||||
# ~ 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 = subtotal + (total_trasladados or 0) - (total_retenciones or 0)
|
||||
total = subtotal - descuento_cfdi + \
|
||||
(total_trasladados or 0) - (total_retenciones or 0) \
|
||||
+ locales_traslados - locales_retenciones
|
||||
total_mn = round(total * invoice.tipo_cambio, DECIMALES)
|
||||
data = {
|
||||
'subtotal': subtotal + descuento,
|
||||
|
|
Loading…
Reference in New Issue