feature/evaluating #2
10
makefile
10
makefile
@@ -1,4 +1,12 @@
|
||||
VENV=source ./.venv/bin/activate;
|
||||
.PHONY: run
|
||||
.PHONY: run run_full run_stocks run_orgs run_contractors
|
||||
run:
|
||||
$(VENV) python run.py
|
||||
run_full:
|
||||
$(VENV) python run.py --mode full
|
||||
run_stocks:
|
||||
$(VENV) python run.py --mode stocks
|
||||
run_orgs:
|
||||
$(VENV) python run.py --mode orgs
|
||||
run_contractors:
|
||||
$(VENV) python run.py --mode contractors
|
||||
27
run.py
27
run.py
@@ -1,3 +1,30 @@
|
||||
import server.backend.services.excel as excel
|
||||
from server.backend.services.validating_files import validating
|
||||
from server.backend.api import companies,contractors,storages
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description="Экспорт в Excel")
|
||||
parser.add_argument(
|
||||
"--mode",
|
||||
choices=["stocks", "orgs", "contractors", "full", "standart"],
|
||||
default="standart",
|
||||
help="Режим экспорта (по умолчанию: standart)"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
match args.mode:
|
||||
case "full":
|
||||
print("Режим:", args.mode)
|
||||
companies.companies()
|
||||
contractors.contractor()
|
||||
storages.storages()
|
||||
case "orgs":
|
||||
print("Режим:", args.mode)
|
||||
companies.companies()
|
||||
case "contractors":
|
||||
print("Режим:", args.mode)
|
||||
contractors.contractor()
|
||||
case "stocks":
|
||||
print("Режим:", args.mode)
|
||||
storages.storages()
|
||||
case "standart":
|
||||
print("Режим:", args.mode)
|
||||
print(validating())
|
||||
@@ -40,6 +40,7 @@ def parse_contragents(xml: str):
|
||||
return df
|
||||
except ET.ParseError:
|
||||
raise
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
print(root)
|
||||
def companies():
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
root.to_excel("./excel_files/companies.xlsx")
|
||||
@@ -44,6 +44,7 @@ def parse_contragents(xml: str):
|
||||
return df
|
||||
except ET.ParseError:
|
||||
raise
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
print(root)
|
||||
def contractor():
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
root.to_excel("./excel_files/contractors.xlsx")
|
||||
@@ -42,6 +42,6 @@ def parse_contragents(xml: str):
|
||||
return df
|
||||
except ET.ParseError:
|
||||
raise
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
print(root)
|
||||
def nomenclature():
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
|
||||
@@ -40,6 +40,7 @@ def parse_contragents(xml: str):
|
||||
return df
|
||||
except ET.ParseError:
|
||||
raise
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
print(root)
|
||||
def storages():
|
||||
xml_data = fetch_contragents()
|
||||
root = parse_contragents(xml_data)
|
||||
root.to_excel("./excel_files/storages.xlsx")
|
||||
@@ -1,5 +1,6 @@
|
||||
from pydantic import ValidationError
|
||||
from server.backend.schemas.pydantic import ExcelInfo,settings
|
||||
from server.backend.api.nomenclature import nomenclature
|
||||
import re
|
||||
|
||||
def process_sheet(df, real_arti:str, real_quantity:str, real_sum_1:str, real_sum_2:str):
|
||||
@@ -21,6 +22,7 @@ def process_sheet(df, real_arti:str, real_quantity:str, real_sum_1:str, real_sum
|
||||
errors.append((i, e.errors())) #выводит ошибку и пишет номер строки
|
||||
if errors:
|
||||
raise Exception(f"There are some errors with validation in Отчет о реализации, check it ", errors)
|
||||
|
||||
return validated_rows
|
||||
def evaluating(dfs):
|
||||
validated_rows_1 = process_sheet(dfs["Отчет о реализации"], real_arti='2',real_quantity='8', real_sum_1='5',real_sum_2='6') # номера столбцов от озона
|
||||
|
||||
@@ -10,9 +10,9 @@ class BaseHandler:
|
||||
self.file_path = file_path
|
||||
self.dfs = self.read()
|
||||
|
||||
def read(self):
|
||||
def read(self, skiprows=None, skipfooter=0):
|
||||
try:
|
||||
return pd.read_excel(self.file_path, sheet_name=None)
|
||||
return pd.read_excel(self.file_path, sheet_name=None, skiprows=skiprows,skipfooter=skipfooter)
|
||||
except Exception as e:
|
||||
raise Exception(f"⚠️ Ошибка при чтении {self.file_path}: {e}")
|
||||
|
||||
@@ -23,7 +23,7 @@ class YandexHandler(BaseHandler):
|
||||
def process(self):
|
||||
# читаем Excel внутри объекта
|
||||
#доставать дату
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=[0, 1, 3]) #skip header
|
||||
dfs = self.read(skiprows=[0,1,3])
|
||||
# проверяем наличие нужных листов
|
||||
if "Получено от потребителей" not in dfs or "Возвращено потребителям" not in dfs:
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
@@ -33,7 +33,7 @@ class YandexHandler(BaseHandler):
|
||||
|
||||
class WBHandler(BaseHandler):
|
||||
def process(self):
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None)
|
||||
dfs = self.read()
|
||||
#доставать дату по месяцу и просто день ставить последний
|
||||
if "Sheet1" not in dfs :
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
@@ -43,7 +43,7 @@ class WBHandler(BaseHandler):
|
||||
class OZONHandler(BaseHandler):
|
||||
def process(self):
|
||||
#Доставать № документа и дату
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=14, skipfooter=17) #skip the header and the footer
|
||||
dfs = self.read(skiprows=14, skipfooter=17)
|
||||
if "Отчет о реализации" not in dfs:
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
validated_data = ozon_handler.evaluating(dfs)
|
||||
@@ -52,7 +52,7 @@ class OZONHandler(BaseHandler):
|
||||
class OZONPurchasesHandler(BaseHandler):
|
||||
def process(self):
|
||||
#доставать дату и номер документа
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=12, skipfooter=1)
|
||||
dfs = self.read(skiprows=12, skipfooter=1)
|
||||
if "Отчет о выкупленных товарах" not in dfs:
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
validated_data = ozon_purchases_handler.evaluating(dfs)
|
||||
@@ -60,7 +60,7 @@ class OZONPurchasesHandler(BaseHandler):
|
||||
|
||||
class WBPurchasesHandler(BaseHandler):
|
||||
def process(self):
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skiprows=9, skipfooter=7)
|
||||
dfs = self.read(skiprows=9, skipfooter=7)
|
||||
if "Sheet1" not in dfs:
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
validated_data = wb_purchases_handler.evaluating(dfs)
|
||||
@@ -68,7 +68,7 @@ class WBPurchasesHandler(BaseHandler):
|
||||
|
||||
class OZONComHandler(BaseHandler):
|
||||
def process(self):
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
|
||||
dfs = self.read(skipfooter=1)
|
||||
if "Лист_1" not in dfs:
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
df = dfs["Лист_1"]
|
||||
@@ -81,7 +81,7 @@ class OZONComHandler(BaseHandler):
|
||||
|
||||
class WBComHandler(BaseHandler):
|
||||
def process(self):
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
|
||||
dfs = self.read(skipfooter=1)
|
||||
if "Лист_1" not in dfs:
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
df = dfs["Лист_1"]
|
||||
@@ -94,7 +94,7 @@ class WBComHandler(BaseHandler):
|
||||
|
||||
class YandexComHandler(BaseHandler):
|
||||
def process(self):
|
||||
dfs = pd.read_excel(self.file_path, sheet_name=None, skipfooter=1)
|
||||
dfs = self.read(skipfooter=1)
|
||||
if "Лист_1" not in dfs:
|
||||
raise Exception(f"В файле {self.file_path.name} отсутствуют необходимые листы")
|
||||
df = dfs["Лист_1"]
|
||||
|
||||
Reference in New Issue
Block a user