want to change the label in xml file odoo

95 views Asked by At

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.

1

There are 1 answers

0
CZoellner On BEST ANSWER

You can inherit/extend/change QWeb templates.

Source: Odoo Dev Documentation

Template inheritance

Template inheritance is used to either:

  • Alter existing templates in-place, e.g. to add information to templates created by other modules.
  • Create a new template from a given parent template

Template inheritance is performed via the use of two directives:

  • t-inherit which is the name of the template to inherit from,
  • t-inherit-mode which is the behaviour of the inheritance: it can either be set to primary to create a new child template from the parented one or to extension to alter the parent template in place.

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>