Commit 8dc775b3 authored by 邱阿朋's avatar 邱阿朋

refactor(src): 重构 SPA 数据处理逻辑

- 修改了 .gitignore 文件,排除 .env 和 pi* 文件
- 移除了 payment.py 中的注释代码
- 更新了 return_goods.py 和 spa_search.py 中的文件路径生成逻辑,增加了国家代码前缀
-优化了 spa_search.py 中的数据处理流程,调整了发票日期和资金类型的处理方式
- 改进了 test 函数,增加了对欧元符号的处理,并修改了输入输出文件名参数
parent 4e3e63ee
......@@ -10,4 +10,5 @@ refund
build
*.spec
payment
.env
\ No newline at end of file
.env
pi*
\ No newline at end of file
......@@ -315,7 +315,6 @@ def handle_data(detail_datum, vendor, deduction_points):
def main():
list_data = export_list_read_data()
# list_data = list_data[25:]
# 获取当前日期和时间并格式化
current_datetime = datetime.now().strftime('%Y-%m-%d-%H-%M')
......
......@@ -43,7 +43,7 @@ def export_list_read_data():
def export_item_read_data(return_id):
file_name = f"return_goods\\{return_id}.xls"
file_name = f"{country}_return_goods\\{return_id}.xls"
if not os.path.isfile(file_name):
while True:
try:
......
......@@ -119,7 +119,7 @@ def get_report_agreement_text(invoice_id):
def export_item_read_data(invoice_id):
file_name = f"spa\\{invoice_id}.xlsx"
file_name = f"{country}_spa\\{invoice_id}.xlsx"
if os.path.isfile(file_name):
df = pd.read_excel(file_name, sheet_name=None)
return df
......@@ -269,6 +269,11 @@ def process_small_items(item_list, relation_data, coop):
processed_item = coop.copy()
processed_item.pop("Agreement title")
processed_item.pop("Original balance")
processed_item.pop("Invoice date")
processed_item.pop("Funding Type")
processed_item["Invoice date"] = coop.get("Invoice date")
processed_item['Funding Type'] = coop.get("Funding Type")
processed_item["Order Date"] = item.get("Order Date")
processed_item['Purchase Order'] = relation.get("Purchase Order")
processed_item["Agreement Currency"] = item.get("Agreement Currency")
......@@ -330,12 +335,8 @@ def push_data_queue(file_name):
else:
parent_id = sheet_name
order_data = item_row.get('Order Date', "")
if order_data == "":
order_data = item_row.get('Receive Date', "")
push_data = {
'ad_date': order_data, # spa费用数据日期
'ad_date': item_row.get('Invoice date', ""), # spa费用数据日期
'erp_sku': item_row.get('ERP SKU', ""), # ERP SKU
'ad_amount': item_row.get('Original balance', ""), # spa费用金额
'ad_amount_currency': item_row.get('Agreement Currency', ""), # spa费用币制
......@@ -353,10 +354,11 @@ def push_data_queue(file_name):
rabbit.send_message(push_data)
def test(file_name):
def test(file_name, result_file_name):
log.info("开始读取数据....")
invoices = pd.read_excel('ContraCogsInvoices.xls')
invoices['Original balance'] = invoices['Original balance'].replace({'\$': '', ',': ''}, regex=True).astype(float)
invoices = pd.read_excel(file_name)
invoices['Original balance'] = invoices['Original balance'].replace({'\$': '', ',': '', '\€': '', },
regex=True).astype(float)
# 通过 Invoice ID 去重,并累加 Original balance
invoices = invoices.groupby('Invoice ID', as_index=False)['Original balance'].sum()
# 根据 Original balance 从小到大排序
......@@ -365,7 +367,7 @@ def test(file_name):
sorted_invoices.to_excel('origin.xlsx', index=False)
log.info("开始读取数据....")
data_dict = pd.read_excel(file_name, sheet_name=None, keep_default_na=False, na_values=[])
data_dict = pd.read_excel(result_file_name, sheet_name=None, keep_default_na=False, na_values=[])
sheet_data = []
for sheet_name, values in data_dict.items():
......@@ -373,7 +375,7 @@ def test(file_name):
for _, item_row in values.iterrows():
balance = item_row.get('Original balance', "")
if isinstance(balance, str):
balance = balance.replace('$', '').replace(',', '')
balance = balance.replace('$', '').replace(',', '').replace('€', '')
if sheet_name == 'Sheet1':
invoice_id = item_row.get('Invoice ID', "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment