Commit 3fa0dfb5 authored by 邱阿朋's avatar 邱阿朋

回款数据

parent e61bb4a6
......@@ -48,9 +48,9 @@ def export_details_read_data(invoice_number):
try:
params = {
"invoiceNumber": invoice_number,
"payeeCode": "VECET",
"activeTab": "lineItems",
"invoiceNumber": invoice_number,
}
# 将字典转换为 URL 查询参数
query_string = urllib.parse.urlencode(params)
......@@ -80,10 +80,13 @@ def get_content(tree, row_index: int, cell_index: int) -> str:
def get_po_code(index, po_id) -> dict:
page.get("https://vendorcentral.amazon.com/po/vendor/members/po-mgmt/dashboard", timeout=3)
result = {
"index": index,
"po_id": po_id
}
page.get(f"https://vendorcentral.amazon.com/po/vendor/members/po-mgmt/order?poId={po_id}", timeout=3)
po_table = page.ele("#po-header", timeout=2).html
......@@ -146,8 +149,9 @@ def click_get_price_data():
# 使用 lxml 解析 HTML
tree = etree.HTML(page_html)
# 使用 XPath 查找第三个 span class="a-color-base invoice-property-field"
# price_variance_amount = tree.xpath('(//div[@class="a-column a-span4"][2]//span[@class="a-color-base invoice-property-field"])[3]/text()')
price_variance_amount = tree.xpath(
'(//div[@class="a-column a-span4"]//span[@class="a-color-base invoice-property-field"])[3]/text()')
'//span[contains(text(),"Price variance amount (price claim)")]/../../div[@class="a-column a-span6 a-span-last"]/span/text()')
# 检查内容是否有效
if price_variance_amount and price_variance_amount[0].strip() != "-":
page.ele("#pd", timeout=2).click()
......@@ -155,17 +159,18 @@ def click_get_price_data():
time.sleep(15)
table_html = page.ele(".a-bordered a-horizontal-stripes mt-table", timeout=2).html
return price_extract_data(table_html)
return []
except ElementNotFoundError:
page.refresh()
click_get_price_data()
def handle_price_data(price_data, detail_data):
result = None
result = {}
"""处理争议数据"""
for _, price in price_data:
if price['ASIN'] == detail_data['ASIN']:
result = detail_data.copy()
result['Quantity received'] = price['Quantity']
result['Amount'] = price['RESOLUTION_COST']
if price['RESOLUTION_DECISION'] == "Approved":
......@@ -218,6 +223,7 @@ def main():
# 获取当前订单的Payee和优惠比例
vendor_payment_terms = get_po_code(i, invoice_number)
time.sleep(1)
print(vendor_payment_terms)
vendor = vendor_payment_terms['vendor']
deduction_points = int(vendor_payment_terms['payment_terms'])
......@@ -235,19 +241,22 @@ def main():
for index, detail_datum in detail_data.iterrows():
# 正常回款数据
success_data = handle_data(detail_datum, vendor, deduction_points)
# 争议回款
price_data = handle_price_data(price_data, detail_datum)
price_data = handle_data(price_data, vendor, deduction_points)
# 将处理后的记录添加到临时列表
normal_pay_data.append(success_data)
# 将处理后的记录添加到临时列表
price_pay_data.append(price_data)
if price_data:
# 争议回款
price_data = handle_price_data(price_data, detail_datum)
price_data = handle_data(price_data, vendor, deduction_points)
# 将处理后的记录添加到临时列表
price_pay_data.append(price_data)
# 添加到汇总列表
all_normal_pay_data.append(pd.DataFrame(normal_pay_data))
all_price_pay_data.append(pd.DataFrame(price_pay_data))
if len(price_pay_data) > 0:
all_price_pay_data.append(pd.DataFrame(price_pay_data))
# 将所有数据合并为一个 DataFrame
normal_pay_summary = pd.concat(all_normal_pay_data, ignore_index=True)
......
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