AutoRpa/rpa_cart/tests/test_parse_xls.py

106 lines
2.9 KiB
Python

from decimal import Decimal
from pathlib import Path
import xlwt
from parse_xls import parse_order_xls
def test_parse_order_xls_reads_settlement_columns(tmp_path: Path):
path = tmp_path / "orders.xls"
book = xlwt.Workbook()
sheet = book.add_sheet("订单明细")
headers = [
"下单时间",
"创建人",
"订单号",
"父订单号",
"支付方式",
"商家",
"订单类型",
"订单状态",
"品名",
"产品编码",
"产品条码",
"医保编码",
"批准文号",
"规格",
"厂商",
"有效期",
"生产日期",
"批号",
"单价(元)",
"数量",
"商品金额(元)",
"折后单价",
"订单实付总金额",
"可获返利金(元)",
"收货地址",
"商品类目",
"上市持有人",
"药检链接",
]
for col, name in enumerate(headers):
sheet.write(0, col, name)
sheet.write(1, 2, "ZQD202609301753126875")
sheet.write(1, 5, "重庆亿昊药业有限公司")
sheet.write(1, 7, "待收货")
sheet.write(1, 8, "复方阿嗪米特肠溶片")
sheet.write(1, 9, "2918225766")
sheet.write(1, 10, "6922197100247")
sheet.write(1, 18, 65.49)
sheet.write(1, 19, 20)
sheet.write(1, 20, 1309.8)
sheet.write(1, 21, 65.49)
sheet.write(1, 22, 1309.8)
book.save(str(path))
lines = parse_order_xls(path)
assert len(lines) == 1
line = lines[0]
assert line.order_no == "ZQD202609301753126875"
assert line.supplier_name == "重庆亿昊药业有限公司"
assert line.status == "待收货"
assert line.bar_code == "6922197100247"
assert line.qty == 20
assert line.pay_price == Decimal("65.49")
assert line.unit_price == Decimal("65.49")
assert line.pay_order_dtl_id == ""
def test_parse_order_xls_takes_first_barcode_when_cell_has_many(tmp_path: Path):
path = tmp_path / "orders.xls"
book = xlwt.Workbook()
sheet = book.add_sheet("订单明细")
headers = [
"订单号",
"父订单号",
"商家",
"订单状态",
"品名",
"产品编码",
"产品条码",
"单价(元)",
"数量",
"商品金额(元)",
"折后单价",
"订单实付总金额",
]
for col, name in enumerate(headers):
sheet.write(0, col, name)
sheet.write(1, 0, "ZQD1")
sheet.write(1, 2, "广东壹号药业有限公司")
sheet.write(1, 3, "待收货")
sheet.write(1, 4, "参芪五味子片")
sheet.write(1, 5, "8353YCZ12965")
sheet.write(1, 6, "6930301630566,1601063192,6930301630627,6927245800070")
sheet.write(1, 7, 10)
sheet.write(1, 8, 1)
sheet.write(1, 9, 10)
sheet.write(1, 10, 10)
sheet.write(1, 11, 10)
book.save(str(path))
lines = parse_order_xls(path)
assert lines[0].bar_code == "6930301630566"