多图翻译加整理测试:英中对照:Odoo报表入门Step by Step,Odoo创建一份报表到打印下拉菜单中
-
多图翻译加整理测试:英中对照:Odoo报表入门Step by Step,Odoo创建一份报表到打印下拉菜单中
原文来自:Multiple report layout step by step
[检测到链接无效,已移除]
How to implement another report in the print drop down menu? (e.g. like this for sale orders)
怎样 实现 在 打印 下拉菜单 里面 增加 另外一个 报表。(比如 在销售订单 的 打印 这里)
[attachimg=1]
STEP #1 – create a new report 第一步: 创建一张新的报表
Goto Settings > Technical > Reports > Reports, create a new report and fill out the four mandatory fields:
去 设置- 技术- 报表-报表 ,创建一张新报表 填写 下面 4个 区域的内容:
[attachimg=2]
After saving this report please have a look in your browser address bar. There you can easily see the report’s id (something like “#id=1234″) – you need this id for a later step.
保存报表时,看一下浏览器中的地址栏,您可以发现报表的Id (类似 id=458) ,最后一步(第四步)时,您需要
用到这地址
[attachimg=3]
STEP #2 – create a new view 第2步: 创建一个新的视图
Goto Settings > Technical > User Interface > Views, create a new view and fill out following fields:
设置-技术-用户界面-视图 ,创建 一个新的 视图,填写下面的区域:
[attachimg=4]
架构这里 填写参考:<?xml version="1.0"?> <t t-name="sale.another_report"> <div class="page"> Hello world! </div> </t>
提示:其实这里可以直接复制本来的 销售订单的 报表。现在这样,打印出来的another_report 就是Hello world!.
[color=red]注意 t-name 后面的 "sale.another_report" [/color]
When View Name is the same as in Template Name (from STEP #1) Odoo automatically associates this view to the given report.
当视图名称和 (第一步的)模版名称相同时Odoo 自动关联这个视图到报表。
After saving this view have a look in your browser address bar. There you can easily see the view’s id (something like “#id=1234″) – later you will need this id.
保存这个 视图 时,观察下浏览器 ,记录下 这个 视图的id (比如:1035) 注意 这个 id 是用于 第三步的。
STEP #3 – create a new identifier 步骤3 - 创建一个新的id
Goto Settings > Technical > Sequences & Identifiers > External Identifiers, create a new identifier and fill out the following fields:
设置-技术-序号和标识-外部标识,创建一个 新的 id 标识,填写下面的区域:
[attachimg=5]
Record ID is the view id you found in STEP #2 这个 id 是填写 第二步时的 id
STEP #3 – create a new identifier 步骤4:创建一个 新的动作绑定
Goto Settings > Technical > Actions > Action Bindings, create a new action binding and fill out following fields:
设置-技术-动作-动作绑定 创建一个 新的 动作绑定,填写下面的区域
[attachimg=6]
Qualifier 是 限定 在 client_print_multi
The number specified in Action Reference is the report id you got in STEP #1
动作引用 这里的 id是填写步骤1的 id.
动作引用这里: ir.actions.report.xml,458 (注意这个id 是第一步时看到的报表的id)
就这样成功了:
[attachimg=7]
要特别注意 : 第一步 创建报表时 保存后 ,浏览器中看到的 id 是 第四步 创建 动作绑定用,
第二步 创建 视图 浏览器中看到的id 是 第三步 创建 外部id 用的。
另外,odoo8.0 其实 报表可以 以所见即所得的方式 在线 编辑。
1:更改报表的方式 为html,
2:安装 website 的模块,
3:再打印这个报表 ,就可以 像编辑odoo的网站一样编辑 报表了。(注意,编辑之前推荐备份此报表)
更多报表设计原文参考: [检测到链接无效,已移除]
祝你们成功。
谢谢 OpenERP- 应用群 212904 中 台湾台北-Jason 提供的教程链接。 (很早就给我了,我一直忘记做测试) -
已经开始翻译 Odoo报表进阶, (初学者先把 报表入门的练习完成,进阶部分,我就只做翻译了)
卓忆翻译:英中对照:Odoo报表设计进阶篇 (第一部分)
Report Design Workshop
原文:<br / [检测到链接无效,已移除] br />
转载请注明翻译及原文出处,谢谢
In this workshop we will create a brand new report from scratch.
Usually you are starting with a moupck you want to implement. Therefore you have to subdivide it into four views:
在这个讲座里我们会 从头开始 创建一份较完整的 Odoo报表。我们将此报表 细分为4个视图 (视图another_report 由另外3个视图组成):
[attachimg=1]
STEP#1 – creating four views 第一步#1 - 创建4个视图
Goto Settings > Technical > User Interface > Views and create:
设置 - 技术 - 用户界面 - 视图 创建
视图1 : another_report , 填写 下面的内容 :
[attachimg=2]
another_report who is generating content and calling another_layout
视图2 another_layout 填写下面的内容:
[attachimg=3]
another_layout who is calling the header and footer
another_layout 的 头部 的 视图 another_layout_header :
[attachimg=4]
another_layout 的 底部 的 视图 another_layout_footer :
[attachimg=5]
Generally the t-call directive loads sub-templates inside a view architecture. But these sub-templates of course can only be found when they are identifiable by the Odoo system. That’s why we need to create an external identifier for each of them.
t-call 命令 是 加载 子模版 到 一个视图架构。 不过 这些 子模版 需要是 Odoo系统可 辨认的。所以 我们 需要为 这些 子模版 创建 外部id 。
注意:每保存上面的一个视图 都 在 浏览器 中 记录下 相关id (在步骤2中 我们会用到)
STEP#2 – creating four identifiers 步骤#2 - 创建4个 id
Goto Settings > Technical > Sequences & Identifiers > External Identifiers and create:
去 设置 - 技术 - 序号和标识 - 外部id 创建 :
[attachimg=6]
[attachimg=7]
[attachimg=8]
[attachimg=9]
Please note: the Record ID is the id you see in the browser’s address bar when you open a view (s.th. like “…/web#id=603&view_type=…”)
这些 ID 就是 您 打开 对应的 视图 时 在 浏览器 地址栏 中 看到的 id
Odoo报表入门 里面 也有 类似的过程。http://shine-it.net/index.php/topic,17350.0.html
STEP#3 – implementing the report 步骤#3 - 完成报表
Goto Settings > Technical > Reports > Reports and create a report with these mandatory fields filled out:
去设置 - 技术 - 报表 - 报表 里 创建 一个报表 并填写下列内容:
[attachimg=10]
Please note: Odoo recognizes account.another_report as the QWeb view from STEP #1 because we created already an external identifier in STEP #2. So it is automatically associated to this report.
请注意: 在步骤#1中 Odoo 能识别 account.another_report 为QWeb 视图 是 因为 我们 在 步骤#2 中 创建了 外部id.
所以它自动关联到此报表。
记录下 这个报表 在 浏览器 地址栏中的 id ,在 下面 创建 动作绑定 时 您会用到它。 -
Odoo报表设计进阶 第二部分:
To gain more flexibility create your own paper format under Settings > Technical > Reports > Paper Format and create a format like this and associate it to our new Another Report:
要增加更多的纸张格式 可在设置 - 技术 - 报表 - 纸张格式 中 创建 新的 格式 并 关联它 到 我们的 Another Report:
[attachimg=2]
Go now to Settings > Technical > Actions > Action bindings and create a new action binding to generate another item in the print drop down menu for invoices:
去 设置 - 技术 - 动作 - 动作绑定 创建 一个 新的动作绑定 生成 到 发票 处的 打印 菜单 里:
[attachimg=3]
Please note: the Action Reference contains the id of the report you created in this step (you can find the id in the address bar of your browser while the report is shown – should be s.th. like “…/web#id=331&view_type=…”)
请注意: 动作参考 这里 需包含 步骤#3 最开始 您所创建 的报表Another Report 的 id (您可以 找到这个id 在 您打开 对应 报表的 浏览器地址栏中 - 就像 “…/web#id=331&view_type=…”)
[attachimg=4]
From now on you should be able to choose your new report design in the printing menu for any invoice in Odoo.
This makes it very easy to test our layout during the next steps!
Test it now and Another Report will currently print a blank page. So it’s time to start with the view architectures!
现在您可以在 Odoo的 发票 打印菜单 中 选择 您 新设计的报表 。
在做下一步之前您 很容易测试 它 !
测试发现 此报表 目前 并没有内容 。所以 是时候 开始设计界面了!
STEP#4 – header architecture 步骤#4 - 报表头部的结构
Goto Settings > Technical > User Interface > Views and edit the another_layout_header view you created in STEP#1:
在 设置 - 技术 - 用户界面 - 视图 中 编辑 您在 步骤#1 中 创建的 another_layout_header 填入以下内容:
<?xml version="1.0"?>
<t t-name="report.another_layout_header">
<div class="header">
<div class="row">
<div class="col-xs-4 col-xs-offset-8">
<img src='/document/static/img/company_logo.png'/>
</div>
</div>
</div>
</t>
Please note: for storing the image file we used a path known to Odoo. You can choose any path of a module folder – even when the app is not installed.
The header consists of one row only. The image width is a third of the page’s width and positioned on the right edge (col-xs-4 and col-xs-offset-8 explained here).
Our report header – so far…
请注意: 我们使用了Odoo已知的路径来保存 图形。 您可以 选择 模块目录的 任意 路径 - 即使这个模块并未被安装。
头部只包含一行。 图形的 宽度 是1/3 页面 位于 我们报表头部的 右边 -- ..
[attachimg=5]
STEP#5 – footer architecture 步骤#5 -- 报表底部的结构
According to our invoice mockup we should try to create an overall layout structure. That’s why we are conforming the footer with the header by subdividing with same proportions:
按照我们发票我们试着创建所有的布局结构。这是之所以我们需要确认底部与顶部有着相同的比例的原因。
[attachimg=6]
The footer has a right column with a width of a third of the page’s width – same as the header with its logo on the right. We subdivide the wished information into three rows.
底部 右侧有一个 1/3页面宽度 的栏 - 和 顶部 的logo 相呼应 。我们再把 要增加的信息 细分到 3行。
So goto Settings > Technical > User Interface > Views now and edit the another_layout_footer view you created in STEP#1:
去 设置 - 技术 - 用户界面 - 视图 中编辑 步骤#1 创建的 another_layout_footer 为下面的内容:
<?xml version="1.0"?>
<t t-name="report.another_layout_footer">
<div class="footer">
<!-- FIRST ROW -->
<div class="row">
<div class="col-xs-8">
<strong>General Information:</strong><br/>
Line 1<br/>
Line 2<br/>
Line 3<br/>
Line 4
</div>
<div class="col-xs-4" style="text-align:right">
<strong>Bank Details:</strong><br/>
Line 1<br/>
Line 2<br/>
Line 3<br/>
Line 4
</div>
</div>
<!-- SECOND ROW -->
<div class="row mt16 mb16" style="text-align:center"> <strong>THANK YOU FOR YOUR BUSINESS</strong>
</div>
<!-- THIRD ROW -->
<div class="row" style="background-color:#568eff;color:#ffffff;">
<div class="col-xs-8">
<strong>Company Tag Line</strong><br/>
Line 1<br/>
Line 2<br/>
Line 3
</div>
<div class="col-xs-4" style="text-align:right">
Page <span class="page"/> of <span class="topage"/>
</div>
</div>
</div>
</t>
Please note: the two span tags with the classes “page” and “topage” will be replaced by the given page numbers via javascript during the rendering.
The result should look like this:
请注意: 有2个 范围标签 : “page”和“topage” 通过javascript渲染将会给页面编码 。
结果会是下面这样的:
[attachimg=7]
STEP#6 – report architecture 步骤#6 - 报表结构
Let’s subdivide the main part of the report with same proportions (2/3 and 1/3 horizontally) as we did with the header and footer:
让我们用相同的 比例 划分 报表主要的部分 (水平 2/3 和 1/3 )就像我们报表的 顶部和底部一样。
[attachimg=8]
As you can see – we need at least six rows.
Goto Settings > Technical > User Interface > Views and edit the another_report view you created in STEP#1:
如图您看到的- 我们需要至少6行。
去 设置 - 技术 - 用户界面 - 视图 中编辑 步骤#1 创建的 another_report 为下面的内容:
<?xml version="1.0"?>
<t t-name="account.another_report">
<t t-call="report.another_layout">
<t t-foreach="docs" t-as="o"> <!-- this makes the context model data accessible throughout the variable "o" -->
<div class="page">
<!-- FIRST ROW -->
<div class="row">
<div class="col-xs-12" style="background-color:#568eff;border: 1px solid #568eff;color:#ffffff;">
<h3>INVOICE</h3>
</div>
</div>
<!-- SECOND ROW -->
<div class="row">
<div class="col-xs-8" style="border-left:1px solid #568eff;">
<strong>BILL TO:</strong><br/>
Line 1<br/>
Line 2<br/>
Line 3
</div>
<div class="col-xs-2" style="text-align:right;border-left:1px solid #568eff;">
<strong>Invoice No.:</strong><br/>
<strong>Invoice Date:</strong><br/>
<strong>Due Date:</strong><br/>
<strong>PO No.:</strong>
</div>
<div class="col-xs-2" style="border-right:1px solid #568eff;">
<span t-field="o.number"/><br/><!-- example of how to access field values -->
Line 2<br/>
Line 3<br/>
Line 4
</div>
</div>
<!-- THIRD ROW -->
<div class="row">
<div class="col-xs-12" style="border:1px solid #568eff;">
<strong>PROJECT:</strong><br/>
Line 1
</div>
</div>
<!-- FOURTH ROW -->
<div class="row mt32" style="background-color:#568eff;border: 1px solid #568eff;color:#ffffff;">
<div class="col-xs-1">NO.</div>
<div class="col-xs-7">DESCRIPTION</div>
<div class="col-xs-1">UOM</div>
<div class="col-xs-1">QTY</div>
<div class="col-xs-1">UNIT RATE</div>
<div class="col-xs-1">AMOUNT</div>
</div>
<!-- FIFTH ROW -->
<div class="row">
<div class="col-xs-1" style="border-left:1px solid #568eff;">1.</div>
<div class="col-xs-7" style="border-left:1px solid #568eff;">Line 1 Item Description</div>
<div class="col-xs-1" style="border-left:1px solid #568eff;">100.00</div>
<div class="col-xs-1" style="border-left:1px solid #568eff;">1</div>
<div class="col-xs-1" style="border-left:1px solid #568eff;">100.00</div>
<div class="col-xs-1" style="border-left:1px solid #568eff;border-right:1px solid #568eff;">100.00</div>
</div>
<!-- SIXTH ROW -->
<div class="row">
<div class="col-xs-10" style="text-align:right;border: 1px solid #568eff;">
<strong>Total:</strong>
</div>
<div class="col-xs-2" style="text-align:right;border: 1px solid #568eff;border-left:0px;">
<strong>100.00</strong>
</div>
</div>
</div>
</t>
</t>
</t>
The complete report should now look like this:
最后完成的报表会是下面这样的:
[attachimg=9]
Please note: depending of your wkhtmltopdf version you now may have to adjust a little bit the used CSS styles.
请注意: 基于不同的wkhtmltopdf 版本,您可能需要微微调整使用的CSS样式。
转载请注明翻译及原文出处,谢谢
Odoo报表设计进阶到此完成
翻译难免有所疏漏,望见谅,另外这个报表进阶的内容,目前并未测试。
下面是 Odoo报表设计基础 ,供大家参考
原文: Odoo report design basics : [检测到链接无效,已移除]
Odoo helps to uniform reports by providing an overall layout structure of individual rows subdivided into twelve columns.
Odoo 报表,提供一个 12列 的 结构细分:
[attachimg=1]
A
Every sheet in Odoo has a top, bottom, left and right margin specified in millimeters in Settings > Technical > Reports > Paper Formats.
在 设置- 技术- 报表 -报表格式 中 :
Odoo 中所有的表单都有 以毫米为单位的 上,下,左和右边距
B
Odoo subdivides a sheet into rows (CSS class “row”) with a top margin (CSS class “mt”) and a bottom margin (CSS class “mb”). To define e.g. a row with 8px top margin and 32px bottom margin you need the following code:
Odoo 把表单 细分为 行 (CSS类的“行”)在 上边距(CSS 类 “mt”)和 下边距 (CSS类“mb”)。
要定义一个类似 8px(像素) 的上边距及32px(像素)的下边距,您需要下列代码:
<div class="row mt8 mb32">Your new line!</div>
Available margins are: mt0, mt4, mt8, mt16, mt32, mt48, mt64, mt92, mt128, mb0, mb4, mb8, mb16, mb32, mb48, mb64, mb92, mb128
可用的上下边距有: mt0, mt4, mt8, mt16, mt32, mt48, mt64, mt92, mt128, mb0, mb4, mb8, mb16, mb32, mb48, mb64, mb92, mb128
C
Odoo subdivides each row into twelve columns. To specify a certain position and width of a div container there are two CSS class names to use – for defining the width “col-[screensize]-[column-factor]” and for defining the position “col-[screensize]-[position-type]-[column-factor]”.
To define e.g. a centered div container of 50% width you need the following code:
Odoo 把每行分为12列。想要定义 位置和宽度 需要使用 另外2个 CSS 类
- 定义宽度 “col-[screensize]-[column-factor]”
定义 位置 “col-[screensize]-[position-type]-[column-factor]”.
要定义 一个 居中 的 50%宽度 您 需要下面的代码:
<div class="col-xs-6 col-xs-offset-3">Big centered container</div>
Explanation 说明:
col-xs-6 means a width of 6 columns. Because there is a total of 12 columns this is exactly the half of it – to say 50%
col-xs-6 表示宽度为6列。由于总共有12列,所以6列就是50%宽度。
col-xs-offset-3 means the container starts to display after a width of 3 columns. Because there is a total of 12 columns and the container itself is exactly 6 columns wide there are also 3 columns left on its right side. Thats why the container is in the middle of the sheet.
col-xs-offset-3 表示从第3列的后一列开始 ,总列数是12,宽度是6,从第3列之后一列开始,刚好就是居中的位置。
Available screensizes 可用的 屏幕尺寸
xs (width smaller than 768px), sm (min-width: 768px), md (min-width: 992px), lg (min-width: 1200px)
xs (宽度小于 768像素),sm(最小宽度:768像素),md (最小宽度:992像素),lg (最小宽度:1200像素)
Available column-factors 可用的 列 :
1,2,3,4,5,6,7,8,9,10,11,12
Available position-types 可用的位置类型:
offset (absolut horizontal position in a row),
offset ( 行内的绝对水平位置),
pull (relative position, on the left hand of the last div element),
pull ( 左起到末尾的相对位置),
push (relative position, on the right hand of the last div element)
push (右起到末尾的相对位置)
Example: to position a small container (only one column width) on the right side of the big one (see example above) with two columns distance you need the following code:
例: 在右边大一点的2列的 区块 边 定位1个(仅1列宽度)的区块(见最上方的示意图) 您需要下面的代码 :
<div class="col-xs-1 col-xs-push-2">Little container on the right</div>
转帖烦请 注明 出处,谢谢
翻译难免有所疏漏,望诸位海涵。谢谢大家。 -
原文: http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/
Inheriting and modifying QWeb reports
继承及修改QWeb报表
Hi guys,
In this tutorial you will learn how to inherit already existing QWeb reports in a custom module. After this tutorial you will be able to inherit and modify any already existing QWeb report in Odoo!
In this example I will modify the default Quotation / order report through inheritance and I will remove a few elements from the report.
大家好,
在这个教程中您会学习到如何写一个模块来继承一个现有的QWeb报表。在这个教程之后,您能继承和修改任何现有的Odoo中的QWeb报表。
1. Creating a new module创建一个新模型
The first step is to create a new module. The correct behaviour in Odoo is to always inherit, don’t ever modify existing files. Start by creating yourself a new module.
Tip: use the scaffold command from Odoo!
第一步创建一个新模型。在Odoo正确的做法是使用继承,而不是直接修改现有文件。从创建一个新模块开始。
提示:可以使用在Odoo中使用scaffold命令来创建新模块如下:
[attachimg=1]
This will create a new module from scratch and the default structure of your module is already there.
这会从草稿创建一个包含默认结构的新模块。
2. Creating your XML file创建XML文件
The next step is to open up your XML file (in my example templates.xml) and to create a new record to inherit the report. To inherit a report you have to know in which module it is and what the original XML id of the report is. So, how do you find this?
The easiest way is to go to ‘Settings’ > ‘Reports’ > ‘Reports’ and to search the report you want to modify. In this tutorial this will be the quotation/order report so I’ll search for ‘Order’:
接下来打开您的XML文件,创建新的纪录来继承报表。您需要知道需要继承的报表的模块的名称以及XML id.
如何找到他们呢?
最简单的方法是到‘设置’>‘报表'>'报表’ 中找到您需要修改的报表。在这个教程中我们修改 报价单/订单,所以 我们搜索 'Order'
[attachimg=2]
Now that you’ve found your report click on it. This will open a new view where you will find all the technical information you need! For example with the quotation report:
点击您需要修改的报表。会打开一个新的视图,在这里您会发现您需要的技术参数!例如报价/订单报表中:
[attachimg=3]
At the right you will see a clickable link named ‘Search associated QWeb views’. Click on it. This will show you a list of all records that are associated to this specific report. In the example of the quotation report:
在右边您会看到 "查找QWeb相关视图",点击。它会展示给您此报表的所有相关记录。此例子中:
[attachimg=4]
So this usually shows you two XML records. How do you know which one you need? The one that ends with _document is the correct XML record that you need to inherit. Under the column ‘External ID’ you will see there is an unique name, in this example sale.report_saleorder_document. The first part of this text (sale) is the module where the report is from, the second part (report_saleorder_document) is the name of the report that you want to inherit and modify.
通常这类会显示2条XML记录。您如何知道哪个是您需要的呢?以_document结尾的那个是您需要继承的正确的那个。在 ‘外部ID’ 这类您会看到它(在数据库对于表中)的唯一名称。
[attachimg=5]
Remember this value and now open up your XML file. To inherit a QWeb report you need two things: an unique template id and the inherit_id. The template id can be chosen by yourself, just make sure its unique. The inherit_id should contain the value you’ve just found on your report (sale.report_saleorder_document).
记录下这个值,然后打开您新建模块中的XML文件。
要继承QWeb报价,您需要做2件事:
一个唯一的template id以及inherit_id. template id您可以自己定义,只需确保它是唯一的。
inherit_id需要包含刚才您在需要继承的报表中发现的那个外部id (sale.report_saleorder_document).<!--Inherit quotation report(frommodule sale)--><br /><template id="report_quotation_inherit_demo"inherit_id="sale.report_saleorder_document"><br /></template>
That is it! You’re now already on the correct report and are inheriting it. So, how do you now add or remove elements? To do this you will need Xpath expressions to find, modify, replace or add elements. Tip: Don’t know how Xpath expressions work? Follow my tutorial here!
For this example I will remove the columns that show the amount, the tax and the price per item. The first step is to modify the table header:
就是这样!您现在已经在正确的报表中并且继承它了。如何增加或者移除元素?您需要Xpath表达式来查找,修改,覆盖或者增加元素。提示:不知道Xpath表达式如何工作?点击这里获得教程 !
在我们这个例子中,我们 移除其他列,只显示 说明和 价格。第一步是修改表头:<!--Finds the first table withasclasstable table-condensed andgives the ability to modify it<br />This will replace everything withing tr(including tr)--><br /><xpath expr="//table[@class='table table-condensed']//thead//tr"position="replace"><br /> <tr style="background-color:lightgray;"><br /> <th>Description</th><br /> <th class="text-right">Price</th><br /> </tr><br /></xpath>
After modifying the table header the table content should also be modified.
附上原报表文件 表头部分代码 参考:<table class="table table-condensed"><br /> <thead><br /> <tr><br /> <th>Description</th><br /> <th>Taxes</th><br /> <th class="text-right">Quantity</th><br /> <th class="text-right">Unit Price</th><br /> <th groups="sale.group_discount_per_so_line">Disc.(%)</th><br /> <th class="text-right">Price</th><br /> </tr><br /> </thead>
然后修改表的内容:<xpath expr="//tbody[@class='sale_tbody']//tr//td[4]"position="replace"><br /></xpath><br /><xpath expr="//tbody[@class='sale_tbody']//tr//td[3]"position="replace"><br /></xpath><br /><xpath expr="//tbody[@class='sale_tbody']//tr//td[2]"position="replace"><br /></xpath>
This code will remove the fourth, third and second td element and all its content but only for the tbody with class ‘sale_tbody’ and inside the tr.
(这些代码会移除,class'sale_tbody' 第4,3,2 的td元素及其内容)
注:去掉的内容 分别是 单价,数量,和税,
附上原报表的内容部分的代码:<tbodyclass="sale_tbody"><br /><trt-foreach="o.order_line"t-as="l"><br /><td><br /><spant-field="l.name"/><br /></td><br /><td><br /><spant-esc="', '.join(map(lambda x: x.name, l.tax_id))"/><br /></td><br /><tdclass="text-right"><br /><spant-field="l.product_uom_qty"/><br /><spangroups="product.group_uom"t-field="l.product_uom"/><br /></td><br /><tdclass="text-right"><br /><spant-field="l.price_unit"/><br /></td><br /><tdgroups="sale.group_discount_per_so_line"><br /><spant-field="l.discount"/><br /></td><br /><tdclass="text-right"><br /><spant-field="l.price_subtotal"t-field-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: &quot;o.pricelist_id.currency_id&quot;}"/><br /></td><br /></tr><br /></tbody>
So this will replace the header and the table content from this report. Have a look at the full code to inherit and modify your QWeb report 完整的代码如下它会覆盖此报表的表头和表的内容:<openerp><br /> <data><br /> <!--Inherit quotation report(frommodule sale)--><br /> <template id="report_quotation_inherit_demo"inherit_id="sale.report_saleorder_document"><br /> <!--Finds the first table withasclasstable table-condensed andgives the ability to modify it<br />This will replace everything withing tr(including tr)--><br /> <xpath expr="//table[@class='table table-condensed']//thead//tr"position="replace"><br /> <tr style="background-color:lightgray;"><br /> <th>Description</th><br /> <th class="text-right">Price</th><br /> </tr><br /> </xpath><br /> <xpath expr="//tbody[@class='sale_tbody']//tr//td[4]"position="replace"><br /> </xpath><br /> <xpath expr="//tbody[@class='sale_tbody']//tr//td[3]"position="replace"><br /> </xpath><br /> <xpath expr="//tbody[@class='sale_tbody']//tr//td[2]"position="replace"><br /> </xpath><br /> </template><br /> </data><br /></openerp>
3. Adding the dependency for the external QWeb report增加依赖
The next, and final step, is to add a dependency. Because this QWeb report is inside another module Odoo has to know about this module and its content so you should add a dependency. Without this your module will not work and you will get errors.
Open up your openerp.py file in your custom module and find the line with depends.
Now take back that ‘External ID’ from the QWeb report and take the first part of the external id (before the dot). This tells you which module you should add as a dependency:
最后一步,增加依赖。因为这个QWeb报表位于其他模块中Odoo需要知道此模块。不然您的模块不会工作并且会报错。
打开 您自定义的模块中的 openerp.py文件,找到depends 这行。
返回QWeb 报表 查看外部id的部分 , 外部id (.之前的)的部分,就是 模块名称,
[attachimg=5]
In this example my QWeb comes from the sale module, so I will add it as a dependency.
在这个例子中,我的QWeb 来自 sale模块,我们把他添加到 openerp.py 的 depends 这行:# any module necessary for this one to work correctly<br />'depends':['sale'],
4. Conclusion结尾
Thats it! You’re done with inheriting and modifying the QWeb report. When you now install this module in your Odoo you will see the modified report.
Do you want to try a demo module and see the source code of this tutorial? You can view on my Github account.
Has this tutorial helped you, do you have any feedback or questions? Post away!
就是这样!您完成了继承和修改QWeb报表。当您安装此模块,您会发现报表已经改变了。
[attachimg=6]
点击后面下载此教程的源码:您可以通过作者的Github账户访问. https://github.com/Yenthe666/Odoo_Samples/tree/master/inherit_report_demo
谢谢大家