This commit is contained in:
2024-07-04 05:52:43 +03:00
parent c75017c1a8
commit 2fa37c54b1

View File

@@ -94,7 +94,9 @@ async def get_stocks_data(
mix_stock_first_subquery = (
select(
func.sum(SupplierProduct.supplier_stock).label('master_stock'),
func.sum(func.greatest(SupplierProduct.supplier_stock - SupplierProduct.sold_today, 0))
.label(
'master_stock'),
SupplierProduct.product_id.label('product_id')
)
.select_from(
@@ -180,7 +182,7 @@ async def get_stocks_data(
)
.where(
SupplierProduct.supplier_id.in_(supplier_ids),
SupplierProduct.supplier_stock > 0
(SupplierProduct.supplier_stock - SupplierProduct.sold_today) > 0
)
.group_by(
Product.id
@@ -190,7 +192,7 @@ async def get_stocks_data(
slaves_stock_first_subquery = (
select(
ProductRelation.master_product_id.label('product_id'),
func.sum(SupplierProduct.supplier_stock).label('slaves_stock')
func.sum(func.greatest(SupplierProduct.supplier_stock - SupplierProduct.sold_today)).label('slaves_stock')
)
.select_from(
ProductRelation