fix: rename is_archived to is_deleted and update stock response logic

This commit is contained in:
2025-10-20 21:21:28 +03:00
parent 1bf01ebd09
commit 0263094386
2 changed files with 21 additions and 28 deletions

View File

@@ -20,6 +20,7 @@ class MarketplaceProduct(BaseSiproModel):
mp_price_bought: Mapped[int] = mapped_column() mp_price_bought: Mapped[int] = mapped_column()
price_recommended: Mapped[int] = mapped_column() price_recommended: Mapped[int] = mapped_column()
is_archived: Mapped[bool] = mapped_column() is_archived: Mapped[bool] = mapped_column()
is_deleted: Mapped[bool] = mapped_column()
product_id: Mapped[int] = mapped_column(ForeignKey("products.id")) product_id: Mapped[int] = mapped_column(ForeignKey("products.id"))
product: Mapped["Product"] = relationship() product: Mapped["Product"] = relationship()

View File

@@ -256,7 +256,7 @@ async def get_stocks_data(
func.coalesce(is_master_subquery.c.is_master, False).label('is_master'), func.coalesce(is_master_subquery.c.is_master, False).label('is_master'),
func.coalesce(slaves_stock_subquery.c.slaves_stock, 0).label('slaves_stock'), func.coalesce(slaves_stock_subquery.c.slaves_stock, 0).label('slaves_stock'),
MarketplaceProduct.price_recommended.label('price_recommended'), MarketplaceProduct.price_recommended.label('price_recommended'),
MarketplaceProduct.is_archived.label('is_archived'), MarketplaceProduct.is_deleted.label('is_deleted'),
func.coalesce(fbo_stock_subquery.c.quantity, 0).label('fbo_stock') func.coalesce(fbo_stock_subquery.c.quantity, 0).label('fbo_stock')
) )
.select_from( .select_from(
@@ -318,25 +318,25 @@ async def get_stocks_data(
is_master, is_master,
slaves_stock, slaves_stock,
price_recommended, price_recommended,
is_archived, is_deleted,
fbo_stock fbo_stock
) in marketplace_products: ) in marketplace_products:
if is_archived or (sell_from_price > price_recommended) or is_paused or reset: base_dict: StockData = {
response.append({ 'article': denco_article,
'article': denco_article, 'marketplace_product': marketplace_product,
'full_stock': 0, 'product_id': marketplace_product.product_id,
'marketplace_product': marketplace_product, 'full_stock': 0
'product_id': marketplace_product.product_id }
}) zero_stock = any([
continue is_deleted,
if fbo_stock > 0 and prefer_fbo_over_fbs: sell_from_price > price_recommended,
response.append({ is_paused,
'article': denco_article, result,
'full_stock': 0, fbo_stock > 0 and prefer_fbo_over_fbs,
'marketplace_product': marketplace_product, 45 > company.balance
'product_id': marketplace_product.product_id ])
if zero_stock:
}) response.append(base_dict)
continue continue
is_mix = mix_stock is not None is_mix = mix_stock is not None
@@ -359,15 +359,7 @@ async def get_stocks_data(
full_stock = warehouse_stock full_stock = warehouse_stock
if (not sell_mixes) and is_mix: if (not sell_mixes) and is_mix:
full_stock = warehouse_stock full_stock = warehouse_stock
if 45 > company.balance:
full_stock = 0
full_stock = max([0, full_stock]) full_stock = max([0, full_stock])
base_dict['full_stock'] = full_stock
response.append({ response.append(base_dict)
'article': denco_article,
'full_stock': full_stock,
'marketplace_product': marketplace_product,
'product_id': marketplace_product.product_id
})
return response return response