feat: do not send stocks where disabled

This commit is contained in:
2024-12-06 11:57:40 +03:00
parent 2b5c3966e5
commit cb65e48009
2 changed files with 9 additions and 2 deletions

View File

@@ -54,6 +54,7 @@ class Marketplace(BaseSiproModel):
sell_from_price: Mapped[bool] = mapped_column() sell_from_price: Mapped[bool] = mapped_column()
is_deleted: Mapped[bool] = mapped_column() is_deleted: Mapped[bool] = mapped_column()
is_paused: Mapped[bool] = mapped_column() is_paused: Mapped[bool] = mapped_column()
send_stocks: Mapped[bool] = mapped_column()
warehouses: Mapped[List["Warehouse"]] = relationship(secondary=marketplace_warehouses) warehouses: Mapped[List["Warehouse"]] = relationship(secondary=marketplace_warehouses)
warehouse_id: Mapped[str] = mapped_column() warehouse_id: Mapped[str] = mapped_column()

View File

@@ -47,6 +47,7 @@ class StocksUpdater:
Company.is_archived == False, Company.is_archived == False,
Marketplace.is_deleted == False, Marketplace.is_deleted == False,
Marketplace.is_paused == False, Marketplace.is_paused == False,
Marketplace.send_stocks==True,
Marketplace.base_marketplace.in_([ Marketplace.base_marketplace.in_([
BaseMarketplace.OZON, BaseMarketplace.OZON,
BaseMarketplace.WILDBERRIES, BaseMarketplace.WILDBERRIES,
@@ -63,6 +64,8 @@ class StocksUpdater:
async def full_update_marketplace(self, marketplace_id: int): async def full_update_marketplace(self, marketplace_id: int):
marketplace = await self.get_marketplace(marketplace_id) marketplace = await self.get_marketplace(marketplace_id)
if not marketplace.send_stocks:
return
start = time.time() start = time.time()
updater = UpdaterFactory.get_updater(self.session, marketplace) updater = UpdaterFactory.get_updater(self.session, marketplace)
await updater.update_all() await updater.update_all()
@@ -97,6 +100,8 @@ class StocksUpdater:
async def update_marketplace_products(self, marketplace_id: int, product_ids: list[int]): async def update_marketplace_products(self, marketplace_id: int, product_ids: list[int]):
marketplace = await self.get_marketplace(marketplace_id) marketplace = await self.get_marketplace(marketplace_id)
if not marketplace.send_stocks:
return
start = time.time() start = time.time()
updater = UpdaterFactory.get_updater(self.session, marketplace) updater = UpdaterFactory.get_updater(self.session, marketplace)
await updater.update_products(product_ids) await updater.update_products(product_ids)
@@ -118,6 +123,7 @@ class StocksUpdater:
Company.is_deleted == False, Company.is_deleted == False,
Company.is_archived == False, Company.is_archived == False,
Marketplace.is_paused == False, Marketplace.is_paused == False,
Marketplace.send_stocks == True
) )
) )
stmt_result = await self.session.execute(stmt) stmt_result = await self.session.execute(stmt)
@@ -133,10 +139,10 @@ class StocksUpdater:
tasks.append(self.update_marketplace(marketplace_id, marketplace_updates)) tasks.append(self.update_marketplace(marketplace_id, marketplace_updates))
await asyncio.gather(*tasks) await asyncio.gather(*tasks)
async def reset_marketplace(self, marketplace_id:int): async def reset_marketplace(self, marketplace_id: int):
marketplace = await self.get_marketplace(marketplace_id) marketplace = await self.get_marketplace(marketplace_id)
start = time.time() start = time.time()
updater = UpdaterFactory.get_updater(self.session,marketplace) updater = UpdaterFactory.get_updater(self.session, marketplace)
await updater.reset() await updater.reset()
logging.info( logging.info(
f"{marketplace.name} successfully updated in {round(time.time() - start, 2)} seconds.") f"{marketplace.name} successfully updated in {round(time.time() - start, 2)} seconds.")