| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- """框架合同金额:有小计则累加,不再强制为 0。"""
- from decimal import Decimal
- from app.crud.crm.contract import _normalize_framework_contract_data
- def test_framework_sale_sums_fixed_line_subtotals():
- data = {
- "contractType": "framework_sale",
- "taxRate": 6,
- "products": [
- {
- "quantityMode": "fixed",
- "priceMode": "fixed",
- "quantity": 10,
- "price": 100,
- "subtotal": 1000,
- },
- {
- "quantityMode": "fixed",
- "priceMode": "fixed",
- "quantity": 2,
- "price": 50,
- "subtotal": 100,
- },
- ],
- }
- _normalize_framework_contract_data(data)
- assert Decimal(str(data["amount"])) == Decimal("1100")
- assert Decimal(str(data["amountWithTax"])) == Decimal("1166")
- def test_framework_purchase_mixed_market_rows_contribute_zero():
- data = {
- "contract_type": "framework_purchase",
- "tax_rate": 6,
- "productList": [
- {
- "quantity_mode": "fixed",
- "price_mode": "fixed",
- "quantity": 5,
- "price": 200,
- "subtotal": 1000,
- },
- {
- "quantity_mode": "customer_demand",
- "price_mode": "market",
- "quantity": 99,
- "price": 999,
- "subtotal": 9999,
- },
- ],
- }
- _normalize_framework_contract_data(data)
- market = data["productList"][1]
- assert market["quantity"] == 0
- assert market["price"] == 0
- assert market["subtotal"] == 0
- assert Decimal(str(data["amount"])) == Decimal("1000")
- def test_framework_all_market_amount_is_zero():
- data = {
- "contractType": "framework",
- "products": [
- {
- "quantityMode": "customer_demand",
- "priceMode": "market",
- "quantity": 1,
- "price": 10,
- "subtotal": 10,
- }
- ],
- }
- _normalize_framework_contract_data(data)
- assert Decimal(str(data["amount"])) == Decimal("0")
- assert Decimal(str(data["amountWithTax"])) == Decimal("0")
- def test_non_framework_unchanged():
- data = {
- "contractType": "sale",
- "amount": 500,
- "products": [{"quantity": 1, "price": 500, "subtotal": 500}],
- }
- _normalize_framework_contract_data(data)
- assert data["amount"] == 500
|