78 lines
2.0 KiB
Python
78 lines
2.0 KiB
Python
from decimal import Decimal
|
|
|
|
from job import run_yaoex_pay
|
|
from settle import MallLine
|
|
|
|
|
|
class MemoryPayRepo:
|
|
def __init__(self, existing=None):
|
|
self.existing = existing or set()
|
|
self.saved: list[dict] = []
|
|
|
|
def load_existing_pay_keys(self):
|
|
return set(self.existing)
|
|
|
|
def save_pay_rows(self, rows):
|
|
self.saved.extend(rows)
|
|
|
|
|
|
def _line(**overrides) -> MallLine:
|
|
data = dict(
|
|
order_no="ZQD1",
|
|
parent_order_no="",
|
|
supplier_name="广东壹号药业有限公司",
|
|
status="待收货",
|
|
goods_name="阿莫西林",
|
|
product_code="2918",
|
|
bar_code="6921665004933",
|
|
unit_price=Decimal("10.00"),
|
|
pay_price=Decimal("9.85"),
|
|
qty=10,
|
|
goods_amount=Decimal("100.00"),
|
|
order_paid=Decimal("98.50"),
|
|
pay_order_dtl_id="",
|
|
)
|
|
data.update(overrides)
|
|
return MallLine(**data)
|
|
|
|
|
|
def test_job_attaches_dtl_and_inserts_without_cart():
|
|
repo = MemoryPayRepo()
|
|
details = {
|
|
"ZQD1": {
|
|
"productList": [
|
|
{
|
|
"orderDetailId": 881,
|
|
"productName": "阿莫西林",
|
|
"quantity": 10,
|
|
"payPrice4": 9.85,
|
|
}
|
|
]
|
|
}
|
|
}
|
|
summary = run_yaoex_pay(repo, [_line()], details)
|
|
assert summary.inserted == 1
|
|
assert summary.unmatched == 0
|
|
assert repo.saved[0]["oms_id"] == 0
|
|
assert repo.saved[0]["pay_order_dtl_id"] == "881"
|
|
assert repo.saved[0]["purchase_total"] == Decimal("98.5000")
|
|
|
|
|
|
def test_job_dry_run_does_not_insert():
|
|
repo = MemoryPayRepo()
|
|
details = {
|
|
"ZQD1": {
|
|
"productList": [
|
|
{
|
|
"orderDetailId": 881,
|
|
"productName": "阿莫西林",
|
|
"quantity": 10,
|
|
"payPrice4": 9.85,
|
|
}
|
|
]
|
|
}
|
|
}
|
|
summary = run_yaoex_pay(repo, [_line()], details, dry_run=True)
|
|
assert summary.inserted == 1
|
|
assert repo.saved == []
|