feat: some stuff

This commit is contained in:
2024-11-04 01:32:14 +03:00
parent 1806f5dec3
commit 757ed72ec3
5 changed files with 18 additions and 3 deletions

4
constants.py Normal file
View File

@@ -0,0 +1,4 @@
import os
import sys
APP_PATH = os.path.dirname(sys.executable) if getattr(sys, "frozen", False) else os.path.dirname(__file__)

View File

@@ -53,6 +53,7 @@ class Marketplace(BaseSiproModel):
sell_warehouse_products: Mapped[bool] = mapped_column() sell_warehouse_products: Mapped[bool] = mapped_column()
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()
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

@@ -5,6 +5,7 @@ from datetime import datetime
from redis import asyncio as aioredis from redis import asyncio as aioredis
import backend.config import backend.config
from constants import APP_PATH
class RedisConnectionManager: class RedisConnectionManager:
@@ -16,6 +17,13 @@ class RedisConnectionManager:
async with cls._redis_lock: async with cls._redis_lock:
if cls._redis_connection is None: if cls._redis_connection is None:
cls._redis_connection = await aioredis.from_url(backend.config.REDIS_URL) cls._redis_connection = await aioredis.from_url(backend.config.REDIS_URL)
path = APP_PATH + "/redis.log"
with open(path, "a") as f:
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
line = f"[{current_datetime}] Created connection to redis\n"
f.write(line)
return cls._redis_connection return cls._redis_connection

View File

@@ -49,7 +49,7 @@ async def get_stocks_data(
sell_blocks: bool = marketplace.sell_blocks sell_blocks: bool = marketplace.sell_blocks
sell_warehouse_products: bool = marketplace.sell_warehouse_products sell_warehouse_products: bool = marketplace.sell_warehouse_products
sell_from_price: int = marketplace.sell_from_price sell_from_price: int = marketplace.sell_from_price
is_paused = marketplace.is_paused
supplier_stock_subquery = ( supplier_stock_subquery = (
select( select(
func.greatest( func.greatest(
@@ -302,7 +302,7 @@ async def get_stocks_data(
slaves_stock, slaves_stock,
price_recommended, price_recommended,
is_archived) in marketplace_products: is_archived) in marketplace_products:
if is_archived or (sell_from_price > price_recommended): if is_archived or (sell_from_price > price_recommended) or is_paused:
response.append({ response.append({
'article': denco_article, 'article': denco_article,
'full_stock': 0, 'full_stock': 0,

View File

@@ -46,6 +46,7 @@ class StocksUpdater:
Company.is_deleted == False, Company.is_deleted == False,
Company.is_archived == False, Company.is_archived == False,
Marketplace.is_deleted == False, Marketplace.is_deleted == False,
Marketplace.is_paused == False,
Marketplace.base_marketplace.in_([ Marketplace.base_marketplace.in_([
BaseMarketplace.OZON, BaseMarketplace.OZON,
BaseMarketplace.WILDBERRIES, BaseMarketplace.WILDBERRIES,
@@ -115,7 +116,8 @@ class StocksUpdater:
MarketplaceProduct.product_id == update.product_id, MarketplaceProduct.product_id == update.product_id,
Marketplace.is_deleted == False, Marketplace.is_deleted == False,
Company.is_deleted == False, Company.is_deleted == False,
Company.is_archived == False Company.is_archived == False,
Marketplace.is_paused == False,
) )
) )
stmt_result = await self.session.execute(stmt) stmt_result = await self.session.execute(stmt)