Skip to content

Instantly share code, notes, and snippets.

@ppa-odoo
Last active December 19, 2023 13:06
Show Gist options
  • Save ppa-odoo/73c091e2fa4a4341dcb485ab6f0920ba to your computer and use it in GitHub Desktop.
Save ppa-odoo/73c091e2fa4a4341dcb485ab6f0920ba to your computer and use it in GitHub Desktop.
Odoo: How to inherit <templates> of web module?
REF LINK: https://www.odoo.com/forum/help-1/question/odoo10-how-to-inherit-templates-of-web-module-119140#answer-119142
This is main template:
<template id="template" xml:space="preserve">
<t t-name="DemoExample">
<div class="demo-one">
<p>odoo</p>
</div>
</t>
</template>
How To Inherit
----------------------
Template file :-> demo_template.xml
<template id="template" xml:space="preserve">
<t t-name="DemoExample" t-extend="DemoExample">
<t t-jquery='.demo-one' t-operation='replace'>
<p>Your Company Name</p>
</t>
</t>
</template>
-----------------------------------------------------
<!- Loaded XML files inside java script code -->
-----------------------------------------------------
JS file :--> demo_example.js
-------------------------------------------------------------------------
put the following JS Code in demo_example.js file:
-------------------------------------------------------------------------
odoo.define('module_name.name_of_fetures', function (require) {
'use strict';
var core = require('web.core');
var ajax = require('web.ajax');
var qweb = core.qweb;
ajax.loadXML('/module_name/static/src/xml/demo_template.xml', qweb);
});
-----------------------------------
Loading of Javascript file
-----------------------------------
<template id="demo_example_ext_js" name="Demo Example Ext Js" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/module_name/static/js/demo_example.js"></script>
</xpath>
</template>
@jp-sft
Copy link

jp-sft commented Nov 7, 2022

Thank lot for this!!

@ppa-odoo
Copy link
Author

ppa-odoo commented Nov 9, 2022

@jp-sft glad to helpful for you!

@HamidAbdalla123
Copy link

this way is working in odoo 15 ?

@OtmanGX
Copy link

OtmanGX commented Dec 5, 2022

@HamidAbdalla123
Yes it's working on odoo 15, if you have any issue tell us maybe we can help.
Just one more thing .. if you want to include a js file on any assets for instance: web.assets_backend you will have to add this property on manifest.py:

'assets': {
        'web.assets_backend': [
            'module_name/static/src/js/js_file.js',
        ],
    }

@ppa-odoo
Copy link
Author

ppa-odoo commented Dec 5, 2022

this way is working in odoo 15 ?
structure has been changed, so you have to check manifest.py file,
how to set the JS, XML, CSS, SCSS file

document
https://www.odoo.com/documentation/15.0/developer/reference/frontend/assets.html#bundles

@ppa-odoo
Copy link
Author

ppa-odoo commented Dec 5, 2022

@OtmanGX Thank you!

@HamidAbdalla123
Copy link

@OtmanGX @ppa-odoo thank you
i need some resources to learn owl framwork
can help me ?

@OtmanGX
Copy link

OtmanGX commented Dec 16, 2022

@ppa-odoo
Copy link
Author

@OtmanGX Thank you very much for sharing with us!
it will be very useful for the other developer
@HamidAbdalla123 please check it above link.

@HamidAbdalla123
Copy link

@ppa-odoo @OtmanGX
Guys I need some help
I want to call and show js popup in my custom module js , the popup i want to call it in pos and name it NumberPopup
how can do that
my module is outside pos it custom module

@AminNoury
Copy link

hi all i want to change tooltip question marker to "!" how to inherit templates to change this on
there is source code in: addons/web/static/src/views/form/form_lable.xml

and source code is:

<t t-name="web.FormLabel">
    <label class="o_form_label" t-att-for="props.id" t-att-class="className" >
        <t t-esc="props.string"/><sup class="text-info p-1" t-if="hasTooltip" t-att="{'data-tooltip-template': 'web.FieldTooltip', 'data-tooltip-info': tooltipInfo, 'data-tooltip-touch-tap-to-show': 'true'}">?</sup>
    </label>
</t>

please help me tnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment