forked from elmau/empresa-libre
Descuentos en prefacturas
This commit is contained in:
parent
28fcb803ab
commit
7da9289082
|
@ -729,7 +729,9 @@ class LIBO(object):
|
||||||
|
|
||||||
#~ Si no se encuentra, copia las celdas hacia abajo de
|
#~ Si no se encuentra, copia las celdas hacia abajo de
|
||||||
#~ {subtotal.titulo} y {subtotal}
|
#~ {subtotal.titulo} y {subtotal}
|
||||||
|
print (data['descuento'])
|
||||||
if 'descuento' in data:
|
if 'descuento' in data:
|
||||||
|
|
||||||
self._copy_cell(cell_title)
|
self._copy_cell(cell_title)
|
||||||
self._copy_cell(cell_value)
|
self._copy_cell(cell_value)
|
||||||
cell_title = self._set_cell(v='Descuento', cell=cell_title)
|
cell_title = self._set_cell(v='Descuento', cell=cell_title)
|
||||||
|
|
|
@ -1721,6 +1721,7 @@ class Facturas(BaseModel):
|
||||||
|
|
||||||
def _calculate_totals(self, invoice, products):
|
def _calculate_totals(self, invoice, products):
|
||||||
subtotal = 0
|
subtotal = 0
|
||||||
|
descuento_cfdi = 0
|
||||||
totals_tax = {}
|
totals_tax = {}
|
||||||
total_trasladados = None
|
total_trasladados = None
|
||||||
total_retenciones = None
|
total_retenciones = None
|
||||||
|
@ -1749,6 +1750,7 @@ class Facturas(BaseModel):
|
||||||
product['precio_final'] = precio_final
|
product['precio_final'] = precio_final
|
||||||
product['importe'] = round(cantidad * valor_unitario, 2)
|
product['importe'] = round(cantidad * valor_unitario, 2)
|
||||||
|
|
||||||
|
descuento_cfdi += descuento
|
||||||
subtotal += importe
|
subtotal += importe
|
||||||
|
|
||||||
FacturasDetalle.create(**product)
|
FacturasDetalle.create(**product)
|
||||||
|
@ -1800,6 +1802,7 @@ class Facturas(BaseModel):
|
||||||
total_mn = round(total * invoice.tipo_cambio, 2)
|
total_mn = round(total * invoice.tipo_cambio, 2)
|
||||||
data = {
|
data = {
|
||||||
'subtotal': subtotal + descuento,
|
'subtotal': subtotal + descuento,
|
||||||
|
'descuento': descuento_cfdi,
|
||||||
'total': total,
|
'total': total,
|
||||||
'total_mn': total_mn,
|
'total_mn': total_mn,
|
||||||
'total_trasladados': total_trasladados,
|
'total_trasladados': total_trasladados,
|
||||||
|
@ -1832,6 +1835,7 @@ class Facturas(BaseModel):
|
||||||
totals = cls._calculate_totals(cls, obj, productos)
|
totals = cls._calculate_totals(cls, obj, productos)
|
||||||
cls._guardar_relacionados(cls, obj, relacionados)
|
cls._guardar_relacionados(cls, obj, relacionados)
|
||||||
obj.subtotal = totals['subtotal']
|
obj.subtotal = totals['subtotal']
|
||||||
|
obj.descuento = totals['descuento']
|
||||||
obj.total_trasladados = totals['total_trasladados']
|
obj.total_trasladados = totals['total_trasladados']
|
||||||
obj.total_retenciones = totals['total_retenciones']
|
obj.total_retenciones = totals['total_retenciones']
|
||||||
obj.total = totals['total']
|
obj.total = totals['total']
|
||||||
|
@ -1879,6 +1883,9 @@ class Facturas(BaseModel):
|
||||||
comprobante['TipoDeComprobante'] = invoice.tipo_comprobante
|
comprobante['TipoDeComprobante'] = invoice.tipo_comprobante
|
||||||
comprobante['MetodoPago'] = invoice.metodo_pago
|
comprobante['MetodoPago'] = invoice.metodo_pago
|
||||||
comprobante['LugarExpedicion'] = invoice.lugar_expedicion
|
comprobante['LugarExpedicion'] = invoice.lugar_expedicion
|
||||||
|
if invoice.descuento:
|
||||||
|
comprobante['Descuento'] = FORMAT.format(invoice.descuento)
|
||||||
|
|
||||||
if invoice.tipo_relacion:
|
if invoice.tipo_relacion:
|
||||||
relacionados = {
|
relacionados = {
|
||||||
'tipo': invoice.tipo_relacion,
|
'tipo': invoice.tipo_relacion,
|
||||||
|
@ -1897,7 +1904,7 @@ class Facturas(BaseModel):
|
||||||
'UsoCFDI': invoice.uso_cfdi,
|
'UsoCFDI': invoice.uso_cfdi,
|
||||||
}
|
}
|
||||||
|
|
||||||
descuento = 0
|
#~ 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:
|
||||||
|
@ -1913,7 +1920,7 @@ class Facturas(BaseModel):
|
||||||
}
|
}
|
||||||
if row.descuento:
|
if row.descuento:
|
||||||
concepto['Descuento'] = FORMAT.format(row.descuento)
|
concepto['Descuento'] = FORMAT.format(row.descuento)
|
||||||
descuento += row.descuento
|
#~ descuento += row.descuento
|
||||||
|
|
||||||
taxes = {}
|
taxes = {}
|
||||||
traslados = []
|
traslados = []
|
||||||
|
@ -1946,8 +1953,8 @@ class Facturas(BaseModel):
|
||||||
concepto['impuestos'] = taxes
|
concepto['impuestos'] = taxes
|
||||||
conceptos.append(concepto)
|
conceptos.append(concepto)
|
||||||
|
|
||||||
if descuento:
|
#~ if descuento:
|
||||||
comprobante['Descuento'] = FORMAT.format(descuento)
|
#~ comprobante['Descuento'] = FORMAT.format(descuento)
|
||||||
|
|
||||||
impuestos = {}
|
impuestos = {}
|
||||||
traslados = []
|
traslados = []
|
||||||
|
@ -2224,6 +2231,9 @@ class PreFacturas(BaseModel):
|
||||||
data['totales']['subtotal'] = str(data['comprobante']['subtotal'])
|
data['totales']['subtotal'] = str(data['comprobante']['subtotal'])
|
||||||
data['totales']['total'] = str(data['comprobante']['total'])
|
data['totales']['total'] = str(data['comprobante']['total'])
|
||||||
|
|
||||||
|
if obj['descuento']:
|
||||||
|
data['totales']['descuento'] = float(obj['descuento'])
|
||||||
|
|
||||||
taxes = PreFacturasImpuestos.get_(id)
|
taxes = PreFacturasImpuestos.get_(id)
|
||||||
data['totales']['traslados'] = taxes['traslados']
|
data['totales']['traslados'] = taxes['traslados']
|
||||||
data['totales']['retenciones'] = taxes['retenciones']
|
data['totales']['retenciones'] = taxes['retenciones']
|
||||||
|
@ -2310,6 +2320,7 @@ class PreFacturas(BaseModel):
|
||||||
|
|
||||||
def _calculate_totals(self, invoice, products):
|
def _calculate_totals(self, invoice, products):
|
||||||
subtotal = 0
|
subtotal = 0
|
||||||
|
descuento_cfdi = 0
|
||||||
totals_tax = {}
|
totals_tax = {}
|
||||||
total_trasladados = None
|
total_trasladados = None
|
||||||
total_retenciones = None
|
total_retenciones = None
|
||||||
|
@ -2318,25 +2329,36 @@ class PreFacturas(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)
|
||||||
|
|
||||||
|
descuento_cfdi += descuento
|
||||||
|
subtotal += importe
|
||||||
|
|
||||||
PreFacturasDetalle.create(**product)
|
PreFacturasDetalle.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 += importe
|
||||||
else:
|
else:
|
||||||
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':
|
||||||
|
@ -2374,7 +2396,8 @@ class PreFacturas(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,
|
||||||
|
'descuento': descuento_cfdi,
|
||||||
'total': total,
|
'total': total,
|
||||||
'total_mn': total_mn,
|
'total_mn': total_mn,
|
||||||
'total_trasladados': total_trasladados,
|
'total_trasladados': total_trasladados,
|
||||||
|
@ -2384,7 +2407,6 @@ class PreFacturas(BaseModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add(cls, values):
|
def add(cls, values):
|
||||||
print ('VALUES', values)
|
|
||||||
productos = util.loads(values.pop('productos'))
|
productos = util.loads(values.pop('productos'))
|
||||||
|
|
||||||
emisor = Emisor.select()[0]
|
emisor = Emisor.select()[0]
|
||||||
|
@ -2397,6 +2419,7 @@ class PreFacturas(BaseModel):
|
||||||
obj = PreFacturas.create(**values)
|
obj = PreFacturas.create(**values)
|
||||||
totals = cls._calculate_totals(cls, obj, productos)
|
totals = cls._calculate_totals(cls, obj, productos)
|
||||||
obj.subtotal = totals['subtotal']
|
obj.subtotal = totals['subtotal']
|
||||||
|
obj.descuento = totals['descuento']
|
||||||
obj.total_trasladados = totals['total_trasladados']
|
obj.total_trasladados = totals['total_trasladados']
|
||||||
obj.total_retenciones = totals['total_retenciones']
|
obj.total_retenciones = totals['total_retenciones']
|
||||||
obj.total = totals['total']
|
obj.total = totals['total']
|
||||||
|
|
|
@ -1045,6 +1045,7 @@ function cmd_prefactura_click(){
|
||||||
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()
|
||||||
|
|
Loading…
Reference in New Issue