﻿{"id":2974,"date":"2016-04-13T17:47:14","date_gmt":"2016-04-13T09:47:14","guid":{"rendered":"http:\/\/www.jointd.com\/?p=2974"},"modified":"2016-04-13T22:16:57","modified_gmt":"2016-04-13T14:16:57","slug":"%e5%8d%93%e5%bf%86%e7%bf%bb%e8%af%91%ef%bc%9a%e5%86%99%e6%a8%a1%e5%9d%97%e8%bf%9b%e8%a1%8codoo-qweb%e6%8a%a5%e8%a1%a8%e7%9a%84%e7%bb%a7%e6%89%bf%e5%92%8c%e4%bf%ae%e6%94%b9","status":"publish","type":"post","link":"https:\/\/www.jointd.com\/?p=2974","title":{"rendered":"\u5353\u5fc6\u7ffb\u8bd1\uff1a\u5bf9Odoo Qweb\u62a5\u8868\u8fdb\u884c\u7ee7\u627f\u548c\u4fee\u6539\u7684\u6a21\u5757"},"content":{"rendered":"<h2>\u5353\u5fc6\u7ffb\u8bd1\uff1a\u5bf9Odoo Qweb\u62a5\u8868\u8fdb\u884c\u7ee7\u627f\u548c\u4fee\u6539\u7684\u6a21\u5757<\/h2>\n<h2>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"http:\/\/www.odoo.yenthevg.com\/inheriting-and-modifying-qweb-reports\/\">Inheriting and modifying QWeb reports<\/a><\/h2>\n<p>Hi guys,<\/p>\n<p>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!<br \/>\nIn this example I will modify the default Quotation \/ order report through inheritance and I will remove a few elements from the report.<\/p>\n<p>\u5927\u5bb6\u597d\uff0c<\/p>\n<p>\u5728\u8fd9\u4e2a\u6559\u7a0b\u4e2d\u60a8\u4f1a\u5b66\u4e60\u5230\u5982\u4f55\u5199\u4e00\u4e2a\u6a21\u5757\u6765\u7ee7\u627f\u4e00\u4e2a\u73b0\u6709\u7684QWeb\u62a5\u8868\u3002\u5728\u8fd9\u4e2a\u6559\u7a0b\u4e4b\u540e\uff0c\u60a8\u80fd\u7ee7\u627f\u548c\u4fee\u6539\u4efb\u4f55\u73b0\u6709\u7684Odoo\u4e2d\u7684QWeb\u62a5\u8868\u3002<\/p>\n<h3>1. Creating a new module\u521b\u5efa\u4e00\u4e2a\u65b0\u6a21\u578b<\/h3>\n<p>The first step is to create a new module. The correct behaviour in Odoo is to always inherit, don\u2019t ever modify existing files. Start by creating yourself a new module.<br \/>\n<b>Tip:<\/b>\u00a0use the scaffold command from Odoo!<\/p>\n<p>\u7b2c\u4e00\u6b65\u521b\u5efa\u4e00\u4e2a\u65b0\u6a21\u578b\u3002\u5728Odoo\u6b63\u786e\u7684\u505a\u6cd5\u662f\u4f7f\u7528\u7ee7\u627f\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4fee\u6539\u73b0\u6709\u6587\u4ef6\u3002\u4ece\u521b\u5efa\u4e00\u4e2a\u65b0\u6a21\u5757\u5f00\u59cb\u3002<\/p>\n<p><b><span style=\"color: #7c705e; font-family: 'Open Sans', Helvetica, Arial, sans-serif; font-size: medium;\">\u63d0\u793a\uff1a\u53ef\u4ee5\u4f7f\u7528\u5728Odoo\u4e2d\u4f7f\u7528scaffold\u547d\u4ee4\u6765\u521b\u5efa\u65b0\u6a21\u5757\u5982\u4e0b\uff1a<\/span><\/b><\/p>\n<p><a href=\"http:\/\/www.jointd.com\/?attachment_id=2977\" rel=\"attachment wp-att-2977\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2977\" src=\"http:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/1.png\" alt=\"1\" width=\"743\" height=\"73\" srcset=\"https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/1.png 743w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/1-150x15.png 150w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/1-300x29.png 300w\" sizes=\"auto, (max-width: 743px) 100vw, 743px\" \/><\/a><br \/>\n<img decoding=\"async\" src=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/428e416b5eb54e7985a59a167639f852\/uz653ch.png\" alt=\"Odoo scaffold command\" data-media-type=\"image\" data-attr-org-src-id=\"72C518F1641049678274058EFD1FB15D\" data-attr-org-img-file=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/428e416b5eb54e7985a59a167639f852\/uz653ch.png\" \/><br \/>\nThis will create a new module from scratch and the default structure of your module is already there.<\/p>\n<p>\u8fd9\u4f1a\u4ece\u8349\u7a3f\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u9ed8\u8ba4\u7ed3\u6784\u7684\u65b0\u6a21\u5757\u3002<\/p>\n<h3>2. Creating your XML file\u521b\u5efaXML\u6587\u4ef6<\/h3>\n<p>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?<br \/>\nThe easiest way is to go to \u2018Settings\u2019 &gt; \u2018Reports\u2019 &gt; \u2018Reports\u2019 and to search the report you want to modify. In this tutorial this will be the quotation\/order report so I\u2019ll search for \u2018Order\u2019:<\/p>\n<p>\u63a5\u4e0b\u6765\u6253\u5f00\u60a8\u7684XML\u6587\u4ef6\uff0c\u521b\u5efa\u65b0\u7684\u7eaa\u5f55\u6765\u7ee7\u627f\u62a5\u8868\u3002\u60a8\u9700\u8981\u77e5\u9053\u9700\u8981\u7ee7\u627f\u7684\u62a5\u8868\u7684\u6a21\u5757\u7684\u540d\u79f0\u4ee5\u53caXML id.<\/p>\n<p>\u5982\u4f55\u627e\u5230\u4ed6\u4eec\u5462\uff1f<\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5230\u2018\u8bbe\u7f6e\u2019&gt;\u2018\u62a5\u8868&#8217;&gt;&#8217;\u62a5\u8868\u2019 \u4e2d\u627e\u5230\u60a8\u9700\u8981\u4fee\u6539\u7684\u62a5\u8868\u3002\u5728\u8fd9\u4e2a\u6559\u7a0b\u4e2d\u6211\u4eec\u4fee\u6539 \u62a5\u4ef7\u5355\/\u8ba2\u5355\uff0c\u6240\u4ee5 \u6211\u4eec\u641c\u7d22 &#8216;Order&#8217;<br \/>\n<img decoding=\"async\" src=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/64cbfedaba924e928281577f48ae9ef5\/clipboard.png\" alt=\"\" data-media-type=\"image\" data-inited=\"true\" \/><a href=\"http:\/\/www.jointd.com\/?attachment_id=2978\" rel=\"attachment wp-att-2978\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-2978\" src=\"http:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/2-1024x514.png\" alt=\"2\" width=\"1024\" height=\"514\" srcset=\"https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/2-1024x514.png 1024w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/2-150x75.png 150w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/2-300x151.png 300w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/2-768x385.png 768w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/2.png 1437w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>Now that you\u2019ve 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:<\/p>\n<p>\u70b9\u51fb\u60a8\u9700\u8981\u4fee\u6539\u7684\u62a5\u8868\u3002\u4f1a\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u89c6\u56fe\uff0c\u5728\u8fd9\u91cc\u60a8\u4f1a\u53d1\u73b0\u60a8\u9700\u8981\u7684\u6280\u672f\u53c2\u6570\uff01\u4f8b\u5982\u62a5\u4ef7\/\u8ba2\u5355\u62a5\u8868\u4e2d\uff1a<br \/>\n<img decoding=\"async\" src=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/f1f92cac7f314c1d8f702d5b55c7ab54\/clipboard.png\" alt=\"\" data-media-type=\"image\" data-inited=\"true\" \/><a href=\"http:\/\/www.jointd.com\/?attachment_id=2979\" rel=\"attachment wp-att-2979\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-2979\" src=\"http:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/3-1024x476.png\" alt=\"3\" width=\"1024\" height=\"476\" srcset=\"https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/3-1024x476.png 1024w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/3-150x70.png 150w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/3-300x139.png 300w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/3-768x357.png 768w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/3.png 1037w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>At the right you will see a clickable link named \u2018Search associated QWeb views\u2019. 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:<\/p>\n<p>\u5728\u53f3\u8fb9\u60a8\u4f1a\u770b\u5230 &#8220;\u67e5\u627eQWeb\u76f8\u5173\u89c6\u56fe&#8221;,\u70b9\u51fb\u3002\u5b83\u4f1a\u5c55\u793a\u7ed9\u60a8\u6b64\u62a5\u8868\u7684\u6240\u6709\u76f8\u5173\u8bb0\u5f55\u3002\u6b64\u4f8b\u5b50\u4e2d\uff1a<\/p>\n<p><a href=\"http:\/\/www.jointd.com\/?attachment_id=2980\" rel=\"attachment wp-att-2980\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-2980\" src=\"http:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-1024x191.png\" alt=\"4\" width=\"1024\" height=\"191\" srcset=\"https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-1024x191.png 1024w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-150x28.png 150w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-300x56.png 300w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-768x143.png 768w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4.png 1250w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><br \/>\n<img decoding=\"async\" src=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/52caa75466dc44b1808f5cad0bc89ed9\/clipboard.png\" alt=\"\" data-media-type=\"image\" data-inited=\"true\" \/><br \/>\nSo 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 \u2018External ID\u2019 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.<\/p>\n<p>\u901a\u5e38\u8fd9\u7c7b\u4f1a\u663e\u793a2\u6761XML\u8bb0\u5f55\u3002\u60a8\u5982\u4f55\u77e5\u9053\u54ea\u4e2a\u662f\u60a8\u9700\u8981\u7684\u5462\uff1f\u4ee5_document\u7ed3\u5c3e\u7684\u90a3\u4e2a\u662f\u60a8\u9700\u8981\u7ee7\u627f\u7684\u6b63\u786e\u7684\u90a3\u4e2a\u3002\u5728\u00a0\u2018\u5916\u90e8ID\u2019 \u8fd9\u7c7b\u60a8\u4f1a\u770b\u5230\u5b83\uff08\u5728\u6570\u636e\u5e93\u5bf9\u4e8e\u8868\u4e2d\uff09\u7684\u552f\u4e00\u540d\u79f0\u3002<\/p>\n<p><img decoding=\"async\" src=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/346ace2e3d7448bd9f9bae53b45efab7\/clipboard.png\" alt=\"\" data-media-type=\"image\" data-inited=\"true\" \/><a href=\"http:\/\/www.jointd.com\/?attachment_id=2981\" rel=\"attachment wp-att-2981\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2981\" src=\"http:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/5.png\" alt=\"5\" width=\"905\" height=\"349\" srcset=\"https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/5.png 905w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/5-150x58.png 150w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/5-300x116.png 300w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/5-768x296.png 768w\" sizes=\"auto, (max-width: 905px) 100vw, 905px\" \/><\/a><\/p>\n<p>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\u2019ve just found on your report (sale.report_saleorder_document).<\/p>\n<p>\u8bb0\u5f55\u4e0b\u8fd9\u4e2a\u503c\uff0c\u7136\u540e\u6253\u5f00\u60a8\u65b0\u5efa\u6a21\u5757\u4e2d\u7684XML\u6587\u4ef6\u3002<\/p>\n<p>\u8981\u7ee7\u627fQWeb\u62a5\u4ef7\uff0c\u60a8\u9700\u8981\u505a2\u4ef6\u4e8b\uff1a<\/p>\n<p>\u4e00\u4e2a\u552f\u4e00\u7684template id\u4ee5\u53cainherit_id. template id\u60a8\u53ef\u4ee5\u81ea\u5df1\u5b9a\u4e49\uff0c\u53ea\u9700\u786e\u4fdd\u5b83\u662f\u552f\u4e00\u7684\u3002<\/p>\n<p>inherit_id\u9700\u8981\u5305\u542b\u521a\u624d\u60a8\u5728\u9700\u8981\u7ee7\u627f\u7684\u62a5\u8868\u4e2d\u53d1\u73b0\u7684\u90a3\u4e2a\u5916\u90e8id\u00a0(sale.report_saleorder_document).<\/p>\n<p>[xml]&lt;!&#8211;Inherit quotation report(frommodule sale)&#8211;&gt;<br \/>\n&lt;template id=&quot;report_quotation_inherit_demo&quot;inherit_id=&quot;sale.report_saleorder_document&quot;&gt;<br \/>\n&lt;\/template&gt;[\/xml]<\/p>\n<p>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:<\/p>\n<p>\u5c31\u662f\u8fd9\u6837\uff01\u60a8\u73b0\u5728\u5df2\u7ecf\u5728\u6b63\u786e\u7684\u62a5\u8868\u4e2d\u5e76\u4e14\u7ee7\u627f\u5b83\u4e86\u3002\u5982\u4f55\u589e\u52a0\u6216\u8005\u79fb\u9664\u5143\u7d20\uff1f\u60a8\u9700\u8981Xpath\u8868\u8fbe\u5f0f\u6765\u67e5\u627e\uff0c\u4fee\u6539\uff0c\u8986\u76d6\u6216\u8005\u589e\u52a0\u5143\u7d20\u3002\u63d0\u793a\uff1a\u4e0d\u77e5\u9053Xpath\u8868\u8fbe\u5f0f\u5982\u4f55\u5de5\u4f5c\uff1f<a href=\"http:\/\/www.odoo.yenthevg.com\/xpath-expressions-in-odoo-8\/\">\u70b9\u51fb\u8fd9\u91cc\u83b7\u5f97\u6559\u7a0b\u00a0<\/a>!<\/p>\n<p>\u5728\u6211\u4eec\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec \u79fb\u9664\u5176\u4ed6\u5217\uff0c\u53ea\u663e\u793a \u8bf4\u660e\u548c \u4ef7\u683c\u3002\u7b2c\u4e00\u6b65\u662f\u4fee\u6539\u8868\u5934\uff1a<\/p>\n<div data-settings=\"minimize scroll-mouseover\">\n<p>[xml]&lt;!&#8211;Finds the first table withasclasstable table-condensed andgives the ability to modify it<br \/>\nThis will replace everything withing tr(including tr)&#8211;&gt;<br \/>\n&lt;xpath expr=&quot;\/\/table[@class=&#8217;table table-condensed&#8217;]\/\/thead\/\/tr&quot;position=&quot;replace&quot;&gt;<br \/>\n  &lt;tr style=&quot;background-color:lightgray;&quot;&gt;<br \/>\n   &lt;th&gt;Description&lt;\/th&gt;<br \/>\n   &lt;th class=&quot;text-right&quot;&gt;Price&lt;\/th&gt;<br \/>\n  &lt;\/tr&gt;<br \/>\n&lt;\/xpath&gt;[\/xml]<\/p>\n<\/div>\n<p>After modifying the table header the table content should also be modified.<\/p>\n<p>\u9644\u4e0a\u539f\u62a5\u8868\u7684\u8868\u5934\u90e8\u5206\u4ee3\u7801 \u53c2\u8003\uff1a<\/p>\n<blockquote>\n<p>[xml]&lt;table class=&quot;table table-condensed&quot;&gt;<br \/>\n &lt;thead&gt;<br \/>\n &lt;tr&gt;<br \/>\n   &lt;th&gt;Description&lt;\/th&gt;<br \/>\n   &lt;th&gt;Taxes&lt;\/th&gt;<br \/>\n   &lt;th class=&quot;text-right&quot;&gt;Quantity&lt;\/th&gt;<br \/>\n   &lt;th class=&quot;text-right&quot;&gt;Unit Price&lt;\/th&gt;<br \/>\n   &lt;th groups=&quot;sale.group_discount_per_so_line&quot;&gt;Disc.(%)&lt;\/th&gt;<br \/>\n   &lt;th class=&quot;text-right&quot;&gt;Price&lt;\/th&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n &lt;\/thead&gt;[\/xml]<\/p>\n<\/blockquote>\n<p>\u7136\u540e\u4fee\u6539\u8868\u7684\u5185\u5bb9\uff1a<\/p>\n<p>[xml]&lt;xpath expr=&quot;\/\/tbody[@class=&#8217;sale_tbody&#8217;]\/\/tr\/\/td[4]&quot;position=&quot;replace&quot;&gt;<br \/>\n&lt;\/xpath&gt;<br \/>\n&lt;xpath expr=&quot;\/\/tbody[@class=&#8217;sale_tbody&#8217;]\/\/tr\/\/td[3]&quot;position=&quot;replace&quot;&gt;<br \/>\n&lt;\/xpath&gt;<br \/>\n&lt;xpath expr=&quot;\/\/tbody[@class=&#8217;sale_tbody&#8217;]\/\/tr\/\/td[2]&quot;position=&quot;replace&quot;&gt;<br \/>\n&lt;\/xpath&gt;[\/xml]<\/p>\n<div data-settings=\"minimize scroll-mouseover\"><\/div>\n<p>This code will remove the fourth, third and second td element and all its content but only for the tbody with class \u2018sale_tbody\u2019 and inside the tr.<\/p>\n<p>\uff08\u8fd9\u4e9b\u4ee3\u7801\u4f1a\u79fb\u9664\uff0cclass&#8217;sale_tbody&#8217; \u7b2c4\uff0c3\uff0c2 \u7684td\u5143\u7d20\u53ca\u5176\u5185\u5bb9)<\/p>\n<p>\u6ce8\uff1a\u53bb\u6389\u7684\u5185\u5bb9 \u5206\u522b\u662f \u5355\u4ef7\uff0c\u6570\u91cf\uff0c\u548c\u7a0e\uff0c<\/p>\n<p>\u9644\u4e0a\u539f\u62a5\u8868\u7684\u5185\u5bb9\u90e8\u5206\u7684\u4ee3\u7801\u4f9b\u53c2\u8003\uff1a<\/p>\n<blockquote>\n<p>[xml]&lt;tbody class=&quot;sale_tbody&quot;&gt;<br \/>\n &lt;tr t-foreach=&quot;o.order_line&quot; t-as=&quot;l&quot;&gt;<br \/>\n  &lt;td&gt;<br \/>\n  &lt;span t-field=&quot;l.name&quot;\/&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n  &lt;td&gt;<br \/>\n  &lt;span t-esc=&quot;&#8217;, &#8216;.join(map(lambda x: x.name, l.tax_id))&quot;\/&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n  &lt;td class=&quot;text-right&quot;&gt;<br \/>\n  &lt;span t-field=&quot;l.product_uom_qty&quot;\/&gt;<br \/>\n  &lt;span groups=&quot;product.group_uom&quot; t-field=&quot;l.product_uom&quot;\/&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n  &lt;td class=&quot;text-right&quot;&gt;<br \/>\n  &lt;span t-field=&quot;l.price_unit&quot;\/&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n  &lt;td groups=&quot;sale.group_discount_per_so_line&quot;&gt;<br \/>\n  &lt;span t-field=&quot;l.discount&quot;\/&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n  &lt;td class=&quot;text-right&quot;&gt;<br \/>\n  &lt;span t-field=&quot;l.price_subtotal&quot; t-field-options=&quot;{&amp;quot;widget&amp;quot;: &amp;quot;monetary&amp;quot;, &amp;quot;display_currency&amp;quot;: &amp;quot;o.pricelist_id.currency_id&amp;quot;}&quot;\/&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n&lt;\/tbody&gt;[\/xml]<\/p>\n<\/blockquote>\n<p>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 \u00a0\u5b8c\u6574\u7684\u4ee3\u7801\u5982\u4e0b\u5b83\u4f1a\u8986\u76d6\u6b64\u62a5\u8868\u7684\u8868\u5934\u548c\u8868\u7684\u5185\u5bb9:<\/p>\n<p>[xml] &lt;data&gt;<br \/>\n &lt;!&#8211;Inherit quotation report(frommodule sale)&#8211;&gt;<br \/>\n &lt;template id=&quot;report_quotation_inherit_demo&quot;inherit_id=&quot;sale.report_saleorder_document&quot;&gt;<br \/>\n &lt;!&#8211;Finds the first table withasclasstable table-condensed andgives the ability to modify it<br \/>\nThis will replace everything withing tr(including tr)&#8211;&gt;<br \/>\n &lt;xpath expr=&quot;\/\/table[@class=&#8217;table table-condensed&#8217;]\/\/thead\/\/tr&quot;position=&quot;replace&quot;&gt;<br \/>\n &lt;tr style=&quot;background-color:lightgray;&quot;&gt;<br \/>\n  &lt;th&gt;Description&lt;\/th&gt;<br \/>\n  &lt;th class=&quot;text-right&quot;&gt;Price&lt;\/th&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n &lt;\/xpath&gt;<br \/>\n &lt;xpath expr=&quot;\/\/tbody[@class=&#8217;sale_tbody&#8217;]\/\/tr\/\/td[4]&quot;position=&quot;replace&quot;&gt;<br \/>\n &lt;\/xpath&gt;<br \/>\n &lt;xpath expr=&quot;\/\/tbody[@class=&#8217;sale_tbody&#8217;]\/\/tr\/\/td[3]&quot;position=&quot;replace&quot;&gt;<br \/>\n &lt;\/xpath&gt;<br \/>\n &lt;xpath expr=&quot;\/\/tbody[@class=&#8217;sale_tbody&#8217;]\/\/tr\/\/td[2]&quot;position=&quot;replace&quot;&gt;<br \/>\n &lt;\/xpath&gt;<br \/>\n &lt;\/template&gt;<br \/>\n &lt;\/data&gt;<br \/>\n&lt;\/openerp&gt;[\/xml]<\/p>\n<div data-settings=\"minimize scroll-mouseover\"><\/div>\n<h3>3. Adding the dependency for the external QWeb report\u589e\u52a0\u4f9d\u8d56<\/h3>\n<p>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.<br \/>\nOpen up your __openerp__.py file in your custom module and find the line with depends.<br \/>\nNow take back that \u2018External ID\u2019 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:<\/p>\n<p>\u6700\u540e\u4e00\u6b65\uff0c\u589e\u52a0\u4f9d\u8d56\u3002\u56e0\u4e3a\u8fd9\u4e2aQWeb\u62a5\u8868\u4f4d\u4e8e\u5176\u4ed6\u6a21\u5757\u4e2dOdoo\u9700\u8981\u77e5\u9053\u6b64\u6a21\u5757\u3002\u4e0d\u7136\u60a8\u7684\u6a21\u5757\u4e0d\u4f1a\u5de5\u4f5c\u5e76\u4e14\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u6253\u5f00 \u60a8\u81ea\u5b9a\u4e49\u7684\u6a21\u5757\u4e2d\u7684\u00a0\u00a0__openerp__.py\u6587\u4ef6\uff0c\u627e\u5230depends \u8fd9\u884c\u3002<\/p>\n<p>\u8fd4\u56deQWeb \u62a5\u8868 \u67e5\u770b\u5916\u90e8id\u7684\u90e8\u5206\u00a0, \u5916\u90e8id (.\u4e4b\u524d\u7684\uff09\u7684\u90e8\u5206\uff0c\u5c31\u662f \u6a21\u5757\u540d\u79f0\uff0c<\/p>\n<p><img decoding=\"async\" src=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/fe520034342b4c1cae3831655ed3bc85\/clipboard.png\" alt=\"\" data-media-type=\"image\" data-inited=\"true\" data-attr-org-src-id=\"6AC5182957EC4B628465BB22FD01A9D2\" data-attr-org-img-file=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/fe520034342b4c1cae3831655ed3bc85\/clipboard.png\" \/><a href=\"http:\/\/www.jointd.com\/?attachment_id=2980\" rel=\"attachment wp-att-2980\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-2980\" src=\"http:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-1024x191.png\" alt=\"4\" width=\"1024\" height=\"191\" srcset=\"https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-1024x191.png 1024w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-150x28.png 150w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-300x56.png 300w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4-768x143.png 768w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/4.png 1250w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>In this example my QWeb comes from the sale module, so I will add it as a dependency.<\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u7684QWeb \u6765\u81ea sale\u6a21\u5757\uff0c\u6211\u4eec\u628a\u4ed6\u6dfb\u52a0\u5230 \u00a0__openerp__.py \u7684\u00a0depends \u8fd9\u884c\uff1a<\/p>\n<div data-settings=\"minimize scroll-mouseover\">\n<p>[py]# any module necessary for this one to work correctly<br \/>\n&lt;div&gt;&#8217;depends&#8217;:[&#8216;sale&#8217;],[\/py]<\/p>\n<\/div>\n<h3>4. Conclusion\u7ed3\u5c3e<\/h3>\n<p>Thats it! You\u2019re done with inheriting and modifying the QWeb report. When you now install this module in your Odoo you will see the modified report.<br \/>\nDo you want to try a demo module and see the source code of this tutorial?\u00a0<a href=\"https:\/\/github.com\/Yenthe666\/Odoo_Samples\/tree\/master\/inherit_report_demo\" target=\"_Blank\">You can view on my Github account<\/a>.<br \/>\nHas this tutorial helped you, do you have any feedback or questions? Post away!<\/p>\n<p>\u5c31\u662f\u8fd9\u6837\uff01\u60a8\u5b8c\u6210\u4e86\u7ee7\u627f\u548c\u4fee\u6539QWeb\u62a5\u8868\u3002\u5f53\u60a8\u5b89\u88c5\u6b64\u6a21\u5757\uff0c\u60a8\u4f1a\u53d1\u73b0\u62a5\u8868\u5df2\u7ecf\u6539\u53d8\u4e86\u3002<\/p>\n<p><a href=\"http:\/\/www.jointd.com\/?attachment_id=2982\" rel=\"attachment wp-att-2982\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2982\" src=\"http:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/6.png\" alt=\"6\" width=\"752\" height=\"553\" srcset=\"https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/6.png 752w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/6-150x110.png 150w, https:\/\/www.jointd.com\/wp-content\/uploads\/2016\/04\/6-300x221.png 300w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/a><\/p>\n<p><img decoding=\"async\" src=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/4dda5972b67a419a83f1dd232a334c8a\/clipboard.png\" alt=\"\" data-media-type=\"image\" data-inited=\"true\" data-attr-org-src-id=\"ADAF32562BC946D9981815CC8E243B82\" data-attr-org-img-file=\"file:\/\/\/C:\/Users\/Steve\/AppData\/Local\/YNote\/data\/join330@126.com\/4dda5972b67a419a83f1dd232a334c8a\/clipboard.png\" \/><\/p>\n<p>\u70b9\u51fb\u540e\u9762\u4e0b\u8f7d\u6b64\u6559\u7a0b\u7684\u6e90\u7801\uff1a<a href=\"https:\/\/github.com\/Yenthe666\/Odoo_Samples\/tree\/master\/inherit_report_demo\" target=\"_Blank\">\u60a8\u53ef\u4ee5\u901a\u8fc7\u539f\u6587\u4f5c\u8005\u7684Github\u8d26\u6237\u8bbf\u95ee<\/a>.<\/p>\n<p>\u4ee5\u4e0a\u5185\u5bb9\u5353\u5fc6\u7ffb\u8bd1\u3002<\/p>\n<p>\u5176\u4ed6QWeb\u62a5\u8868\u76f8\u5173\uff1a<\/p>\n<ol>\n<li>\n<h3><a title=\"\u8be6\u7ec6\u9605\u8bfb \u591a\u56fe\u7ffb\u8bd1\u52a0\u6574\u7406\u6d4b\u8bd5\uff1a\u82f1\u4e2d\u5bf9\u7167\uff1aOdoo\u62a5\u8868\u5165\u95e8Step by Step,Odoo\u521b\u5efa\u4e00\u4efd\u62a5\u8868\u5230\u6253\u5370\u4e0b\u62c9\u83dc\u5355\u4e2d\" href=\"http:\/\/www.jointd.com\/?p=2579\" rel=\"bookmark\">\u591a\u56fe\u7ffb\u8bd1\u52a0\u6574\u7406\u6d4b\u8bd5\uff1a\u82f1\u4e2d\u5bf9\u7167\uff1aOdoo\u62a5\u8868\u5165\u95e8Step by Step,Odoo\u521b\u5efa\u4e00\u4efd\u62a5\u8868\u5230\u6253\u5370\u4e0b\u62c9\u83dc\u5355\u4e2d<\/a><\/h3>\n<\/li>\n<li>\n<h3><a title=\"\u8be6\u7ec6\u9605\u8bfb \u5353\u5fc6\u7ffb\u8bd1\uff1a\u82f1\u4e2d\u5bf9\u7167\uff1aOdoo\u62a5\u8868\u57fa\u7840\" href=\"http:\/\/www.jointd.com\/?p=2598\" rel=\"bookmark\">\u5353\u5fc6\u7ffb\u8bd1\uff1a\u82f1\u4e2d\u5bf9\u7167\uff1aOdoo\u62a5\u8868\u57fa\u7840<\/a><\/h3>\n<\/li>\n<li>\n<h3><a title=\"\u8be6\u7ec6\u9605\u8bfb \u5353\u5fc6\u7ffb\u8bd1\uff1a\u82f1\u4e2d\u5bf9\u7167\uff1aOdoo\u62a5\u8868\u8bbe\u8ba1\u8fdb\u9636\u7bc7\" href=\"http:\/\/www.jointd.com\/?p=2603\" rel=\"bookmark\">\u5353\u5fc6\u7ffb\u8bd1\uff1a\u82f1\u4e2d\u5bf9\u7167\uff1aOdoo\u62a5\u8868\u8bbe\u8ba1\u8fdb\u9636\u7bc7<\/a><\/h3>\n<\/li>\n<li>\n<h3><a href=\"http:\/\/www.jointd.com\/?p=2974\" rel=\"bookmark\">\u5353\u5fc6\u7ffb\u8bd1\uff1a\u5199\u6a21\u5757\u8fdb\u884cOdoo Qweb\u62a5\u8868\u7684\u7ee7\u627f\u548c\u4fee\u6539<\/a><\/h3>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u5353\u5fc6\u7ffb\u8bd1\uff1a\u5bf9Odoo Qweb\u62a5\u8868\u8fdb\u884c\u7ee7\u627f\u548c\u4fee\u6539\u7684\u6a21\u5757 \u539f\u6587\u94fe\u63a5\uff1aInheriting and modifyi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[139],"tags":[169,278,344,343,277,342,341,279],"class_list":["post-2974","post","type-post","status-publish","format-standard","hentry","category-odoo-openerp","tag-odoo","tag-odoo-qweb","tag-qweb"],"views":5348,"_links":{"self":[{"href":"https:\/\/www.jointd.com\/index.php?rest_route=\/wp\/v2\/posts\/2974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jointd.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jointd.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jointd.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jointd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2974"}],"version-history":[{"count":24,"href":"https:\/\/www.jointd.com\/index.php?rest_route=\/wp\/v2\/posts\/2974\/revisions"}],"predecessor-version":[{"id":3001,"href":"https:\/\/www.jointd.com\/index.php?rest_route=\/wp\/v2\/posts\/2974\/revisions\/3001"}],"wp:attachment":[{"href":"https:\/\/www.jointd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jointd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jointd.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}