Fix - Issue #139

This commit is contained in:
Mauricio Baeza 2018-01-21 14:09:43 -06:00
commit a1a37d17ed
1 changed files with 21 additions and 11 deletions

View File

@ -2200,10 +2200,20 @@ class Productos(BaseModel):
@classmethod @classmethod
def next_key(cls): def next_key(cls):
value = (Productos try:
.select(fn.Max(cast(Productos.clave, 'int')).alias('fm')) with database_proxy.transaction():
.order_by(SQL('fm')) value = (Productos
.scalar()) .select(fn.Max(cast(Productos.clave, 'int')).alias('fm'))
.order_by(SQL('fm'))
.scalar())
except Exception as e:
values = (Productos
.select(Productos.clave)
.order_by(Productos.clave)
.tuples()
)
value = max([int(v[0]) for v in values if v[0].isdigit()])
value = value or 0 value = value or 0
value += 1 value += 1
return {'value': value} return {'value': value}
@ -3806,7 +3816,7 @@ class PreFacturas(BaseModel):
totals_tax = {} totals_tax = {}
total_trasladados = None total_trasladados = None
total_retenciones = None total_retenciones = None
total_iva = 0 # ~ total_iva = 0
for product in products: for product in products:
id_product = product.pop('id') id_product = product.pop('id')
@ -3848,8 +3858,8 @@ class PreFacturas(BaseModel):
continue continue
import_tax = round(float(tax.tasa) * tax.importe, DECIMALES) import_tax = round(float(tax.tasa) * tax.importe, DECIMALES)
total_trasladados = (total_trasladados or 0) + import_tax total_trasladados = (total_trasladados or 0) + import_tax
if tax.name == 'IVA': # ~ if tax.name == 'IVA':
total_iva += import_tax # ~ total_iva += import_tax
invoice_tax = { invoice_tax = {
'factura': invoice.id, 'factura': invoice.id,
@ -3862,10 +3872,10 @@ class PreFacturas(BaseModel):
for tax in totals_tax.values(): for tax in totals_tax.values():
if tax.tipo == 'E' or tax.tipo == 'T': if tax.tipo == 'E' or tax.tipo == 'T':
continue continue
if tax.tasa == round(Decimal(2/3), 6): # ~ if tax.tasa == round(Decimal(2/3), 6):
import_tax = round(float(tax.tasa) * total_iva, DECIMALES) # ~ import_tax = round(float(tax.tasa) * total_iva, DECIMALES)
else: # ~ else:
import_tax = round(float(tax.tasa) * tax.importe, DECIMALES) import_tax = round(float(tax.tasa) * tax.importe, DECIMALES)
total_retenciones = (total_retenciones or 0) + import_tax total_retenciones = (total_retenciones or 0) + import_tax
invoice_tax = { invoice_tax = {