Fix - Issue 58
This commit is contained in:
parent
5d1d0c8c79
commit
13053b24e3
|
@ -2343,7 +2343,7 @@ class Facturas(BaseModel):
|
|||
totals_tax = {}
|
||||
total_trasladados = None
|
||||
total_retenciones = None
|
||||
total_iva = 0
|
||||
# ~ total_iva = 0
|
||||
locales_traslados = 0
|
||||
locales_retenciones = 0
|
||||
|
||||
|
@ -2376,52 +2376,66 @@ class Facturas(BaseModel):
|
|||
|
||||
FacturasDetalle.create(**product)
|
||||
|
||||
base = product['importe'] - product['descuento']
|
||||
for tax in p.impuestos:
|
||||
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' or tax.tipo == 'R':
|
||||
if tax.tipo == 'E':
|
||||
continue
|
||||
|
||||
import_tax = round(float(tax.tasa) * tax.importe, DECIMALES)
|
||||
if tax.key == '000':
|
||||
locales_traslados += import_tax
|
||||
else:
|
||||
total_trasladados = (total_trasladados or 0) + import_tax
|
||||
if tax.name == 'IVA':
|
||||
total_iva += import_tax
|
||||
# ~ import_tax = round(float(tax.tasa) * tax.importe, DECIMALES)
|
||||
# ~ if tax.key == '000':
|
||||
# ~ locales_traslados += import_tax
|
||||
# ~ else:
|
||||
# ~ 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,
|
||||
}
|
||||
FacturasImpuestos.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)
|
||||
if tax.key == '000':
|
||||
locales_retenciones += import_tax
|
||||
else:
|
||||
total_retenciones = (total_retenciones or 0) + import_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)
|
||||
# ~ if tax.key == '000':
|
||||
# ~ locales_retenciones += import_tax
|
||||
# ~ else:
|
||||
# ~ total_retenciones = (total_retenciones or 0) + import_tax
|
||||
|
||||
invoice_tax = {
|
||||
'factura': invoice.id,
|
||||
'impuesto': tax.id,
|
||||
'base': tax.importe,
|
||||
'importe': import_tax,
|
||||
}
|
||||
FacturasImpuestos.create(**invoice_tax)
|
||||
# ~ invoice_tax = {
|
||||
# ~ 'factura': invoice.id,
|
||||
# ~ 'impuesto': tax.id,
|
||||
# ~ 'base': tax.base,
|
||||
# ~ 'importe': tax.suma_impuestos,
|
||||
# ~ }
|
||||
# ~ FacturasImpuestos.create(**invoice_tax)
|
||||
|
||||
total = subtotal - descuento_cfdi + \
|
||||
(total_trasladados or 0) - (total_retenciones or 0) \
|
||||
|
|
|
@ -702,6 +702,69 @@ function calculate_taxes(){
|
|||
}
|
||||
|
||||
|
||||
function calcular_impuestos(){
|
||||
var tmp = null
|
||||
var subtotal = 0
|
||||
var id = 2
|
||||
var grid_totals = $$('grid_totals')
|
||||
var impuesto_producto = 0
|
||||
var impuesto = null
|
||||
|
||||
table_totals.clear()
|
||||
grid_totals.clearAll()
|
||||
grid_totals.add({id: 1, concepto: 'SubTotal', importe: 0})
|
||||
|
||||
grid.eachRow(function(row){
|
||||
var product = grid.getItem(row)
|
||||
var importe = parseFloat(product.importe)
|
||||
subtotal += importe
|
||||
query = table_pt.chain().find({'product': product.id}).data()
|
||||
for(var tax of query){
|
||||
impuesto = table_taxes.findOne({'id': tax.tax})
|
||||
if(impuesto.tipo == 'E'){
|
||||
continue
|
||||
}
|
||||
|
||||
var base = importe
|
||||
if(impuesto.tipo == 'R'){
|
||||
base = (importe * -1).round(DECIMALES)
|
||||
}
|
||||
impuesto_producto = (impuesto.tasa * base).round(DECIMALES)
|
||||
|
||||
tmp = table_totals.findOne({'tax': tax.tax})
|
||||
if(tmp === null){
|
||||
table_totals.insert({'tax': tax.tax, 'importe': impuesto_producto})
|
||||
}else{
|
||||
tmp.importe += impuesto_producto
|
||||
table_totals.update(tmp)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
var tipo = ''
|
||||
var concepto = ''
|
||||
|
||||
query = table_totals.chain().data()
|
||||
for(var t of query){
|
||||
tax = table_taxes.findOne({'id': t.tax})
|
||||
if(tax.tipo == 'E'){
|
||||
continue
|
||||
}
|
||||
tipo = 'Traslado '
|
||||
if(tax.tipo == 'R'){
|
||||
tipo = 'Retención '
|
||||
}
|
||||
concepto = tipo + tax.name + ' (' + tax.tasa + ')'
|
||||
grid_totals.add({id: id, concepto: concepto, importe: t.importe})
|
||||
id += 1
|
||||
}
|
||||
|
||||
var row = {importe: subtotal}
|
||||
grid_totals.updateItem(1, row)
|
||||
}
|
||||
|
||||
|
||||
function set_product(values){
|
||||
var taxes = values.taxes
|
||||
var values = values.row
|
||||
|
@ -729,7 +792,8 @@ function set_product(values){
|
|||
table_pt.insert(v)
|
||||
}
|
||||
}
|
||||
calculate_taxes()
|
||||
//~ calculate_taxes()
|
||||
calcular_impuestos()
|
||||
}
|
||||
|
||||
|
||||
|
@ -846,7 +910,8 @@ function grid_details_before_edit_stop(state, editor){
|
|||
row['importe'] = (cantidad * precio_final).round(DECIMALES)
|
||||
|
||||
grid.refresh()
|
||||
calculate_taxes()
|
||||
//~ calculate_taxes()
|
||||
calcular_impuestos()
|
||||
}
|
||||
|
||||
|
||||
|
@ -855,7 +920,8 @@ function grid_details_click(id, e, node){
|
|||
return
|
||||
}
|
||||
grid.remove(id.row)
|
||||
calculate_taxes()
|
||||
//~ calculate_taxes()
|
||||
calcular_impuestos()
|
||||
}
|
||||
|
||||
|
||||
|
@ -874,7 +940,8 @@ function grid_details_header_click(id){
|
|||
callback:function(result){
|
||||
if (result){
|
||||
grid.clearAll()
|
||||
calculate_taxes()
|
||||
//~ calculate_taxes()
|
||||
calcular_impuestos()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -1299,7 +1366,8 @@ function refacturar_preinvoice(id){
|
|||
for(var p of values.rows){
|
||||
agregar_preproducto(p)
|
||||
}
|
||||
calculate_taxes()
|
||||
//~ calculate_taxes()
|
||||
calcular_impuestos()
|
||||
$$('tv_invoice').getTabbar().setValue('Generar')
|
||||
}
|
||||
})
|
||||
|
|
|
@ -10,7 +10,7 @@ var grid_cfdi_cliente_cols = [
|
|||
css: 'right'},
|
||||
{id: 'uuid', header: ['UUID', {content: 'textFilter'}], width: 250,
|
||||
sort: 'string'},
|
||||
{id: "fecha", header: ["Fecha y Hora"], width: 150, sort: 'date'},
|
||||
{id: "fecha", header: ["Fecha y Hora"], width: 150, sort: 'string'},
|
||||
{id: "tipo_comprobante", header: ["Tipo", {content: "selectFilter"}],
|
||||
adjust: 'header', sort: 'string'},
|
||||
{id: "estatus", header: ["Estatus", {content: "selectFilter"}],
|
||||
|
@ -202,7 +202,7 @@ var grid_invoices_cols = [
|
|||
{id: "uuid", header: ["UUID", {content: "textFilter"}], adjust: "data",
|
||||
sort:"string", hidden:true},
|
||||
{id: "fecha", header: ["Fecha y Hora"],
|
||||
adjust: "data", sort: "date"},
|
||||
adjust: "data", sort: "string"},
|
||||
{id: "tipo_comprobante", header: ["Tipo", {content: "selectFilter"}],
|
||||
adjust: 'header', sort: 'string'},
|
||||
{id: "estatus", header: ["Estatus", {content: "selectFilter"}],
|
||||
|
|
Loading…
Reference in New Issue