Compare commits
1 Commits
features/f
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| ac6297415c |
@@ -6,6 +6,7 @@
|
||||
import logging
|
||||
|
||||
from ...abstract_task import AbstractTask, pass_if_error, handle_errors
|
||||
from ...exceptions import TaskExceptionWithEmailNotify
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -13,12 +14,12 @@ class DeliveryPeriodFromConfig(AbstractTask):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@pass_if_error
|
||||
#@pass_if_error
|
||||
def do(self, attachment) -> None:
|
||||
try:
|
||||
delivery_period = self.config.get("delivery_period")
|
||||
attachment["delivery_period"] = delivery_period
|
||||
logger.warning(f"Срок доставки установлен из конфига - {delivery_period} (ч.)")
|
||||
except Exception as e:
|
||||
raise Exception(f"Ошибка при установке срока доставки из конфига. Детали ошибки: {e}")
|
||||
raise TaskExceptionWithEmailNotify(f"Ошибка при установке срока доставки из конфига. Детали ошибки: {e}")
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"""
|
||||
|
||||
from ...abstract_task import AbstractTask, pass_if_error, handle_errors
|
||||
from ...exceptions import TaskExceptionWithEmailNotify
|
||||
|
||||
import logging
|
||||
import re
|
||||
@@ -48,7 +49,7 @@ class DeliveryPeriodFromSubject(AbstractTask):
|
||||
logger.debug(f"Срок доставки для файла {attachment["name"]} установлен как {delivery_time}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
raise TaskExceptionWithEmailNotify(f"Ошибка при установке срока доставки из темы письма. Детали ошибки: {e}")
|
||||
|
||||
|
||||
def _parse_delivery_period(self, subject: str) -> int:
|
||||
|
||||
@@ -13,8 +13,6 @@ class DeliveryPeriodLocalStore(AbstractTask):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def do(self) -> None:
|
||||
attachments = self.context.data["attachments"]
|
||||
for attachment in attachments:
|
||||
def do(self, attachment) -> None:
|
||||
attachment["delivery_period"] = 0
|
||||
logger.info(f"Срок доставки для файла {attachment["name"]} - только из наличия")
|
||||
|
||||
@@ -8,6 +8,7 @@ from email import encoders
|
||||
|
||||
|
||||
from ...abstract_task import AbstractTask, pass_if_error, handle_errors
|
||||
from ...exceptions import TaskExceptionWithEmailNotify
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -19,10 +20,10 @@ class EmailReplyTask(AbstractTask):
|
||||
"""Формирует ответ на входящее письмо с запросом на заказ°"""
|
||||
EMAIl = "zosimovaa@yandex.ru" #"noreply@zapchastiya.ru"
|
||||
|
||||
@pass_if_error
|
||||
#@pass_if_error
|
||||
#@handle_errors
|
||||
def do(self, attachment):
|
||||
|
||||
try:
|
||||
email = self.context.data.get("email")
|
||||
|
||||
if not email:
|
||||
@@ -52,7 +53,8 @@ class EmailReplyTask(AbstractTask):
|
||||
self.context.email_client.send_email(reply_message)
|
||||
|
||||
logger.warning(f"Сформирован ответ на заказ на email")
|
||||
|
||||
except Exception as e:
|
||||
raise TaskExceptionWithEmailNotify("Произошла ошибка при отправке уведомления клиенту об успешном заказе")
|
||||
|
||||
def _attach_file(self, reply_message, attachment):
|
||||
"""
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
from io import BytesIO
|
||||
from mail_order_bot.task_processor.abstract_task import AbstractTask, pass_if_error, handle_errors
|
||||
from mail_order_bot.task_processor.handlers.excel_parcers.order_extractor import ExcelFileParcer
|
||||
from ...exceptions import TaskExceptionWithEmailNotify
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -15,10 +16,13 @@ class ExcelExtractor(AbstractTask):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.excel_config = self.config.get("excel", {})
|
||||
|
||||
@pass_if_error
|
||||
#@pass_if_error
|
||||
#@handle_errors
|
||||
def do(self, attachment) -> None:
|
||||
try:
|
||||
file_bytes = BytesIO(attachment['bytes'])
|
||||
excel_file = ExcelFileParcer(file_bytes, self.excel_config)
|
||||
attachment["excel"] = excel_file
|
||||
logger.warning(f"Произведен успешный парсинг файла {attachment.get('name', 'неизвестный файл')}")
|
||||
except Exception as e:
|
||||
raise TaskExceptionWithEmailNotify("Произошла ошибка при парсинге эксель файла. Детали ошибки: {e}")
|
||||
|
||||
@@ -3,6 +3,7 @@ import pandas as pd
|
||||
from io import BytesIO
|
||||
from mail_order_bot.parsers.order_parcer import OrderParser
|
||||
from ...abstract_task import AbstractTask, pass_if_error, handle_errors
|
||||
from ...exceptions import TaskExceptionWithEmailNotify
|
||||
|
||||
from mail_order_bot.parsers.excel_parcer import ExcelFileParcer
|
||||
|
||||
@@ -19,8 +20,9 @@ class OrderExtractor(AbstractTask):
|
||||
self.excel_config = self.config.get("excel", {})
|
||||
|
||||
@pass_if_error
|
||||
#@handle_errors
|
||||
#@handle_errors("Произошла ошибка при парсинге заказа")
|
||||
def do(self, attachment) -> None:
|
||||
try:
|
||||
# todo сделать проверку на наличие файла и его тип
|
||||
delivery_period = attachment.get("delivery_period", 0)
|
||||
mapping = self.excel_config.get("mapping")
|
||||
@@ -36,6 +38,8 @@ class OrderExtractor(AbstractTask):
|
||||
attachment["order"] = order
|
||||
|
||||
logger.warning(f"Файл заказа обработан успешно, извлечено {len(order.positions)} позиций")
|
||||
except Exception as e:
|
||||
raise TaskExceptionWithEmailNotify(f"Ошибка при парсинге заказа. Детали ошибки: {e}")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
from ...abstract_task import AbstractTask, pass_if_error, handle_errors
|
||||
|
||||
from ...exceptions import TaskExceptionWithEmailNotify
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@ class UpdateExcelFile(AbstractTask):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.excel_config = self.config.get("excel", {})
|
||||
|
||||
@pass_if_error
|
||||
#@pass_if_error
|
||||
#@handle_errors
|
||||
def do(self, attachment) -> None:
|
||||
try:
|
||||
# todo сделать проверку на наличие файла и его тип
|
||||
excel_file = attachment.get("excel")
|
||||
order = attachment.get("order")
|
||||
@@ -43,3 +44,5 @@ class UpdateExcelFile(AbstractTask):
|
||||
excel_file.set_value(sku, manufacturer, column, value)
|
||||
|
||||
logger.warning(f"Файла {attachment.get('name', 'неизвестный файл')} отредактирован")
|
||||
except Exception as e:
|
||||
raise TaskExceptionWithEmailNotify(f"Не удалось отредактировать исходный файл с заказом. Детали ошибки: {e}")
|
||||
|
||||
@@ -9,6 +9,7 @@ import logging
|
||||
from ...abstract_task import AbstractTask, pass_if_error, handle_errors
|
||||
from mail_order_bot.abcp_api.abcp_provider import AbcpProvider
|
||||
from mail_order_bot.credential_provider import CredentialProvider
|
||||
from ...exceptions import TaskExceptionSilent
|
||||
|
||||
from mail_order_bot.telegram.client import TelegramClient
|
||||
|
||||
@@ -19,9 +20,10 @@ class TelegramNotifier(AbstractTask):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@pass_if_error
|
||||
#@pass_if_error
|
||||
# @handle_errors
|
||||
def do(self, attachment) -> None:
|
||||
try:
|
||||
message = self.build_message(attachment)
|
||||
|
||||
client = TelegramClient()
|
||||
@@ -36,6 +38,8 @@ class TelegramNotifier(AbstractTask):
|
||||
)
|
||||
|
||||
logger.warning("Инфо по заказу отправлено в телеграм")
|
||||
except Exception as e:
|
||||
raise TaskExceptionSilent(f"Ошибка при отправке в телеграм. Детали ошибки: {e}")
|
||||
|
||||
def build_message(self, attachment):
|
||||
order = attachment["order"]
|
||||
|
||||
@@ -15,17 +15,15 @@ from mail_order_bot.abcp_api.abcp_provider import AbcpProvider
|
||||
from mail_order_bot.credential_provider import CredentialProvider
|
||||
from mail_order_bot.order.auto_part_order import OrderStatus
|
||||
|
||||
from ...exceptions import TaskException
|
||||
from ...exceptions import TaskExceptionWithEmailNotify
|
||||
|
||||
from typing import Dict, Any
|
||||
from typing import List, Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class StockSelectorException(TaskException):
|
||||
pass
|
||||
|
||||
class RefusalLevelExceededException(TaskException):
|
||||
class RefusalLevelExceededException(TaskExceptionWithEmailNotify):
|
||||
pass
|
||||
|
||||
|
||||
@@ -46,6 +44,7 @@ class StockSelector(AbstractTask):
|
||||
#@handle_errors
|
||||
def do(self, attachment) -> None:
|
||||
# todo сделать проверку на наличие файла и его тип
|
||||
try:
|
||||
order = attachment.get("order", None)
|
||||
delivery_period = attachment.get("delivery_period")
|
||||
for position in order.positions:
|
||||
@@ -79,6 +78,11 @@ class StockSelector(AbstractTask):
|
||||
f"Уровень отказов: {refusal_level:.2%}, допустимый лимит: {refusal_threshold:.2%}")
|
||||
|
||||
logger.warning("Определены оптимальные позиции со складов")
|
||||
except RefusalLevelExceededException:
|
||||
raise RefusalLevelExceededException
|
||||
|
||||
except Exception as e:
|
||||
raise TaskExceptionWithEmailNotify(f"Произошла ошибка при выборе позиций со складов. Детали ошибки: {e}")
|
||||
|
||||
def get_optimal_stock(self, stock_list, asking_price, asking_quantity, delivery_period):
|
||||
"""Выбирает позицию для заказа"""
|
||||
|
||||
Reference in New Issue
Block a user