forked from elmau/empresa-libre
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
|
rfc = Emisor.select()[0].rfc
|
||||||
obj = Facturas.get(Facturas.id == id)
|
obj = Facturas.get(Facturas.id == id)
|
||||||
# ~ obj.xml = cls._make_xml(cls, obj)
|
|
||||||
xml = cls._make_xml(cls, obj)
|
xml = cls._make_xml(cls, obj)
|
||||||
# ~ obj.estatus = 'Generada'
|
|
||||||
# ~ obj.save()
|
|
||||||
q = (Facturas
|
q = (Facturas
|
||||||
.update(xml=xml, estatus='Generada')
|
.update(xml=xml, estatus='Generada')
|
||||||
.where(Facturas.id == id)
|
.where(Facturas.id == id)
|
||||||
|
@ -5567,7 +5564,6 @@ class Facturas(BaseModel):
|
||||||
|
|
||||||
anticipo = False
|
anticipo = False
|
||||||
msg = 'Factura timbrada correctamente'
|
msg = 'Factura timbrada correctamente'
|
||||||
# ~ result = utils.xml_stamp(obj.xml, auth)
|
|
||||||
result = utils.xml_stamp(xml, auth)
|
result = utils.xml_stamp(xml, auth)
|
||||||
|
|
||||||
if result['ok']:
|
if result['ok']:
|
||||||
|
@ -5890,9 +5886,6 @@ class Facturas(BaseModel):
|
||||||
cant = Decimal(p.cantidad)
|
cant = Decimal(p.cantidad)
|
||||||
if cancel:
|
if cancel:
|
||||||
cant *= -1
|
cant *= -1
|
||||||
# ~ p.producto.existencia += Decimal(p.cantidad)
|
|
||||||
# ~ else:
|
|
||||||
# ~ p.producto.existencia -= Decimal(p.cantidad)
|
|
||||||
p.producto.existencia -= cant
|
p.producto.existencia -= cant
|
||||||
p.producto.save()
|
p.producto.save()
|
||||||
|
|
||||||
|
@ -7513,9 +7506,9 @@ class Tickets(BaseModel):
|
||||||
|
|
||||||
TicketsDetalle.create(**producto)
|
TicketsDetalle.create(**producto)
|
||||||
|
|
||||||
if p.inventario:
|
# ~ if p.inventario:
|
||||||
p.existencia -= Decimal(cantidad)
|
# ~ p.existencia -= Decimal(cantidad)
|
||||||
p.save()
|
# ~ p.save()
|
||||||
|
|
||||||
base = producto['importe']
|
base = producto['importe']
|
||||||
for tax in p.impuestos:
|
for tax in p.impuestos:
|
||||||
|
@ -7571,6 +7564,39 @@ class Tickets(BaseModel):
|
||||||
rows = Tickets.select(Tickets.notas).where(Tickets.id.in_(tickets))
|
rows = Tickets.select(Tickets.notas).where(Tickets.id.in_(tickets))
|
||||||
return '\n'.join([r.notas for r in rows])
|
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
|
@classmethod
|
||||||
def add(cls, values, user):
|
def add(cls, values, user):
|
||||||
productos = util.loads(values.pop('productos'))
|
productos = util.loads(values.pop('productos'))
|
||||||
|
@ -7586,6 +7612,8 @@ class Tickets(BaseModel):
|
||||||
obj.total = totals['total']
|
obj.total = totals['total']
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
|
cls._update_inventory(cls, obj, user=user)
|
||||||
|
|
||||||
row = {
|
row = {
|
||||||
'id': obj.id,
|
'id': obj.id,
|
||||||
'serie': obj.serie,
|
'serie': obj.serie,
|
||||||
|
|
Loading…
Reference in New Issue