90 lines
3.6 KiB
Python
90 lines
3.6 KiB
Python
"""Contract draft input model for CONTRACT_CREATE."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from dataclasses import dataclass, field
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from .contract_flow_steps import ContractGoodsLine
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ContractDraft:
|
|
supplier_name: str
|
|
order_date: str
|
|
source_type: str
|
|
template_type: str = "FORMAT"
|
|
template_name: str = ""
|
|
customer_code: str = ""
|
|
customer_name: str = ""
|
|
contract_category: str = ""
|
|
settlement_type: str = "付款"
|
|
contract_background: str = ""
|
|
contract_nature: str = "主合同"
|
|
amount_currency: str = "人民币"
|
|
amount: str = ""
|
|
contract_end_date: str = ""
|
|
is_major_contract: str = "否"
|
|
is_prepayment: str = "否"
|
|
belong_year: str = ""
|
|
payment_method: str = "账期支付"
|
|
payment_days: str = "30"
|
|
contract_status: str = "正式合同"
|
|
contains_blood_products: str = "否"
|
|
submit_mode: str = "submit"
|
|
goods_lines: list[ContractGoodsLine] = field(default_factory=list)
|
|
platform_pdf_paths: list[str] = field(default_factory=list)
|
|
merged_pdf_path: str | None = None
|
|
order_no_list: list[str] = field(default_factory=list)
|
|
|
|
|
|
def load_contract_draft(path: str | Path) -> ContractDraft:
|
|
data = json.loads(Path(path).read_text(encoding="utf-8"))
|
|
return contract_draft_from_dict(data)
|
|
|
|
|
|
def contract_draft_from_dict(data: dict[str, Any]) -> ContractDraft:
|
|
goods_lines = [
|
|
ContractGoodsLine(
|
|
operation_code=str(item.get("operationCode", "")),
|
|
goods_code=str(item.get("goodsCode", "")),
|
|
goods_name=str(item.get("goodsName", "")),
|
|
approval_no=str(item.get("approvalNo", "")),
|
|
spec=str(item.get("spec", "")),
|
|
unit=str(item.get("unit", "")),
|
|
quantity=float(item.get("quantity", 0) or 0),
|
|
mdm_code=str(item.get("mdmCode", "")),
|
|
unit_price=str(item.get("unitPrice", "")),
|
|
)
|
|
for item in data.get("goodsLines", [])
|
|
]
|
|
return ContractDraft(
|
|
supplier_name=str(data.get("supplierName", "")),
|
|
order_date=str(data.get("orderDate", "")),
|
|
source_type=str(data.get("sourceType", "")),
|
|
template_type=str(data.get("templateType", "FORMAT")),
|
|
template_name=str(data.get("templateName", "")),
|
|
customer_code=str(data.get("customerCode", "")),
|
|
customer_name=str(data.get("customerName", "")),
|
|
contract_category=str(data.get("contractCategory", "")),
|
|
settlement_type=str(data.get("settlementType", "付款")),
|
|
contract_background=str(data.get("contractBackground", "")),
|
|
contract_nature=str(data.get("contractNature", "主合同")),
|
|
amount_currency=str(data.get("amountCurrency", "人民币")),
|
|
amount=str(data.get("amount", "")),
|
|
contract_end_date=str(data.get("contractEndDate", "")),
|
|
is_major_contract=str(data.get("isMajorContract", "否")),
|
|
is_prepayment=str(data.get("isPrepayment", "否")),
|
|
belong_year=str(data.get("belongYear", "")),
|
|
payment_method=str(data.get("paymentMethod", "账期支付")),
|
|
payment_days=str(data.get("paymentDays", "30")),
|
|
contract_status=str(data.get("contractStatus", "正式合同")),
|
|
contains_blood_products=str(data.get("containsBloodProducts", "否")),
|
|
submit_mode=str(data.get("submitMode", "submit")),
|
|
goods_lines=goods_lines,
|
|
platform_pdf_paths=[str(path) for path in data.get("platformPdfPaths", [])],
|
|
merged_pdf_path=data.get("mergedPdfPath"),
|
|
order_no_list=[str(x) for x in data.get("orderNoList", [])],
|
|
)
|