123
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from typing import Union
|
||||
from dataclasses import dataclass
|
||||
from typing import Union, TypedDict
|
||||
|
||||
from sqlalchemy import select, func, and_, cast, String, case, or_
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -9,6 +10,12 @@ from database.sipro import *
|
||||
from database.sipro.enums.product import ProductRelationType
|
||||
|
||||
|
||||
class StockData(TypedDict):
|
||||
full_stock: int
|
||||
article: Union[str, int]
|
||||
marketplace_product: MarketplaceProduct
|
||||
|
||||
|
||||
def get_marketplace_suppliers_and_company_warehouses(marketplace: Marketplace):
|
||||
company = marketplace.company
|
||||
suppliers = set()
|
||||
@@ -30,7 +37,7 @@ async def get_stocks_data(
|
||||
session: AsyncSession,
|
||||
marketplace: Marketplace,
|
||||
product_ids: Union[list[int], None] = None
|
||||
):
|
||||
) -> List[StockData]:
|
||||
if not product_ids:
|
||||
product_ids = []
|
||||
company = marketplace.company
|
||||
@@ -46,7 +53,7 @@ async def get_stocks_data(
|
||||
supplier_stock_subquery = (
|
||||
select(
|
||||
func.greatest(
|
||||
func.sum(SupplierProduct.supplier_stock) - func.coalesce(DailyStock.sold_today, 0),
|
||||
func.sum(SupplierProduct.supplier_stock - SupplierProduct.sold_today),
|
||||
0
|
||||
)
|
||||
.label('supplier_stock'),
|
||||
@@ -58,10 +65,6 @@ async def get_stocks_data(
|
||||
.join(
|
||||
Product
|
||||
)
|
||||
.outerjoin(
|
||||
DailyStock,
|
||||
DailyStock.product_id == SupplierProduct.product_id
|
||||
)
|
||||
.where(
|
||||
SupplierProduct.supplier_id.in_(supplier_ids)
|
||||
)
|
||||
@@ -286,9 +289,13 @@ async def get_stocks_data(
|
||||
slaves_stock_subquery.c.product_id == MarketplaceProduct.product_id
|
||||
)
|
||||
)
|
||||
print('-------------------------')
|
||||
print(stmt.compile(compile_kwargs={
|
||||
'literal_binds': True
|
||||
}))
|
||||
result = await session.execute(stmt)
|
||||
marketplace_products = result.all()
|
||||
result = []
|
||||
response: List[StockData] = []
|
||||
for (marketplace_product,
|
||||
denco_article,
|
||||
price_purchase,
|
||||
@@ -301,8 +308,8 @@ async def get_stocks_data(
|
||||
price_recommended,
|
||||
is_archived) in marketplace_products:
|
||||
if is_archived or (sell_from_price > price_recommended):
|
||||
result.append({
|
||||
'denco_article': denco_article,
|
||||
response.append({
|
||||
'article': denco_article,
|
||||
'full_stock': 0,
|
||||
'marketplace_product': marketplace_product,
|
||||
})
|
||||
@@ -328,10 +335,10 @@ async def get_stocks_data(
|
||||
full_stock = 0
|
||||
full_stock = max([0, full_stock])
|
||||
|
||||
result.append({
|
||||
'denco_article': denco_article,
|
||||
response.append({
|
||||
'article': denco_article,
|
||||
'full_stock': full_stock,
|
||||
'marketplace_product': marketplace_product,
|
||||
})
|
||||
|
||||
return result
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user