Update inventory in tickets
This commit is contained in:
parent
f792b79655
commit
30a4a276dd
|
@ -5552,10 +5552,7 @@ class Facturas(BaseModel):
|
|||
|
||||
rfc = Emisor.select()[0].rfc
|
||||
obj = Facturas.get(Facturas.id == id)
|
||||
# ~ obj.xml = cls._make_xml(cls, obj)
|
||||
xml = cls._make_xml(cls, obj)
|
||||
# ~ obj.estatus = 'Generada'
|
||||
# ~ obj.save()
|
||||
q = (Facturas
|
||||
.update(xml=xml, estatus='Generada')
|
||||
.where(Facturas.id == id)
|
||||
|
@ -5567,7 +5564,6 @@ class Facturas(BaseModel):
|
|||
|
||||
anticipo = False
|
||||
msg = 'Factura timbrada correctamente'
|
||||
# ~ result = utils.xml_stamp(obj.xml, auth)
|
||||
result = utils.xml_stamp(xml, auth)
|
||||
|
||||
if result['ok']:
|
||||
|
@ -5890,9 +5886,6 @@ class Facturas(BaseModel):
|
|||
cant = Decimal(p.cantidad)
|
||||
if cancel:
|
||||
cant *= -1
|
||||
# ~ p.producto.existencia += Decimal(p.cantidad)
|
||||
# ~ else:
|
||||
# ~ p.producto.existencia -= Decimal(p.cantidad)
|
||||
p.producto.existencia -= cant
|
||||
p.producto.save()
|
||||
|
||||
|
@ -7513,9 +7506,9 @@ class Tickets(BaseModel):
|
|||
|
||||
TicketsDetalle.create(**producto)
|
||||
|
||||
if p.inventario:
|
||||
p.existencia -= Decimal(cantidad)
|
||||
p.save()
|
||||
# ~ if p.inventario:
|
||||
# ~ p.existencia -= Decimal(cantidad)
|
||||
# ~ p.save()
|
||||
|
||||
base = producto['importe']
|
||||
for tax in p.impuestos:
|
||||
|
@ -7571,6 +7564,39 @@ class Tickets(BaseModel):
|
|||
rows = Tickets.select(Tickets.notas).where(Tickets.id.in_(tickets))
|
||||
return '\n'.join([r.notas for r in rows])
|
||||
|
||||
@utils.run_in_thread
|
||||
def _update_inventory(cls, ticket, cancel=False, user=None):
|
||||
warehouse = None
|
||||
try:
|
||||
warehouse = user.sucursal.warehouse
|
||||
except:
|
||||
pass
|
||||
|
||||
products = (TicketsDetalle
|
||||
.select()
|
||||
.where(TicketsDetalle.ticket==ticket.id)
|
||||
)
|
||||
for p in products:
|
||||
if p.producto.inventario:
|
||||
cant = Decimal(p.cantidad)
|
||||
if cancel:
|
||||
cant *= -1
|
||||
p.producto.existencia -= cant
|
||||
p.producto.save()
|
||||
|
||||
if warehouse is None:
|
||||
continue
|
||||
|
||||
fields = (
|
||||
WareHouseProduct.warehouse==warehouse,
|
||||
WareHouseProduct.product==p.producto,
|
||||
)
|
||||
|
||||
obj = WareHouseProduct.get(*fields)
|
||||
obj.exists -= cant
|
||||
obj.save()
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def add(cls, values, user):
|
||||
productos = util.loads(values.pop('productos'))
|
||||
|
@ -7586,6 +7612,8 @@ class Tickets(BaseModel):
|
|||
obj.total = totals['total']
|
||||
obj.save()
|
||||
|
||||
cls._update_inventory(cls, obj, user=user)
|
||||
|
||||
row = {
|
||||
'id': obj.id,
|
||||
'serie': obj.serie,
|
||||
|
|
Loading…
Reference in New Issue