test_crm_framework_contract_amount.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """框架合同金额:有小计则累加,不再强制为 0。"""
  2. from decimal import Decimal
  3. from app.crud.crm.contract import _normalize_framework_contract_data
  4. def test_framework_sale_sums_fixed_line_subtotals():
  5. data = {
  6. "contractType": "framework_sale",
  7. "taxRate": 6,
  8. "products": [
  9. {
  10. "quantityMode": "fixed",
  11. "priceMode": "fixed",
  12. "quantity": 10,
  13. "price": 100,
  14. "subtotal": 1000,
  15. },
  16. {
  17. "quantityMode": "fixed",
  18. "priceMode": "fixed",
  19. "quantity": 2,
  20. "price": 50,
  21. "subtotal": 100,
  22. },
  23. ],
  24. }
  25. _normalize_framework_contract_data(data)
  26. assert Decimal(str(data["amount"])) == Decimal("1100")
  27. assert Decimal(str(data["amountWithTax"])) == Decimal("1166")
  28. def test_framework_purchase_mixed_market_rows_contribute_zero():
  29. data = {
  30. "contract_type": "framework_purchase",
  31. "tax_rate": 6,
  32. "productList": [
  33. {
  34. "quantity_mode": "fixed",
  35. "price_mode": "fixed",
  36. "quantity": 5,
  37. "price": 200,
  38. "subtotal": 1000,
  39. },
  40. {
  41. "quantity_mode": "customer_demand",
  42. "price_mode": "market",
  43. "quantity": 99,
  44. "price": 999,
  45. "subtotal": 9999,
  46. },
  47. ],
  48. }
  49. _normalize_framework_contract_data(data)
  50. market = data["productList"][1]
  51. assert market["quantity"] == 0
  52. assert market["price"] == 0
  53. assert market["subtotal"] == 0
  54. assert Decimal(str(data["amount"])) == Decimal("1000")
  55. def test_framework_all_market_amount_is_zero():
  56. data = {
  57. "contractType": "framework",
  58. "products": [
  59. {
  60. "quantityMode": "customer_demand",
  61. "priceMode": "market",
  62. "quantity": 1,
  63. "price": 10,
  64. "subtotal": 10,
  65. }
  66. ],
  67. }
  68. _normalize_framework_contract_data(data)
  69. assert Decimal(str(data["amount"])) == Decimal("0")
  70. assert Decimal(str(data["amountWithTax"])) == Decimal("0")
  71. def test_non_framework_unchanged():
  72. data = {
  73. "contractType": "sale",
  74. "amount": 500,
  75. "products": [{"quantity": 1, "price": 500, "subtotal": 500}],
  76. }
  77. _normalize_framework_contract_data(data)
  78. assert data["amount"] == 500