no message
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
pipeline:
|
pipeline:
|
||||||
|
-
|
||||||
# Настраиваем парсинг экселя
|
# Настраиваем парсинг экселя
|
||||||
- handler: BasicExcelParser
|
- handler: BasicExcelParser
|
||||||
config:
|
config:
|
||||||
@@ -12,9 +13,10 @@ pipeline:
|
|||||||
quantity: "Кол-во"
|
quantity: "Кол-во"
|
||||||
total: "Сумма"
|
total: "Сумма"
|
||||||
|
|
||||||
|
# Запрос остатков со склада
|
||||||
- handler: GetStock
|
- handler: GetStock
|
||||||
|
|
||||||
|
# Определяем логику обработки заказа (в данном случае все с локального склада)
|
||||||
- handler: LocalStoreOrder
|
- handler: LocalStoreOrder
|
||||||
|
|
||||||
|
|
||||||
@@ -23,3 +25,5 @@ pipeline:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import random
|
||||||
|
import logging
|
||||||
|
from mail_order_bot.email_processor.handlers.abstract_task import AbstractTask
|
||||||
|
from mail_order_bot.email_processor.order.auto_part_order import OrderStatus
|
||||||
|
from mail_order_bot.email_processor.order.auto_part_position import AutoPartPosition, PositionStatus
|
||||||
|
from decimal import Decimal
|
||||||
|
import random
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class LocalStoreOrder(AbstractTask):
|
||||||
|
"""Сейчас логика такая
|
||||||
|
- ищем на складе наш сапплиер код, берем самую дешевую позицию и делаем заказ из нее
|
||||||
|
|
||||||
|
Другие чуть более дорогие не рассматриваем
|
||||||
|
|
||||||
|
"""
|
||||||
|
# это код нашего склада
|
||||||
|
|
||||||
|
def do(self) -> None:
|
||||||
|
attachments = self.context.data["attachments"]
|
||||||
|
for attachment in attachments:
|
||||||
|
order = attachment["order"]
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ class AutoPartOrder:
|
|||||||
self.status = OrderStatus.NEW
|
self.status = OrderStatus.NEW
|
||||||
self.delivery_period = 0
|
self.delivery_period = 0
|
||||||
self.reason = ""
|
self.reason = ""
|
||||||
|
self.errors = []
|
||||||
|
|
||||||
def add_position(self, position: AutoPartPosition) -> None:
|
def add_position(self, position: AutoPartPosition) -> None:
|
||||||
self.positions.append(position)
|
self.positions.append(position)
|
||||||
@@ -32,10 +33,23 @@ class AutoPartOrder:
|
|||||||
|
|
||||||
def set_delivery_period(self, delivery_period: int) -> None:
|
def set_delivery_period(self, delivery_period: int) -> None:
|
||||||
self.delivery_period = delivery_period
|
self.delivery_period = delivery_period
|
||||||
|
ы
|
||||||
def fill_from_local_supplier(self) -> None:
|
def fill_from_local_supplier(self) -> None:
|
||||||
for position in self.positions:
|
for position in self.positions:
|
||||||
position.fill_from_local_supplier()
|
errors = position.fill_from_local_supplier()
|
||||||
|
self.errors += errors
|
||||||
|
|
||||||
|
def check_order(self, config) -> None:
|
||||||
|
# 1. Проверка общего количества отказов
|
||||||
|
order_refusal_threshold = config.get("order_refusal_threshold", 1)
|
||||||
|
refusal_positions_count = len([position for position in self.positions if str(position.status) in
|
||||||
|
[PositionStatus.REFUSED, PositionStatus.STOCK_FAILED]])
|
||||||
|
|
||||||
|
order_refusal_rate = refusal_positions_count / len(self.positions)
|
||||||
|
if order_refusal_rate > order_refusal_threshold:
|
||||||
|
self.errors.append(f"Превышен порог отказов в заказе - {order_refusal_rate:.0%} "
|
||||||
|
f"({refusal_positions_count} из {len(self.positions)})")
|
||||||
|
self.status = OrderStatus.OPERATOR_REQUIRED
|
||||||
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class AutoPartPosition:
|
|||||||
|
|
||||||
def fill_from_local_supplier(self):
|
def fill_from_local_supplier(self):
|
||||||
if self.status != PositionStatus.STOCK_RECIEVED:
|
if self.status != PositionStatus.STOCK_RECIEVED:
|
||||||
return
|
return []
|
||||||
|
|
||||||
supplier_stock_items = [item for item in self.stock if str(item["supplierCode"]) == self.SUPPLIER_CODE]
|
supplier_stock_items = [item for item in self.stock if str(item["supplierCode"]) == self.SUPPLIER_CODE]
|
||||||
supplier_stock_items.sort(key=lambda item: Decimal(item["price"]), reverse=False)
|
supplier_stock_items.sort(key=lambda item: Decimal(item["price"]), reverse=False)
|
||||||
@@ -71,11 +71,25 @@ class AutoPartPosition:
|
|||||||
self.order_quantity = self.requested_quantity
|
self.order_quantity = self.requested_quantity
|
||||||
self.status = PositionStatus.READY
|
self.status = PositionStatus.READY
|
||||||
self.desc = "Готов к заказу"
|
self.desc = "Готов к заказу"
|
||||||
|
self._set_price(supplier_stock_items[0])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.order_quantity = supplier_stock_items[0]["availability"]
|
self.order_quantity = supplier_stock_items[0]["availability"]
|
||||||
|
self.status = PositionStatus.READY
|
||||||
self.status = PositionStatus.READY_PARTIAL
|
self.status = PositionStatus.READY_PARTIAL
|
||||||
self.desc = "Частичный остаток"
|
self.desc = "Частичный остаток"
|
||||||
|
self._set_price(supplier_stock_items[0])
|
||||||
|
|
||||||
|
def _set_price(self, stok_item: Dict[str, Any]):
|
||||||
|
stok_item_price = Decimal(stok_item["price"])
|
||||||
|
if stok_item_price <= self.requested_price:
|
||||||
|
self.order_price = stok_item_price
|
||||||
|
else:
|
||||||
|
self.status = PositionStatus.REFUSED
|
||||||
|
self.desc = "Превышение по цене"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user