forked from elmau/empresa-libre
Update inventory
This commit is contained in:
parent
61a8937eb3
commit
bc53171969
|
@ -4058,7 +4058,10 @@ class WareHouseProduct(BaseModel):
|
||||||
product = args['product'],
|
product = args['product'],
|
||||||
)
|
)
|
||||||
obj, created = WareHouseProduct.get_or_create(**values)
|
obj, created = WareHouseProduct.get_or_create(**values)
|
||||||
obj.exists += args['cant']
|
cant = args['cant']
|
||||||
|
if created:
|
||||||
|
cant = float(cant)
|
||||||
|
obj.exists += cant
|
||||||
obj.save()
|
obj.save()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -5120,6 +5123,9 @@ class Facturas(BaseModel):
|
||||||
values['forma_pago'] = ''
|
values['forma_pago'] = ''
|
||||||
|
|
||||||
with database_proxy.atomic() as txn:
|
with database_proxy.atomic() as txn:
|
||||||
|
|
||||||
|
print(values)
|
||||||
|
|
||||||
obj = Facturas.create(**values)
|
obj = Facturas.create(**values)
|
||||||
totals = cls._calculate_totals(cls, obj, productos, tipo_comprobante)
|
totals = cls._calculate_totals(cls, obj, productos, tipo_comprobante)
|
||||||
cls._guardar_relacionados(cls, obj, relacionados)
|
cls._guardar_relacionados(cls, obj, relacionados)
|
||||||
|
@ -5547,7 +5553,7 @@ class Facturas(BaseModel):
|
||||||
anticipo = True
|
anticipo = True
|
||||||
cls._actualizar_saldo_cliente(cls, obj)
|
cls._actualizar_saldo_cliente(cls, obj)
|
||||||
if update:
|
if update:
|
||||||
cls._update_inventory(cls, obj)
|
cls._update_inventory(cls, obj, user=user)
|
||||||
cls._sync(cls, id, rfc)
|
cls._sync(cls, id, rfc)
|
||||||
|
|
||||||
m = 'T {}'.format(obj.id)
|
m = 'T {}'.format(obj.id)
|
||||||
|
@ -5823,18 +5829,38 @@ class Facturas(BaseModel):
|
||||||
|
|
||||||
# ~ v2
|
# ~ v2
|
||||||
@utils.run_in_thread
|
@utils.run_in_thread
|
||||||
def _update_inventory(self, invoice, cancel=False):
|
def _update_inventory(self, invoice, cancel=False, user=None):
|
||||||
if invoice.tipo_comprobante != 'I':
|
if invoice.tipo_comprobante != 'I':
|
||||||
return
|
return
|
||||||
|
|
||||||
|
warehouse = None
|
||||||
|
try:
|
||||||
|
warehouse = user.sucursal.warehouse
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
products = FacturasDetalle.get_by_invoice(invoice.id)
|
products = FacturasDetalle.get_by_invoice(invoice.id)
|
||||||
for p in products:
|
for p in products:
|
||||||
if p.producto.inventario:
|
if p.producto.inventario:
|
||||||
|
cant = Decimal(p.cantidad)
|
||||||
if cancel:
|
if cancel:
|
||||||
p.producto.existencia += Decimal(p.cantidad)
|
cant *= -1
|
||||||
else:
|
# ~ p.producto.existencia += Decimal(p.cantidad)
|
||||||
p.producto.existencia -= Decimal(p.cantidad)
|
# ~ else:
|
||||||
|
# ~ p.producto.existencia -= Decimal(p.cantidad)
|
||||||
|
p.producto.existencia -= cant
|
||||||
p.producto.save()
|
p.producto.save()
|
||||||
|
|
||||||
|
if warehouse is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
fields = (
|
||||||
|
WareHouseProduct.warehouse==warehouse,
|
||||||
|
WareHouseProduct.product==p,
|
||||||
|
)
|
||||||
|
obj = WareHouseProduct.get(*fields)
|
||||||
|
obj.exists -= cant
|
||||||
|
obj.save()
|
||||||
return
|
return
|
||||||
|
|
||||||
@utils.run_in_thread
|
@utils.run_in_thread
|
||||||
|
|
Loading…
Reference in New Issue