跳至内容
Odoo 菜单
  • 登录
  • 免费试用
  • 应用程序
    财务
    • 会计
    • 发票
    • 费用
    • 电子表格 (BI)
    • 文档
    • 电子签名
    销售
    • 客户关系管理
    • 销售
    • POS 销售点管理-零售
    • POS 销售点管理 - 餐厅
    • 订阅
    • 租赁
    网站
    • 网站设计
    • 电子商务
    • 博客
    • 论坛
    • 在线客服
    • 在线学习
    供应链
    • 库存
    • 制造
    • 产品生命周期
    • 采购
    • 维护保养
    • 品控
    人力资源
    • 员工
    • 招聘
    • 休假
    • 评价
    • 内部推荐
    • 车队
    营销
    • 社媒营销
    • 电邮营销
    • 短信营销
    • 近期活动
    • 营销自动化
    • 网上调查
    服务
    • 项目管理
    • 工时单
    • 现场服务
    • 服务台
    • 排期
    • 预约
    生产力
    • 讨论
    • 批核
    • IoT物联网
    • VoIP
    • 知识库
    • WhatsApp
    第三方应用软件 Odoo 定制 Odoo云端平台
  • 行业
    零售
    • 书店
    • 服装店
    • 家具店
    • 食品杂货店
    • 五金店
    • 玩具店
    餐饮与酒店服务
    • 酒吧及酒馆
    • 餐厅
    • 快餐
    • 民宿
    • 饮品分销商
    • 酒店
    房地产
    • 房地产代理
    • 建筑师事务所
    • 建造业
    • 地产管理
    • 园艺
    • 业主协会
    咨询
    • 会计师事务所
    • Odoo合作伙伴
    • 市场推广公司
    • 律师事务所
    • 人才招聘
    • 审核 & 认证
    制造
    • 纺织
    • 金属
    • 家具
    • 食品
    • 啤酒厂
    • 企业礼品
    保健与健身
    • 体育俱乐部
    • 眼镜店
    • 健身中心
    • 健康从业者
    • 药房
    • 发型屋
    商贸服务
    • 维修人员
    • IT 硬件及支持
    • 太阳能系统
    • 鞋匠
    • 清洁服务
    • 暖通空调服务
    其他
    • 非营利组织
    • 环境机构
    • 广告牌租赁
    • 摄影服务
    • 自行车租赁
    • 软件经销商
    浏览所有行业
  • 社区
    学习
    • 教学视频
    • 文档
    • 认证
    • 培训
    • 博客
    • 播客
    赋能教育
    • 教育计划
    • Scale Up! 商业游戏
    • 参观Odoo
    获取软件
    • 下载
    • 版本对比
    • 发布
    合作
    • Github
    • 论坛
    • 近期活动
    • 翻译
    • 成为合作伙伴
    • 合作伙伴服务
    • 注册您的会计事务所
    获取服务
    • 寻找合作伙伴
    • 查找会计服务
    • 预约顾问咨询
    • 安装及推行服务
    • 客户参考
    • 支持
    • 升级
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    获取演示
  • 定价
  • 技术支持

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • 客户关系管理
  • e-Commerce
  • 会计
  • 库存
  • PoS
  • 项目
  • MRP
All apps
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
帮助

Odoo qweb dynamic html generation

订阅

此帖文有活动时,接收通知

此问题已终结
xmlqwebreporting8.0
15 回复
16030 查看
形象
Paul Catinean

Hello everyone

I wanted to know how does one handle a dynamically generated xml code that is invalid before being proccessed 

For example generating a table that displays the information in two cells per row:

<t t-foreach="list" t-as="item">

    <tr t-if="item_even">

        <td><span t-field="item"></td>

    </tr t-if="item_odds>

</t>

This will not work since it's invalid xml because the closing tag has a property and neither will <t t-if="condition"> </tr> </t> since the closing tag is embeded in what the xml sees another tag

Alternatives to this would be looping over grouped items, two by two or how many you want per column, and placing them inside one <tr> in one loop but it's not that elegant

Any way around this?

3
形象
丢弃
Paul Catinean
编写者

That is the purpose of the var_last var_first and var_odds var_even (in your case i_last, i_first) to hold index information see: http://odoo-80.readthedocs.org/en/latest/reference/qweb.html#loops The logic of achieving this is not the problem it's just that it does not work in qweb.You need two in the same to make a two columned table. This means you have to open on even and close on odds so the end result is 1 2

Yenthe Van Ginneken (Mainframe Monkey)

Hmm I see I understood your question wrong so I've deleted my reply as it wasn't of any value then. I'm not sure about this though, interesting question. Upvoted it :)

Yenthe Van Ginneken (Mainframe Monkey)

Have a look at this by the way: http://odoo-80.readthedocs.org/en/latest/reference/qweb.html#attributes

Paul Catinean
编写者

My theory (though could very well be wrong) is that the error comes in even before qweb can kick into action.If qweb would come in and resolve the t-tags and loops it would result in valid xml code But before the qweb is parsed it's actually read as standard xml where it sees a closing tag having a attribute which is invalid syntax and stops dead.It does not know that the attribute is actually a qweb condition that will output a empty closing tag which will in the end compose valid XML

Leonardo Donelli

IMO looping on a grouped list it's the correct way and a lot more elegant than a conditional closing tag.

Sajin Aziz

is this what you are trying for (last answer) , it works in qweb reports.

形象
Leonardo Donelli
最佳答案

You say:

Alternatives to this would be looping over grouped items, two by two or how many you want per column, and placing them inside one <tr> in one loop but it's not that elegant

But I don't think that's true at all. Conceptually, it better represents what you are trying to do, while the conditional closing tag feels more like an hack.

Also notice that your code would not generate valid XML if the number of items is odd (it would never close the last <tr> tag), and generally that's the problem with what you wanted to do: you cannot be sure that the generated html will be valid after evaluation because it depends on the context.

To create a grouped list with groups of size n:

[ l[i:i+n] for i in xrange(0, len(l), n) ]

Examples:  

 l = range(7)
>>> [ l[i:i+2] for i in xrange(0, len(l), 2) ]
[[0, 1], [2, 3], [4, 5], [6]]
>>> [ l[i:i+3] for i in xrange(0, len(l), 3) ]
[[0, 1, 2], [3, 4, 5], [6]]
>>> [ l[i:i+4] for i in xrange(0, len(l), 4) ]
[[0, 1, 2, 3], [4, 5, 6]]

1
形象
丢弃
Paul Catinean
编写者

While indeed it is a limitation you cannot do conditional closing tags your explanation makes a lot of sense and it is the proper/better method of tackling this issue regardless of the templating system.Thank you for your complete and eloquent answer!

形象
Sajin Aziz
最佳答案

try This :

 <tr>
            <t t-foreach="list" t-as="item">

                    <td><span t-esc="item_index"/></td>
                    <t t-if="item_odd">
                        &lt;/tr &gt;
                        &lt;tr &gt;
                    </t>
            </t>

</tr>

5
形象
丢弃
Paul Catinean
编写者

Sajin indeed this solution works and provides the possibility of doing conditional closing tags i.e parsing xml that would otherwise be invalid.Thank you for your help!

Mersed Kahrimanovic

Actually this is the only and complete solution on the question above. I can confirm that it works now as well. Grouping is indeed better in some of the solutions - but somtimes - grouping is bad idea as well. Consider the "one data source" for the lets say select field. If you want to implement behaviour based on the data source - and present that select field as well on the frontend, then its much easier to have one object instead grouped one.

形象
Hardikgiri Goswami
最佳答案

Hello Paul,

As I observed you theory is on opposite way of qweb tag (specially for the ending tag).

But I can understand what kind of output you want.

You need to create list of list.

I am explaining by your example

<t t-foreach="list" t-as="item">

    <tr t-if="item_even">

        <td><span t-field="item"></td>

    </tr t-if="item_odds>

</t>

Here "list" is a list something like [1,2,3,4,5].
and it will print like 
1
2
3
4
5

and you want it like
1   2
3   4
5

If you want something like this, then you need to pass list of list like,
your "list" should be like [[1,2],[3,4],[5]] instead of [1,2,3,4,5].
Now you xml code should be something like.

<t t-foreach="list" t-as="row">

    <tr>
        <t t-foreach="row" t-as="item">

            <td><span t-field="item"></td>
        </t>
    </tr>

</t>

and python code for converting simple "list" this "list of list" is

Option 1 :


your_list = [1,2,3,4,5,6,1,2,3,4,5,6]
new_list = []
for i in range(0, len(your_list), 2):
    temp_list = [your_list[i]]
    if i < len(your_list)-1:
        temp_list.append(your_list[i+1])
    new_list.append(temp_list)
print new_list

Option 2 :

your_list = [1,2,3,4,5,6,1,2,3,4,5,6]
new_list1 = zip(*[iter(your_list)]*2)
print new_list1

4
形象
丢弃
Paul Catinean
编写者

Indeed Hardikgiri that is the alternative when looping through a grouped set

Hardikgiri Goswami

As per my knowledge solution for this question is not possible. I have tried two other ways but I got the error and stuck over there.

形象
Aldennis
最佳答案

I have a similar requirement but with three columns for a pay slip report. 

The solution that I came up with is to construct some part of the Qweb report in python and save the generated html in a text field.


Call the text field in the Qweb report like this:

<div t-field="o.field_name" t-options="{'widget':'html'}"/>


When the Qweb report gets generated, the content of the text field is rendered together with the rest of the report. I use this approach in Odoo13 but I guess will work on previous versions as well.

0
形象
丢弃
喜欢讨论吗?不要只阅读,加入进来!

立即创建账户,享受专属功能,与我们的精彩社区互动!

注册
相关帖文 回复 查看 活动
Replace stock inventory report
stock xml qweb reporting
形象
0
11月 15
4058
How can I display all tasks (including completed ones) in a QWeb report in Odoo?
qweb reporting
形象
形象
2
9月 24
3065
t-att-href url get error 已解决
xml qweb
形象
形象
2
4月 23
9711
odoo report columns not displaying
xml qweb layout reporting css
形象
0
3月 23
3318
v15: object has no attribute 'generate_report'
xml reporting
形象
0
5月 22
2874
社区
  • 教学视频
  • 文档
  • 论坛
开源
  • 下载
  • Github
  • Runbot
  • 翻译
服务
  • Odoo.sh 托管
  • 支持
  • 升级
  • 自定义开发服务
  • 教育
  • 查找会计服务
  • 寻找合作伙伴
  • 成为合作伙伴
关于我们
  • 我们的公司
  • 品牌资产
  • 联系我们
  • 招聘
  • 近期活动
  • 播客
  • 博客
  • 客户
  • 法律 • 隐私
  • 安全
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo致力于为企业管理提供高效智能的开源解决方案,是全球业内高速成长的软件服务商之一,逾七百五十万用户选择Odoo进行数字化升级。通过一系列全业务链覆盖、高度集成、简单易用的商业应用,助力企业实现信息化改革、降本增效并释放公司增长潜力。

Odoo独特的价值在于是一款非常容易使用又完全集成的应用。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now