javascriptjqueryodooodoo-16trending

want to change the label in xml file odoo


I want to inherit this file, odoo16/addons/product/staic/src/xml/price_report.xml, and change the one of labels

<div class="form-check">
  <input class="form-check-input o_is_visible_title ms-2" type="checkbox"/>
  <label class="form-check-label">Display Pricelist</label>
</div>

I tried using jQuery but it's working in Chrome console only, not in odoo. Let me share my JS

odoo.define('aretx_product_pricelist.custom', function (require) {
  "use strict";

  var core = require('web.core');
  var Widget = require('web.Widget');

  var test = $('.form-check-label').text('newText');
  $('html body .form-check-label').text('newText123');
  $('.form-check-label').text('newText123');
  $('html .form-check-label').text('newText123');
  $('body .form-check-label').text('newText132');
});

I want to simply change the label from any method.


Solution

  • You can inherit/extend/change QWeb templates.

    Source: Odoo Dev Documentation

    Template inheritance

    Template inheritance is used to either:

    Template inheritance is performed via the use of two directives:

    An optional t-name directive can also be specified. It will be the name of the newly created template if used in primary mode, else it will be added as a comment on the transformed template to help retrace inheritances.

    For the inheritance itself, the changes are done using xpaths directives. See the XPATH documentation for the complete set of available instructions.

    Primary inheritance (child template):

    <t t-name="child.template" t-inherit="base.template" t-inherit-mode="primary">
        <xpath expr="//ul" position="inside">
            <li>new element</li>
        </xpath>
    </t>
    

    Extension inheritance (in-place transformation):

    <t t-inherit="base.template" t-inherit-mode="extension">
        <xpath expr="//tr[1]" position="after">
            <tr><td>new cell</td></tr>
        </xpath>
    </t>