我需要在几个报告的标题中显示一个字符串,该字符串必须根据正在打印的报告进行更改。
到目前为止,我已经这样做了:
<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
... Print here what I need to show in sale order reports ...
</t>
...
</template>
它对我来说效果很好,但现在,字符串不依赖于模型/表,而是依赖于打印的报告。
我有一个模型,它有两个不同的报告要打印。如果打印了一个,我必须在标题中显示“X”,如果打印了另一个,我必须在标题中显示“Y”。它们之间没有区别,我的意思是,模型中没有允许我识别它们的属性。
例如,在之前的案例中,尽管有相同的模型,但由于 state 字段值,我能够显示正确的字符串:
<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o._table=='sale_order'">
<t t-if="o.state=='draft'">
... Print Sale Quotation ...
</t>
<t t-if="o.state!='draft'">
... Print Sale Order ...
</t>
</t>
...
</template>
但在这种情况下,没有任何字段可以帮助我。只有报告名称,所以我需要从标题中获取它。
有人知道如何实现吗?
最佳答案
我试过了,效果不错,希望你能理解。首先有一些 我知道(但不确定)的事实让我产生了这种逻辑。
docs 上的属性或 o (RecordSet 传递给报告)在 Qweb 上。o.env.context .为什么我们不使用 o.with_context 向魔术属性上下文添加键而不是添加属性?
使用 t-set 的力量我们可以添加一个额外的 key但我们需要确保我们之前这样做
我们调用<t t-call="report.external_layout">在报告模板中所以 external_layout可以找到
那个额外的key在上下文中^^
<!-- add extra key to context -->
<!-- you can set it one time on docs it's better -->
<t t-set="o" t-value="o.with_context(report_name='hello_report')"/>
<t t-call="report.external_layout">
现在因为上下文是 frozendict 实例或类似的东西(我不确定),我们可以使用 get默认
值以检查是否在上下文中传递了该特殊键。
<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('report_name', False) == 'hello_report'">
<!-- show what you want to show for this report -->
或者您可以通过在上下文中传递值本身来使这种行为变得普遍,从而使它变得更好
这将最大限度地减少 if statements 的数量在你的 external_layout 上。
<template id="external_layout_header" inherit_id="report.external_layout_header">
...
<t t-if="o.env.context.get('extra_value', False)">
<p t-esc="o.env.context.get('extra_value')"></p>
因此对于您需要它具有此行为的任何报告。
如果它存在,则继承模板并确保在调用 external_layout 之前添加 key 使用 x-path .
编辑:
这是在 odoo 中的结果示例 8.0我没有使用 inherit 我直接更新了 remplates。
销售订单模板
<template id="report_saleorder_document">
<t t-set="o" t-value="o.with_context(extra_info='show this on header')"/>
<t t-call="report.external_layout">
报表的外部布局
<template id="external_layout_header">
<div class="header">
<div class="row">
<t t-if=" 'extra_info' in o.env.context" >
<p t-esc="o.env.context.get('extra_info')"></p>
</t>
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
....
.....
...
结果是这样
关于xml - 如何在 Odoo 10 的 Qweb header 中获取 report_name?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53477734/
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我正在使用这个:4.times{|i|assert_not_equal("content#{i+2}".constantize,object.first_content)}我之前声明过局部变量content1content2content3content4content5我得到的错误NameError:wrongconstantnamecontent2这个错误是什么意思?我很确定我想要content2=\ 最佳答案 你必须用一个大字母来调用ruby常量:Content2而不是content2。Aconstantnamestart
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
这可能是个愚蠢的问题。但是,我是一个新手......你怎么能在交互式rubyshell中有多行代码?好像你只能有一条长线。按回车键运行代码。无论如何我可以在不运行代码的情况下跳到下一行吗?再次抱歉,如果这是一个愚蠢的问题。谢谢。 最佳答案 这是一个例子:2.1.2:053>a=1=>12.1.2:054>b=2=>22.1.2:055>a+b=>32.1.2:056>ifa>b#Thecode‘if..."startsthedefinitionoftheconditionalstatement.2.1.2:057?>puts"f