Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amazon_reports
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
common
amazon_reports
Commits
3fa0dfb5
Commit
3fa0dfb5
authored
Oct 18, 2024
by
邱阿朋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
回款数据
parent
e61bb4a6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
invoices.py
invoices.py
+21
-12
No files found.
invoices.py
View file @
3fa0dfb5
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment