【问题标题】:odoo - add tablerow in sales order total costsodoo - 在销售订单总成本中添加表格行
【发布时间】:2015-07-29 14:58:54
【问题描述】:

我正在尝试在销售订单中的总未税成本总税费之间添加一个额外的行。在查看report_saleorder.xml 时,应在以下代码中添加我的行:

<div class="row">
                <div class="col-xs-4 pull-right">
                    <table class="table table-condensed">
                        <tr class="border-black">
                            <td><strong>Total Without Taxes</strong></td>
                            <td class="text-right">
                                <span t-field="o.amount_untaxed"
                                    t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                            </td>
                        </tr>
                        <tr>
                            <td>Taxes</td>
                            <td class="text-right">
                                <span t-field="o.amount_tax"
                                    t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                            </td>
                        </tr>
                        <tr class="border-black">
                            <td><strong>Total</strong></td>
                            <td class="text-right">
                                <span t-field="o.amount_total"
                                    t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

由于编辑核心 xml 不是一个选项,我想知道是否可以使用 &lt;xpath&gt; 执行此操作,但我不确定如何执行此操作。我已经在我的 sale.py 文件中创建了一个 field 并查看他们的代码,我的 xml 应该类似于

<tr>
     <td>Insurance</td>
     <td class="text-right">
         <span t-field="o.amount_insurance" t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
     </td>
</tr>

任何关于我如何能够做到这一点的帮助将不胜感激

【问题讨论】:

    标签: xml odoo odoo-8


    【解决方案1】:

    是的,你是绝对正确的并使用 xpath 标签将必填字段添加为所需字段:

    如果您在界面本身中进行操作,请使用以下语法创建一个新的视图记录并从report_saleorder_document 继承它。

    <?xml version="1.0"?>
    
    <data inherit_id="sale.report_saleorder_document">
        <xpath expr="//div[@class='col-xs-4 pull-right']/table/tr[2]" position="after">
        <tr>
             <td>Insurance</td>
                 <td class="text-right">
                 <span t-field="o.amount_insurance" t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
             </td>
        </tr>
        </xpath>
    </data>
    

    如果您通过代码执行,则添加继承的视图定义。它应该看起来像这样:

    对于通过代码进行的更改,请创建新文件并添加以下代码:

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
    <data>
      <template id="report_saleorder_insurance_inherit" inherit_id="sale.report_saleorder_document">
            <xpath expr="//div[@class='col-xs-4 pull-right']/table/tr[2]" position="after">
            <tr>
                 <td>Insurance</td>
                     <td class="text-right">
                     <span t-field="o.amount_insurance" t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
                 </td>
            </tr>
            </xpath>
     </template>
    </data>
    </openerp>
    

    别忘了在清单下注册我们的文件

    最佳

    【讨论】:

    • 你展示的图片正是我需要的!但我真的不明白我应该把你的代码放在哪里。只需为其创建一个新的 xml 文件或将其放入现有文件中?我都试过了,但它给了我AssertionError: Did not expect element xpath there
    • @ThomasS :使用您想要执行的代码文件的更多详细信息更新了答案。添加新文件后更新模块列表和模块。或从终端使用 -u -d 选项。
    • 我把你给我的代码放在一个单独的 xml 文件中,并将这个文件添加到__openerp__.py,但我看不到任何新的变化。我重新启动了服务并且模块更新没有问题。有什么我错过的或任何想法为什么看起来好像没有使用 xml?非常感谢到目前为止的帮助!
    • 不确定你在做什么,但代码可靠,如果你使用销售订单布局模块,这里更具体的 xpath
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    • 2018-07-23
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多