【问题标题】:How to extend a template attribute using t-jquery and t-operation (Odoo 14)如何使用 t-jquery 和 t-operation 扩展模板属性(Odoo 14)
【发布时间】:2020-12-18 18:28:31
【问题描述】:

我想更改 POS 模块中“折扣”按钮的名称。所以我用这段代码扩展了模板,但不起作用。

<t t-extend="DiscountButton">
         <t t-jquery="span[class='control-button js_discount']" t-operation="replace">
              <span class="control-button js_discount">
            <i class="fa fa-tag"></i>
                <span> </span>
                <span>Discount(%)</span>
            </span>
         </t>
    </t>

有什么帮助吗?

【问题讨论】:

    标签: javascript python odoo


    【解决方案1】:

    您可以使用Extension inheritance(就地转换):

    <t t-inherit="pos_discount.DiscountButton" t-inherit-mode="extension">
        <xpath expr="//span[hasclass('js_discount')]/span[2]" position="replace">
            <span>Discount(%)</span>
        </xpath>
    </t>
    

    extension 指令用于更改父模板。

    编辑:

    您可以更改DiscountButton的模板

    odoo.define('my_module_name.NewDiscount', function(require) {
        'use strict';
    
        var DiscountButton = require('pos_discount.DiscountButton');
        DiscountButton.template = "NewDiscount"
    });
    

    并将js文件添加到销售点资产:

    <template id="assets" inherit_id="point_of_sale.assets">
          <xpath expr="." position="inside">
              <script type="text/javascript" src="/my_module_name/static/js/new_discount.js"></script>
          </xpath>
    </template>  
    

    我想你已经定义了NewDiscount 模板并将其添加到清单文件的qweb 条目下。

    【讨论】:

    • 谢谢@Kenly,这行得通,用js代码添加新跨度和新模板怎么样?我尝试使用此代码(t-name)添加新 span ,但仍有问题 新折扣
    • 您可以更改按钮模板。检查我的编辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    相关资源
    最近更新 更多