7-3 成本单价改为产品定价模板单价(base_unit_price)并显示单位

- 后端enrich_items_from_db返回base_unit_price和pricing_unit
- formula_detail支持面积/重量/件等多种定价类型
- 前端成本单价列显示如¥150/㎡而非一件总价¥6000

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wsb1224 2026-07-03 21:48:31 +08:00
parent 7117e8a8ef
commit dc417365de
2 changed files with 13 additions and 4 deletions

View File

@ -308,15 +308,24 @@ class OrderService:
rule = rules_map[item.product_id]
item_dict["formula_expr"] = getattr(rule, "formula_expr", None)
item_dict["formula_note"] = getattr(rule, "formula_note", None)
item_dict["base_unit_price"] = float(rule.base_unit_price or 0)
item_dict["pricing_unit"] = getattr(rule, "pricing_unit", None)
# 构建人类可读的计算过程
if not item_dict.get("formula_detail"):
try:
unit_price = float(rule.base_unit_price or 0)
pricing_type = getattr(rule, "pricing_type", "area") or "area"
pricing_unit = getattr(rule, "pricing_unit", "") or ""
qty = float(item.quantity or 0)
length = float(getattr(item, "length_m", 0) or 0)
width = float(getattr(item, "width_m", 0) or 0)
unit_price = float(rule.base_unit_price or 0)
if length and width and unit_price:
if pricing_type == "area" and length and width and unit_price:
area = length * width
item_dict["formula_detail"] = f"{length}m × {width}m × ¥{unit_price}/㎡ = ¥{area * unit_price:.2f}"
item_dict["formula_detail"] = f"{length}m × {width}m × ¥{unit_price}/{pricing_unit} = ¥{area * unit_price:.2f}"
elif pricing_type in ("kg", "weight_g") and qty and unit_price:
item_dict["formula_detail"] = f"{qty}{pricing_unit} × ¥{unit_price}/{pricing_unit} = ¥{qty * unit_price:.2f}"
elif unit_price:
item_dict["formula_detail"] = f"{qty}{pricing_unit} × ¥{unit_price}/{pricing_unit} = ¥{qty * unit_price:.2f}"
except Exception:
pass

View File

@ -334,7 +334,7 @@
<td>{{ item.demand_specification || "-" }}</td>
<td>{{ item.unit || '-' }}</td>
<td>{{ computeTotalDemand(item) || item.quantity }}</td>
<td>¥{{ Number(item.cost_price || 0).toFixed(2) }}</td>
<td>¥{{ Number(item.base_unit_price || item.cost_price || 0).toFixed(2) }}{{ item.pricing_unit ? '/' + item.pricing_unit : '' }}</td>
<td style="font-size:12px;color:#666;white-space:nowrap;">
{{ item.formula_detail || `${item.quantity} × ¥${Number(item.cost_price || 0).toFixed(2)}` }}
</td>