api 1.4
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from pydantic import ValidationError
|
||||
from server.backend.schemas.pydantic import ExcelInfo,settings
|
||||
from server.backend.api.nomenclature import nomenclature
|
||||
from server.backend.schemas.pydantic import ExcelInfo,settings,Translit
|
||||
from server.backend.api.nomenclature import processing
|
||||
import re
|
||||
|
||||
def process_sheet(df, real_arti:str, real_quantity:str, real_sum_1:str, real_sum_2:str):
|
||||
@@ -9,11 +9,12 @@ def process_sheet(df, real_arti:str, real_quantity:str, real_sum_1:str, real_sum
|
||||
df[real_sum_1]+=df[real_sum_2]
|
||||
df = df[[real_arti, real_quantity, real_sum_1]].copy()
|
||||
df.rename(columns={real_arti: 'arti', real_quantity: 'counts', real_sum_1: 'price'}, inplace=True) #переименовываем для pydantic
|
||||
df['arti'] = df['arti'].astype(str).str.extract(f'({settings.PATTERN})', flags=re.IGNORECASE) #arti под regex
|
||||
|
||||
df['arti'] = df['arti'].replace(Translit.TRANSLIT, regex=True)
|
||||
df['arti'] = df['arti'].astype(str).str.upper().str.extract(f'({settings.PATTERN})') #arti под regex
|
||||
df['price'] = df['price'].astype(float) #Float to Int, if exists
|
||||
df['counts'] = df['counts'].astype(int) #Float to Int, if exists
|
||||
df = df.groupby('arti', as_index=False).agg({'counts': 'sum', 'price': 'sum'}) #groupping
|
||||
df = processing(df) #vlookup for ref_keys
|
||||
validated_rows, errors = [], []
|
||||
for i, row in df.iterrows(): #проходит построчно по df, где i - индекс строки, row - данные строки
|
||||
try:
|
||||
@@ -22,7 +23,6 @@ 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') # номера столбцов от озона
|
||||
|
||||
Reference in New Issue
Block a user