You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Frappe单据打印格式中添加金额总计

在Frappe单据打印格式中添加金额总计功能

你可以通过初始化总计变量、循环累加单行金额的方式实现需求,修改后的完整代码如下:

Item Code
Item Name
Qty
Rate
Selling Price

{%- set total = 0 -%}
{%- for row in doc.items -%}
{%
set rate=frappe.db.get_value("Item Price",{"item_code":row.item_code,"price_list":doc.price_list,"selling":1},"price_list_rate")
%}
{{row.item_code}}
{{row.item_name}}
{{row.qty}}
{{rate}}
{% set row_total = rate*row.qty|float %}
{{'%0.3f'| format(row_total)}}
{% set total = total + row_total %}
{%- endfor -%}

---
**Total:** {{'%0.3f'| format(total)}}

关键改动说明:

  • 循环开始前用{% set total = 0 %}初始化总计变量,初始值设为0
  • 计算单行售价时,先将结果存入row_total变量,既方便格式化输出,也便于后续累加
  • 每次循环末尾通过{% set total = total + row_total %}将当前行金额累加到总计中
  • 循环结束后,添加分隔线和总计行,用格式化后的数值展示最终总金额

内容的提问来源于stack exchange,提问作者habeeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 09:25:32