Odoo Help

3

2
18 Answers
3
Avatar

Prashant Panchal (ppa) India

--Prashant Panchal (ppa)--
Prashant Panchal (ppa)
2167
| 3 2 5
gandhinagar, India
--Prashant Panchal (ppa)--


Prashant Panchal (ppa) India
5/26/17, 6:02 AM

Hello,


Please Try Following Demo: 

--------------------------

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>
18 Comments
Anil R. Kesariya (AKE) India
5/26/17, 6:11 AM

I followed as you explained. using t-extend and j-query

Tried this one NOT working

<template>

<t t-name="web.UserMenu" t-extend="web.UserMenu">

<t t-jquery='.dropdown-menu' t-operation='replace'/>

</t>

</template>

Tried this one NOT working

<template>

<t t-name="UserMenu" t-extend="UserMenu">

<t t-jquery='.dropdown-menu' t-operation='replace'/>

</t>

</template>

Not getting any error, but doesn't gives result as expected.

Prashant Panchal (ppa) India
5/26/17, 6:23 AM

use this one <templates> instead of <template>

Prashant Panchal (ppa) India
5/26/17, 6:29 AM

try this one

<templates xml:space="preserve">

<t t-extend="UserMenu">

<t t-jquery=".dropdown-menu" t-operation="replace"/>

</t>

</templates>

Anil R. Kesariya (AKE) India
5/26/17, 6:30 AM

When i use <templates> instead <template>, than xml file not loading, getting error.

Prashant Panchal (ppa) India
5/26/17, 6:33 AM

how to load xml file can you explain ? you can load xml file by javascript or in __openerp__.py or __manifest__.py

Anil R. Kesariya (AKE) India
5/26/17, 6:38 AM

I am loading XML file inside __openerp__.py under data = []

Prashant Panchal (ppa) India
5/26/17, 6:39 AM

load in 'qweb': [],

Anil R. Kesariya (AKE) India
5/26/17, 8:07 AM

@prashant : I loaded that XML file in 'qweb':[] instead of data. but still doesn't working :)

Anil R. Kesariya (AKE) India
5/26/17, 8:07 AM

I appreciate your help, thanks.

Prashant Panchal (ppa) India
5/26/17, 8:12 AM

create you file with templates code and put in this directory like

module > static > src > xml > file.xml

and you can use like : 'qweb': ['static/src/xml/file.xml'], and then after upgrade the module

Anil R. Kesariya (AKE) India
5/26/17, 8:14 AM

Yes prashant, I followed the same file path and upgraded module, but no error, but it not functioning.

Prashant Panchal (ppa) India
5/26/17, 8:21 AM

Create one js fille and put the code following code:

odoo.define('module_name.js_file_name', function (require) {

'use strict';

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

var ajax = require('web.ajax');

var qweb = core.qweb;

ajax.loadXML('/maodule/static/src/xml/file.xml', qweb);

});

Anil R. Kesariya (AKE) India
5/26/17, 8:38 AM

Yes, now loaded :) working perfectly.

Prashant Panchal (ppa) India
5/26/17, 8:39 AM

yeah..............................

Anil R. Kesariya (AKE) India
5/26/17, 8:48 AM

Cheers!

LaoThai Vietnam
5/30/19, 12:45 AM

Hi Anil, How can I add function print reciept for this button we just created?

Dasadiya Chaitanya India
9/20/19, 4:20 AM

Good Answer @Prashant your answer is really helping me a lot..

Prashant Panchal (ppa) India
9/20/19, 4:39 AM

Yeah,

Thank you

Cheers!

4
Avatar

Anil R. Kesariya (AKE) India

--Anil R. Kesariya (AKE)--
6755
| 8 7 10
Rajkot, India
--Anil R. Kesariya (AKE)--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.

Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66

Upwork : https://www.upwork.com/fl/anilkesariya


Anil R. Kesariya (AKE) India
5/26/17, 8:47 AM

Hi All,

Here I am writing complete solution which works for me, all credit goes to @ Prashant Panchal, Finally the long discussion on the solution was fruitful. 

Sample example.

Template file   : header_template.xml                   

<template id="template" xml:space="preserve">
    <t t-name="UserMenu" t-extend="UserMenu">
        <t t-jquery='.dropdown-menu' t-operation='replace'/>
    </t>
</template>
<!- Loaded XML files inside java script code -->


Javascript file qweb_template.js

odoo.define('yourmodulename.your_feature_name', function (require) {
'use strict';
var core = require('web.core');
var ajax = require('web.ajax');
var qweb = core.qweb;
ajax.loadXML('/yourmodulename/static/src/xml/header_template.xml', qweb);
});


Loading of Javascript file 

<template id="extended_libs" name="extended libs" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
    <script type="text/javascript" src="/yourmodulename/static/js/qweb_template.js"></script>
    </xpath>
</template>


Regards,

Anil kesariya

4 Comments
Minh Nguyen Vietnam
1/9/18, 4:57 AM

I have same problem like you, i want inherit templates from:

<templates id="template" xml:space="preserve">

<t t-name="UserMenu.Actions">

<li><a href="#" data-menu="documentation">Documentation</a></li>

<li><a href="#" data-menu="support">Support</a></li>

<li class="divider"/>

<li><a href="#" data-menu="settings">Preferences</a></li>

<li><a href="#" data-menu="account">My Odoo.com account</a></li>

<li><a href="#" data-menu="logout">Log out</a></li>

</t>

</templates>

in module web to add 1 more <li> to this list, can u suggest me anything? I tried to make it like you but it didn't word for me.

Thanks,

Minh

Anil R. Kesariya (AKE) India
1/9/18, 5:19 AM

In which version of odoo, you are applying this?

LaoThai Vietnam
5/30/19, 12:46 AM

Hi Anil, how can i add function print receipt for this button we just created?

Anil R. Kesariya (AKE) India
5/30/19, 1:23 AM

@LaoThai, I don't understand your question. please provide some more information.

1
Avatar

Mohammed Amal N India

--Mohammed Amal N--

2312
| 6 4 9
Ernakulam, India
--Mohammed Amal N--

Email : mohammedamal.n@gmail.com

Blog: https://www.blogger.com/profile/14877879550922602186

Mohammed Amal N India
5/26/17, 5:32 AM

Anything inside templates can be extended using t-extend and t-jquery.

1 Comment
Anil R. Kesariya (AKE) India
5/26/17, 5:38 AM

Thanks Mohammed for quick response, any sample example?

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now