Add warehouse in detail tickets
This commit is contained in:
parent
c4e29e47fa
commit
cd35884999
|
@ -7482,12 +7482,18 @@ class Tickets(BaseModel):
|
||||||
base = round(importe / tasa, DECIMALES)
|
base = round(importe / tasa, DECIMALES)
|
||||||
return base
|
return base
|
||||||
|
|
||||||
def _calcular_totales(self, ticket, productos):
|
def _calcular_totales(self, ticket, productos, user=None):
|
||||||
subtotal = 0
|
subtotal = 0
|
||||||
descuento_cfdi = 0
|
descuento_cfdi = 0
|
||||||
totals_tax = {}
|
totals_tax = {}
|
||||||
total_trasladados = None
|
total_trasladados = None
|
||||||
|
|
||||||
|
warehouse = None
|
||||||
|
try:
|
||||||
|
warehouse = user.sucursal.warehouse
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
for producto in productos:
|
for producto in productos:
|
||||||
id_producto = producto.pop('id_product')
|
id_producto = producto.pop('id_product')
|
||||||
p = Productos.get(Productos.id==id_producto)
|
p = Productos.get(Productos.id==id_producto)
|
||||||
|
@ -7507,6 +7513,8 @@ class Tickets(BaseModel):
|
||||||
producto['precio_final'] = precio_final
|
producto['precio_final'] = precio_final
|
||||||
producto['importe'] = importe
|
producto['importe'] = importe
|
||||||
|
|
||||||
|
producto['warehouse'] = warehouse
|
||||||
|
|
||||||
descuento_cfdi += descuento
|
descuento_cfdi += descuento
|
||||||
subtotal += importe
|
subtotal += importe
|
||||||
|
|
||||||
|
@ -7593,12 +7601,12 @@ class Tickets(BaseModel):
|
||||||
if warehouse is None:
|
if warehouse is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fields = (
|
where = (
|
||||||
WareHouseProduct.warehouse==warehouse,
|
WareHouseProduct.warehouse==warehouse,
|
||||||
WareHouseProduct.product==p.producto,
|
WareHouseProduct.product==p.producto,
|
||||||
)
|
)
|
||||||
|
|
||||||
obj = WareHouseProduct.get(*fields)
|
obj = WareHouseProduct.get(*where)
|
||||||
obj.exists -= cant
|
obj.exists -= cant
|
||||||
obj.save()
|
obj.save()
|
||||||
return
|
return
|
||||||
|
@ -7611,7 +7619,7 @@ class Tickets(BaseModel):
|
||||||
|
|
||||||
with database_proxy.atomic() as txn:
|
with database_proxy.atomic() as txn:
|
||||||
obj = Tickets.create(**values)
|
obj = Tickets.create(**values)
|
||||||
totals = cls._calcular_totales(cls, obj, productos)
|
totals = cls._calcular_totales(cls, obj, productos, user)
|
||||||
obj.subtotal = totals['subtotal']
|
obj.subtotal = totals['subtotal']
|
||||||
obj.descuento = totals['descuento']
|
obj.descuento = totals['descuento']
|
||||||
obj.total_trasladados = totals['total_trasladados']
|
obj.total_trasladados = totals['total_trasladados']
|
||||||
|
@ -7898,6 +7906,10 @@ class Tickets(BaseModel):
|
||||||
if p.producto.inventario:
|
if p.producto.inventario:
|
||||||
p.producto.existencia += p.cantidad
|
p.producto.existencia += p.cantidad
|
||||||
p.producto.save()
|
p.producto.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -8154,6 +8166,7 @@ class TicketsDetalle(BaseModel):
|
||||||
auto_round=True)
|
auto_round=True)
|
||||||
importe = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
importe = DecimalField(default=0.0, max_digits=20, decimal_places=6,
|
||||||
auto_round=True)
|
auto_round=True)
|
||||||
|
warehouse = ForeignKeyField(Almacenes, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
order_by = ('ticket',)
|
order_by = ('ticket',)
|
||||||
|
@ -10308,6 +10321,13 @@ def _migrate_tables(rfc=''):
|
||||||
warehouse = ForeignKeyField(Almacenes, null=True, to_field=Almacenes.id)
|
warehouse = ForeignKeyField(Almacenes, null=True, to_field=Almacenes.id)
|
||||||
migrations.append(migrator.add_column(table, 'warehouse_id', warehouse))
|
migrations.append(migrator.add_column(table, 'warehouse_id', warehouse))
|
||||||
|
|
||||||
|
table = 'ticketsdetalle'
|
||||||
|
field = 'warehouse_id'
|
||||||
|
columns = [c.name for c in database_proxy.get_columns(table)]
|
||||||
|
if not field in columns:
|
||||||
|
warehouse = ForeignKeyField(Almacenes, null=True, to_field=Almacenes.id)
|
||||||
|
migrations.append(migrator.add_column(table, field, warehouse))
|
||||||
|
|
||||||
if migrations:
|
if migrations:
|
||||||
with database_proxy.atomic() as txn:
|
with database_proxy.atomic() as txn:
|
||||||
migrate(*migrations)
|
migrate(*migrations)
|
||||||
|
|
Loading…
Reference in New Issue