From 02630943867efdb3618f20f124fbe532ba29bab6 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 20 Oct 2025 21:21:28 +0300 Subject: [PATCH] fix: rename is_archived to is_deleted and update stock response logic --- database/sipro/models/products.py | 1 + queries/general.py | 48 +++++++++++++------------------ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/database/sipro/models/products.py b/database/sipro/models/products.py index ccc7ece..b3e238e 100644 --- a/database/sipro/models/products.py +++ b/database/sipro/models/products.py @@ -20,6 +20,7 @@ class MarketplaceProduct(BaseSiproModel): mp_price_bought: Mapped[int] = mapped_column() price_recommended: Mapped[int] = mapped_column() is_archived: Mapped[bool] = mapped_column() + is_deleted: Mapped[bool] = mapped_column() product_id: Mapped[int] = mapped_column(ForeignKey("products.id")) product: Mapped["Product"] = relationship() diff --git a/queries/general.py b/queries/general.py index 257c488..913f755 100644 --- a/queries/general.py +++ b/queries/general.py @@ -256,7 +256,7 @@ async def get_stocks_data( func.coalesce(is_master_subquery.c.is_master, False).label('is_master'), func.coalesce(slaves_stock_subquery.c.slaves_stock, 0).label('slaves_stock'), 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') ) .select_from( @@ -318,25 +318,25 @@ async def get_stocks_data( is_master, slaves_stock, price_recommended, - is_archived, + is_deleted, fbo_stock ) in marketplace_products: - if is_archived or (sell_from_price > price_recommended) or is_paused or reset: - response.append({ - 'article': denco_article, - 'full_stock': 0, - 'marketplace_product': marketplace_product, - 'product_id': marketplace_product.product_id - }) - continue - if fbo_stock > 0 and prefer_fbo_over_fbs: - response.append({ - 'article': denco_article, - 'full_stock': 0, - 'marketplace_product': marketplace_product, - 'product_id': marketplace_product.product_id - - }) + base_dict: StockData = { + 'article': denco_article, + 'marketplace_product': marketplace_product, + 'product_id': marketplace_product.product_id, + 'full_stock': 0 + } + zero_stock = any([ + is_deleted, + sell_from_price > price_recommended, + is_paused, + result, + fbo_stock > 0 and prefer_fbo_over_fbs, + 45 > company.balance + ]) + if zero_stock: + response.append(base_dict) continue is_mix = mix_stock is not None @@ -359,15 +359,7 @@ async def get_stocks_data( full_stock = warehouse_stock if (not sell_mixes) and is_mix: full_stock = warehouse_stock - if 45 > company.balance: - full_stock = 0 full_stock = max([0, full_stock]) - - response.append({ - 'article': denco_article, - 'full_stock': full_stock, - 'marketplace_product': marketplace_product, - 'product_id': marketplace_product.product_id - - }) + base_dict['full_stock'] = full_stock + response.append(base_dict) return response