feat: update marketplace products
This commit is contained in:
@@ -31,6 +31,9 @@ class BaseMarketplaceUpdater(ABC):
|
||||
if not self.marketplace_api:
|
||||
return
|
||||
product_ids = list(set([update.product_id for update in updates]))
|
||||
await self.update_products(product_ids)
|
||||
|
||||
async def update_products(self, product_ids: list[int]):
|
||||
stock_data_list = await queries.general.get_stocks_data(
|
||||
session=self.session,
|
||||
marketplace=self.marketplace,
|
||||
|
||||
@@ -19,7 +19,7 @@ class StocksUpdater:
|
||||
def __init__(self, session: AsyncSession):
|
||||
self.session = session
|
||||
|
||||
async def get_marketplace(self, marketplace_id: int):
|
||||
async def get_marketplace(self, marketplace_id: int) -> Marketplace:
|
||||
marketplace = await self.session.get(Marketplace, marketplace_id, options=[
|
||||
joinedload(Marketplace.warehouses).joinedload(Warehouse.suppliers),
|
||||
joinedload(Marketplace.warehouses).joinedload(Warehouse.company_warehouses),
|
||||
@@ -94,6 +94,14 @@ class StocksUpdater:
|
||||
logging.info(
|
||||
f"Successfully uploaded {len(updates)} updates to {marketplace.name} in {round(time.time() - start, 2)} seconds.")
|
||||
|
||||
async def update_marketplace_products(self, marketplace_id: int, product_ids: list[int]):
|
||||
marketplace = await self.get_marketplace(marketplace_id)
|
||||
start = time.time()
|
||||
updater = UpdaterFactory.get_updater(self.session, marketplace)
|
||||
await updater.update_products(product_ids)
|
||||
logging.info(
|
||||
f"Successfully updated {len(product_ids)} products for {marketplace.name} in {round(time.time() - start, 2)} seconds.")
|
||||
|
||||
async def update(self, updates: list[StockUpdate]):
|
||||
updates_dict = defaultdict(list)
|
||||
for update in updates:
|
||||
|
||||
Reference in New Issue
Block a user