Agregar descuentos
This commit is contained in:
parent
cb616a79c5
commit
28fcb803ab
|
@ -952,6 +952,15 @@ class SATUsoCfdi(BaseModel):
|
||||||
return tuple(rows)
|
return tuple(rows)
|
||||||
|
|
||||||
|
|
||||||
|
class TipoCambio(BaseModel):
|
||||||
|
dia = DateField(default=util.now)
|
||||||
|
moneda = ForeignKeyField(SATMonedas)
|
||||||
|
tipo_cambio = DecimalField(max_digits=15, decimal_places=6, auto_round=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
order_by = ('-dia',)
|
||||||
|
|
||||||
|
|
||||||
class Addendas(BaseModel):
|
class Addendas(BaseModel):
|
||||||
nombre = TextField(unique=True)
|
nombre = TextField(unique=True)
|
||||||
addenda = TextField()
|
addenda = TextField()
|
||||||
|
@ -1173,8 +1182,13 @@ class Productos(BaseModel):
|
||||||
id = int(values.get('id', 0))
|
id = int(values.get('id', 0))
|
||||||
if id:
|
if id:
|
||||||
row = (Productos
|
row = (Productos
|
||||||
.select(Productos.id, Productos.clave, Productos.descripcion,
|
.select(
|
||||||
SATUnidades.name.alias('unidad'), Productos.valor_unitario)
|
Productos.id,
|
||||||
|
Productos.clave,
|
||||||
|
Productos.descripcion,
|
||||||
|
SATUnidades.name.alias('unidad'),
|
||||||
|
Productos.valor_unitario,
|
||||||
|
Productos.descuento)
|
||||||
.join(SATUnidades).switch(Productos)
|
.join(SATUnidades).switch(Productos)
|
||||||
.where(Productos.id==id).dicts())
|
.where(Productos.id==id).dicts())
|
||||||
if len(row):
|
if len(row):
|
||||||
|
@ -1330,7 +1344,8 @@ class Facturas(BaseModel):
|
||||||
descuento = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
descuento = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
||||||
auto_round=True)
|
auto_round=True)
|
||||||
moneda = TextField(default='MXN')
|
moneda = TextField(default='MXN')
|
||||||
tipo_cambio = DecimalField(default=1.0, decimal_places=6, auto_round=True)
|
tipo_cambio = DecimalField(default=1.0, max_digits=15, decimal_places=6,
|
||||||
|
auto_round=True)
|
||||||
total = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
total = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
||||||
auto_round=True)
|
auto_round=True)
|
||||||
total_mn = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
total_mn = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
||||||
|
@ -1714,29 +1729,43 @@ class Facturas(BaseModel):
|
||||||
for product in products:
|
for product in products:
|
||||||
id_product = product.pop('id')
|
id_product = product.pop('id')
|
||||||
p = Productos.get(Productos.id==id_product)
|
p = Productos.get(Productos.id==id_product)
|
||||||
#~ product['descripcion'] = p.descripcion
|
|
||||||
product['unidad'] = p.unidad.key
|
product['unidad'] = p.unidad.key
|
||||||
product['clave'] = p.clave
|
product['clave'] = p.clave
|
||||||
product['clave_sat'] = p.clave_sat
|
product['clave_sat'] = p.clave_sat
|
||||||
|
|
||||||
product['factura'] = invoice.id
|
product['factura'] = invoice.id
|
||||||
product['producto'] = id_product
|
product['producto'] = id_product
|
||||||
product['importe'] = round(
|
|
||||||
float(product['cantidad']) * float(product['valor_unitario']), 2)
|
cantidad = float(product['cantidad'])
|
||||||
subtotal += product['importe']
|
valor_unitario = float(product['valor_unitario'])
|
||||||
|
descuento = float(product['descuento'])
|
||||||
|
precio_final = valor_unitario - descuento
|
||||||
|
importe = round(cantidad * precio_final, 2)
|
||||||
|
|
||||||
|
product['cantidad'] = cantidad
|
||||||
|
product['valor_unitario'] = valor_unitario
|
||||||
|
product['descuento'] = descuento
|
||||||
|
product['precio_final'] = precio_final
|
||||||
|
product['importe'] = round(cantidad * valor_unitario, 2)
|
||||||
|
|
||||||
|
subtotal += importe
|
||||||
|
|
||||||
FacturasDetalle.create(**product)
|
FacturasDetalle.create(**product)
|
||||||
|
|
||||||
for tax in p.impuestos:
|
for tax in p.impuestos:
|
||||||
if tax.id in totals_tax:
|
if tax.id in totals_tax:
|
||||||
totals_tax[tax.id].importe += product['importe']
|
#~ totals_tax[tax.id].importe += product['importe']
|
||||||
|
totals_tax[tax.id].importe += importe
|
||||||
else:
|
else:
|
||||||
tax.importe = product['importe']
|
#~ tax.importe = product['importe']
|
||||||
|
tax.importe = importe
|
||||||
totals_tax[tax.id] = tax
|
totals_tax[tax.id] = tax
|
||||||
#~ totals_tax[tax.id]['importe'] = product['importe']
|
|
||||||
|
|
||||||
for tax in totals_tax.values():
|
for tax in totals_tax.values():
|
||||||
if tax.tipo == 'E' or tax.tipo == 'R':
|
if tax.tipo == 'E' or tax.tipo == 'R':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
import_tax = round(float(tax.tasa) * tax.importe, 2)
|
import_tax = round(float(tax.tasa) * tax.importe, 2)
|
||||||
total_trasladados = (total_trasladados or 0) + import_tax
|
total_trasladados = (total_trasladados or 0) + import_tax
|
||||||
if tax.name == 'IVA':
|
if tax.name == 'IVA':
|
||||||
|
@ -1770,7 +1799,7 @@ class Facturas(BaseModel):
|
||||||
total = subtotal + (total_trasladados or 0) - (total_retenciones or 0)
|
total = subtotal + (total_trasladados or 0) - (total_retenciones or 0)
|
||||||
total_mn = round(total * invoice.tipo_cambio, 2)
|
total_mn = round(total * invoice.tipo_cambio, 2)
|
||||||
data = {
|
data = {
|
||||||
'subtotal': subtotal,
|
'subtotal': subtotal + descuento,
|
||||||
'total': total,
|
'total': total,
|
||||||
'total_mn': total_mn,
|
'total_mn': total_mn,
|
||||||
'total_trasladados': total_trasladados,
|
'total_trasladados': total_trasladados,
|
||||||
|
@ -1868,6 +1897,7 @@ class Facturas(BaseModel):
|
||||||
'UsoCFDI': invoice.uso_cfdi,
|
'UsoCFDI': invoice.uso_cfdi,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
descuento = 0
|
||||||
conceptos = []
|
conceptos = []
|
||||||
rows = FacturasDetalle.select().where(FacturasDetalle.factura==invoice)
|
rows = FacturasDetalle.select().where(FacturasDetalle.factura==invoice)
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
@ -1881,6 +1911,9 @@ class Facturas(BaseModel):
|
||||||
'ValorUnitario': FORMAT.format(row.valor_unitario),
|
'ValorUnitario': FORMAT.format(row.valor_unitario),
|
||||||
'Importe': FORMAT.format(row.importe),
|
'Importe': FORMAT.format(row.importe),
|
||||||
}
|
}
|
||||||
|
if row.descuento:
|
||||||
|
concepto['Descuento'] = FORMAT.format(row.descuento)
|
||||||
|
descuento += row.descuento
|
||||||
|
|
||||||
taxes = {}
|
taxes = {}
|
||||||
traslados = []
|
traslados = []
|
||||||
|
@ -1889,12 +1922,13 @@ class Facturas(BaseModel):
|
||||||
for impuesto in row.producto.impuestos:
|
for impuesto in row.producto.impuestos:
|
||||||
if impuesto.tipo == 'E':
|
if impuesto.tipo == 'E':
|
||||||
continue
|
continue
|
||||||
import_tax = round(impuesto.tasa * row.importe, 2)
|
base = row.importe - row.descuento
|
||||||
|
import_tax = round(impuesto.tasa * base, 2)
|
||||||
tipo_factor = 'Tasa'
|
tipo_factor = 'Tasa'
|
||||||
if impuesto.factor != 'T':
|
if impuesto.factor != 'T':
|
||||||
tipo_factor = 'Cuota'
|
tipo_factor = 'Cuota'
|
||||||
tax = {
|
tax = {
|
||||||
"Base": FORMAT.format(row.importe),
|
"Base": FORMAT.format(base),
|
||||||
"Impuesto": impuesto.key,
|
"Impuesto": impuesto.key,
|
||||||
"TipoFactor": tipo_factor,
|
"TipoFactor": tipo_factor,
|
||||||
"TasaOCuota": str(impuesto.tasa),
|
"TasaOCuota": str(impuesto.tasa),
|
||||||
|
@ -1912,6 +1946,9 @@ class Facturas(BaseModel):
|
||||||
concepto['impuestos'] = taxes
|
concepto['impuestos'] = taxes
|
||||||
conceptos.append(concepto)
|
conceptos.append(concepto)
|
||||||
|
|
||||||
|
if descuento:
|
||||||
|
comprobante['Descuento'] = FORMAT.format(descuento)
|
||||||
|
|
||||||
impuestos = {}
|
impuestos = {}
|
||||||
traslados = []
|
traslados = []
|
||||||
retenciones = []
|
retenciones = []
|
||||||
|
@ -2684,7 +2721,7 @@ def _crear_tablas(rfc):
|
||||||
PreFacturasRelacionadas,
|
PreFacturasRelacionadas,
|
||||||
SATAduanas, SATFormaPago, SATImpuestos, SATMonedas, SATRegimenes,
|
SATAduanas, SATFormaPago, SATImpuestos, SATMonedas, SATRegimenes,
|
||||||
SATTipoRelacion, SATUnidades, SATUsoCfdi, SATBancos,
|
SATTipoRelacion, SATUnidades, SATUsoCfdi, SATBancos,
|
||||||
Socios, Tags, Usuarios, CuentasBanco,
|
Socios, Tags, Usuarios, CuentasBanco, TipoCambio,
|
||||||
Emisor.regimenes.get_through_model(),
|
Emisor.regimenes.get_through_model(),
|
||||||
Socios.tags.get_through_model(),
|
Socios.tags.get_through_model(),
|
||||||
Productos.impuestos.get_through_model(),
|
Productos.impuestos.get_through_model(),
|
||||||
|
|
|
@ -422,6 +422,7 @@ function guardar_y_timbrar(values){
|
||||||
delete rows[i]['unidad']
|
delete rows[i]['unidad']
|
||||||
delete rows[i]['importe']
|
delete rows[i]['importe']
|
||||||
rows[i]['valor_unitario'] = parseFloat(rows[i]['valor_unitario'])
|
rows[i]['valor_unitario'] = parseFloat(rows[i]['valor_unitario'])
|
||||||
|
rows[i]['descuento'] = parseFloat(rows[i]['descuento'])
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = new Object()
|
var data = new Object()
|
||||||
|
@ -687,7 +688,7 @@ function search_product_id_key_press(code, e){
|
||||||
|
|
||||||
|
|
||||||
function grid_details_before_edit_start(id){
|
function grid_details_before_edit_start(id){
|
||||||
var columns = ['', 'descripcion', 'cantidad', 'valor_unitario']
|
var columns = ['', 'descripcion', 'cantidad', 'valor_unitario', 'descuento']
|
||||||
if(!columns.indexOf(id.column)){
|
if(!columns.indexOf(id.column)){
|
||||||
return !this.getItem(id.row)[id.column]
|
return !this.getItem(id.row)[id.column]
|
||||||
}
|
}
|
||||||
|
@ -722,7 +723,8 @@ function grid_details_before_edit_stop(state, editor){
|
||||||
grid.unblockEvent()
|
grid.unblockEvent()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
var valor_unitario = row['valor_unitario']
|
var valor_unitario = parseFloat(row['valor_unitario'])
|
||||||
|
var descuento = parseFloat(row['descuento'])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(editor.column == 'valor_unitario'){
|
if(editor.column == 'valor_unitario'){
|
||||||
|
@ -736,10 +738,28 @@ function grid_details_before_edit_stop(state, editor){
|
||||||
grid.unblockEvent()
|
grid.unblockEvent()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
var cantidad = row['cantidad']
|
var cantidad = parseFloat(row['cantidad'])
|
||||||
|
var descuento = parseFloat(row['descuento'])
|
||||||
}
|
}
|
||||||
|
|
||||||
row['importe'] = (cantidad * valor_unitario).round(DECIMALES)
|
if(editor.column == 'descuento'){
|
||||||
|
var descuento = parseFloat(state.value)
|
||||||
|
if(isNaN(descuento)){
|
||||||
|
msg = 'El descuento debe ser un número'
|
||||||
|
webix.message({type:'error', text: msg})
|
||||||
|
grid.blockEvent()
|
||||||
|
state.value = state.old
|
||||||
|
grid.editCancel()
|
||||||
|
grid.unblockEvent()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
var cantidad = parseFloat(row['cantidad'])
|
||||||
|
var valor_unitario = parseFloat(row['valor_unitario'])
|
||||||
|
}
|
||||||
|
|
||||||
|
var precio_final = valor_unitario - descuento
|
||||||
|
row['importe'] = (cantidad * precio_final).round(DECIMALES)
|
||||||
|
|
||||||
grid.refresh()
|
grid.refresh()
|
||||||
calculate_taxes()
|
calculate_taxes()
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,9 +254,14 @@ var grid_details_cols = [
|
||||||
{id: "unidad", header:{text: 'Unidad', css: 'center'}, width: 100},
|
{id: "unidad", header:{text: 'Unidad', css: 'center'}, width: 100},
|
||||||
{id: 'cantidad', header: {text: 'Cantidad', css: 'center'}, width: 100,
|
{id: 'cantidad', header: {text: 'Cantidad', css: 'center'}, width: 100,
|
||||||
format: webix.i18n.numberFormat, css:'right', editor: 'text'},
|
format: webix.i18n.numberFormat, css:'right', editor: 'text'},
|
||||||
{id: "valor_unitario", header:{text: 'Valor Unitario', css: 'center'}, width: 100,
|
{id: "valor_unitario", header:{text: 'Valor Unitario', css: 'center'},
|
||||||
format: webix.i18n.priceFormat, css:'right', editor: 'text'},
|
width: 100, format: webix.i18n.priceFormat, css:'right', editor: 'text'},
|
||||||
{id: "importe", header:{text: 'Importe', css: 'center'}, width: 150, format: webix.i18n.priceFormat, css:'right'},
|
{id: 'descuento', header:{text: 'Descuento', css: 'center'},
|
||||||
|
width: 80, format: webix.i18n.priceFormat, css:'right', editor: 'text'},
|
||||||
|
{id: 'precio_final', hidden: true, header: 'precio_final', width: 80,
|
||||||
|
format: webix.i18n.priceFormat, css:'right'},
|
||||||
|
{id: "importe", header:{text: 'Importe', css: 'center'}, width: 150,
|
||||||
|
format: webix.i18n.priceFormat, css:'right'},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue