惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

PCI Perspectives
PCI Perspectives
J
Java Code Geeks
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
博客园 - 聂微东
雷峰网
雷峰网
The Cloudflare Blog
V
V2EX
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
爱范儿
爱范儿
NISL@THU
NISL@THU
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
腾讯CDC
罗磊的独立博客
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
S
Security Affairs
S
SegmentFault 最新的问题
月光博客
月光博客
P
Privacy International News Feed
Last Week in AI
Last Week in AI
博客园 - Franky
C
Cisco Blogs
宝玉的分享
宝玉的分享
Forbes - Security
Forbes - Security
WordPress大学
WordPress大学
博客园 - 叶小钗
L
LINUX DO - 最新话题
博客园_首页
Spread Privacy
Spread Privacy
大猫的无限游戏
大猫的无限游戏
S
Secure Thoughts
IT之家
IT之家
人人都是产品经理
人人都是产品经理
I
Intezer
W
WeLiveSecurity
C
CERT Recently Published Vulnerability Notes
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cyberwarzone
Cyberwarzone
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Security @ Cisco Blogs
L
Lohrmann on Cybersecurity
美团技术团队

博客园 - *感悟人生*

PDFtoEXCEL批量处理高保真同步格式 JS 逆向与前端安全加固实战指南 批量处理苹果电脑的HEIF格式转成JPG|PNG 邮件群发系统 注册授权--续 独立授权模块 --可以为你的程序或者工具加上一把锁 音频转换合并切割工具 修改文件重命名(1、默认去掉预览和备份,2、默认当前文件路径) AI 平台 SQL语句解析 扣代码中,遇到this 应该怎么处理 AST解OB混淆,适用大部分的混淆 Akamai的形成与风控分析:聚焦Akamai 3.0 执行py3o的重启脚本(包含手动执行,以及自动执行的脚本) reduce与map+filter的复杂计算场景 py3o中汇总的计算:sum reduce map 三种形式来处理对比 加密解密基本概念 MJ提示词自动批处理GUI版 uv 在 Python 开发中的常用命令详解 表单和载荷的区别,以及python和js在处理json时的空格问题。 R函数处理异步迭代,在爬虫中的作用。
py3o中数字金额转大写
*感悟人生* · 2025-07-03 · via 博客园 - *感悟人生*

py3o模板中利用libroffice中的calc来处理odoo中的模板打印

${eval("__import__('num2words')").num2words(round(sum(lowes.product_uom_qty * lowes.price_unit for lowes in objects.order_line if lowes.client_order_ref == order_ref), 2), to='currency', lang='en')}
round(sum(lowes.product_uom_qty * lowes.price_unit for lowes in objects.order_line if lowes.client_order_ref == order_ref), 2)是计算公式,得到的是一个数字。把这个数字转换成英文大写,如:
数字输出
1234.56 one thousand, two hundred and thirty-four point five six (不带单位)
1234.56(用 currency) one thousand, two hundred and thirty-four dollars and fifty-six cents

✅ 注意事项:

  • 如果用 to='currency'语言一定要是 'en',不要用 'zh' 否则报错。

  • 如果不加 to='currency',默认是纯英文数字大写,没有“美元”单位。

你可以通过 传入币种 作为参数来控制显示不同的货币。

${eval("__import__('num2words')").num2words(round(sum(lowes.product_uom_qty * lowes.price_unit for lowes in objects.order_line if lowes.client_order_ref == order_ref), 2), to='currency', lang='en', currency=currency_type)}

假设你希望根据传入的币种类型来显示不同的货币格式。首先,你可以使用这样的模板代码:

${currency_type == 'CNY' and '人民币' + eval("__import__('num2words')").num2words(round(sum(lowes.product_uom_qty * lowes.price_unit for lowes in objects.order_line if lowes.client_order_ref == order_ref), 2), to='currency', lang='zh') or
 currency_type == 'USD' and 'USD ' + eval("__import__('num2words')").num2words(round(sum(lowes.product_uom_qty * lowes.price_unit for lowes in objects.order_line if lowes.client_order_ref == order_ref), 2), to='currency', lang='en') or
 currency_type == 'EUR' and 'EUR ' + eval("__import__('num2words')").num2words(round(sum(lowes.product_uom_qty * lowes.price_unit for lowes in objects.order_line if lowes.client_order_ref == order_ref), 2), to='currency', lang='en')}

✅ 解释:

  1. 动态币种判断

    • currency_type'CNY' 时,显示 人民币

    • currency_type'USD' 时,显示 美元

    • currency_type'EUR' 时,显示 欧元

  2. num2words 的语言和货币处理

    • 使用 num2words 模块将数字转换为指定语言的货币大写。

  3. 传递 currency_type

    • 你需要在 Odoo 的报告上下文中,确保把币种类型(如 'CNY''USD''EUR')传递到模板中。