SuperAPI AI 工具集

print-format

通用与其它

查看项目

更新于 10-16 05:43

技能介绍

用途:为 Frappe v14+ 设计打印格式(Print Format),用 Jinja 模板生成收据、证书、发票等 PDF 文档,并遵循团队 edu_quality 约定。

主要能力:支持四种格式类型——Standard(由 DocType 字段自动生成)、Custom(Print Format Builder,存 format_data JSON)、Jinja(文件式,手写 html,可进 git)、Server-side(控制器 get_print_html 动态生成)。模板内可用 doc、frappe、_、print_settings、lang 等上下文变量,支持 frappe.db.get_value 内联查询、fmt_money 货币格式化、money_in_words 金额大写、formatdate/format_time/format_datetime 日期时间格式化、page-break 分页与 thead 表头跨页重复。

团队约定:格式自包含,不使用 {{ letter_head }} 或 {{ footer }};pdf_generator 固定为 "wkhtmltopdf";日期统一 formatdate(doc.field, "dd-MM-yyyy");货币用 Rs. 而非 ₹;四边 margin 15.0,page_number 为 "Hide",standard 为 "Yes",print_format_type 为 "Jinja"。文件位于 {app}/{module}/print_format/{slug}/{slug}.json,HTML 内嵌于 JSON 的 html 字段,通过 hooks.py 的 fixtures 与 bench export-fixtures 提交。

使用方式:手写 Jinja 格式时设 custom_format: 1;Builder 布局用 custom_format: 0。CSS 需内联在 body 的 <style> 中,图片用绝对 URL(如 {{ frappe.utils.get_url() }}/files/logo.png)。

限制与注意:wkhtmltopdf 为旧版 Webkit 引擎,不支持 CSS Grid/现代 flexbox,@font-face 支持有限,₹ 常渲染为 ?,<head> 中的 <style> 被忽略,相对图片 URL 无法抓取,异步图片可能竞态。模板中超过 5–6 次 frappe.db.get_value 建议改用控制器 get_context 以避免 N+1。不要直接渲染 doc.posting_date 原始值。

适用场景:Frappe 应用中的收据、证书、发票等打印与 PDF 输出。具体收费、价格、平台等信息暂未提供。