How to extend a qweb template in Odoo? - odoo

Im trying to extend the point of sale, template to modify the web ticket and the printed version also.... I want to put a codebar with the id numbe. But reading and testing my code doesn't work.... For testing purpuse I put a text in several parts of the template to watch if it is modify... but it's not.
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-extend="XmlReceipt">
<t t-jquery=".receipt-change" t-operation="inner">
<div><span>hello world</span></div>
</t>
</t>
<t t-extend="PosTicket">
<t t-jquery=".receipt-orderlines .product_line" t-operation="inner">
<div><span>hello world</span></div>
</t>
</t>
<t t-extend="PaymentScreenWidget">
<t t-jquery="div.pos-payment-container" t-operation="inner">
<div>
Payment Screen Modified
</div>
</t>
</t>
</templates>
This code is in a file name pos.xml and I append it from openerp.py like this:
'qweb': ['static/src/xml/pos.xml'],
Why the XmlReceipt or the PosTicket or the payment template are not extending????
Then when I sucessfully extend the template, Im gonna try to replace the hello world with
<barcode encoding="CODE128"><t t-esc="o.id"/></barcode>
Thanks!
[EDIT]
Ok, now I'm extending the template, but I cant generate the barcode from the order.sequence_number
I'm trying like this:
<img class="img-responsive" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('Code128', order.sequence_number, 500, 100)" style="width:250px;height:50px;"/>
The barcode its not generate like this... but if I do it like this it is
<img t-att-src="'/report/barcode/Code128/*mycode*'" style="width:250px;height:50px;"/>
So I think the error is in the string rendering.....

This is how I extends the mail chatter in odoo-10 and it's working fine for me.
Take a look, may be its help if still needed.
<templates>
<!--
Chatter composer
-->
<t t-extend="mail.chatter.ChatComposer">
<!-- Insert information before the composer -->
<t t-jquery=".o_composer_suggested_partners" t-operation="replace">
<!-- List of followers -->
<div class="o_composer_suggested_partners">
<t t-foreach='widget.suggested_partners' t-as='recipient'>
<div t-attf-title="Add as recipient and follower (reason: #{recipient.reason})">
<input type="checkbox" t-att-data-fullname="recipient.full_name"/>
<t t-esc="recipient.name"/>
<t t-if="recipient.email_address">(<t t-esc="recipient.email_address"/>)</t>
</div>
</t>
</div>
</t>
</t>
</templates>

Related

how to hide the sidebar on saleorder formview odoo?

I have been trying many different ways for hiding the sidebar button. Below code is working on all forms. However, i just want to hide it on sale order form. Widget.modelName seems not working because it is before the form declaration. I also tried doc_model in [sale.order'] and not working as well. How can I solve it? thanks
<t t-jquery = ".o_cp_left" t-operation = "replace">
<t t-if = "widget.modelName == 'sale.order'">
<div class="o_cp_left hiddenManagerSO">
<div class="o_cp_buttons" role="toolbar" aria-label="Control panel toolbar"/>
<aside class="o_cp_sidebar"/>
</div>
</t>
<t t-if = "widget.modelName !== 'sale.order'">
<div class="o_cp_left hiddenManagerKOO">
<div class="o_cp_buttons" role="toolbar" aria-label="Control panel toolbar"/>
<aside class="o_cp_sidebar"/>
</div>
</t>
</t>
</t>

Odoo 10 how to replace inherited qweb template content

I have tried to insert a tag into an existing template but couldn't get it to work.
Existing template in odoo/addons/mail/static/src/xml/thread.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="mail.ChatThread">
<t t-if="messages.length">
:
<t t-name="mail.ChatComposer.Attachments">
<div class="o_attachments">
<t t-foreach="attachments" t-as='attachment'>
<t t-call="mail.Attachment">
<t t-set="editable" t-value="true"/>
</t>
</t>
</div>
</t>
<t t-name="mail.Attachment">
<div t-attf-class="o_attachment #{attachment.upload ? 'o_attachment_uploading' : ''}" t-att-title="attachment.name">
<a class="o_image" t-att-href='attachment.url' target="_blank" t-att-data-mimetype="attachment.mimetype" t-attf-data-src="/web/image/#{attachment.id}/100x80">
<span class='o_attachment_name'><t t-esc='attachment.name'/></span>
</a>
<t t-if="editable">
<div class="o_attachment_delete">
<i class='fa fa-times-circle' title="Delete this attachment" t-att-data-id="attachment.id"/>
</div>
<div class="o_attachment_progress_bar">
Uploading
</div>
</t>
</div>
</t>
My custom template (odoo/addons/mycustom/static/src/xml/thread.xml):
I want to insert the Hello world after the class o_image in the original template.
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="mycustom.ImageAttachment" t-extend="mail.Attachment">
<t t-jquery="o_image" t-operation="append">
<div>Hello world</div>
</t>
</t>
</templates>
My javascript to render the template (odoo/addons/mycustom/static/src/js/thread.js):
odoo.define('mycustom.thread', function (require) {
"use strict";
var core = require('web.core');
var ajax = require('web.ajax');
var qweb = core.qweb;
ajax.loadXML('/mycustom/static/src/xml/thread.xml', qweb);
console.log("INFO", "Hello World")
});
My assets file (odoo/addons/mycustom/views/assets.xml):
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="my assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/mycustom/static/src/js/thread.js"></script>
</xpath>
</template>
</odoo>
My manifest file (odoo/addons/mycustom/manifest.py):
# -*- coding: utf-8 -*-
{
'name': "test",
'summary': """my test""",
'description': """
This is my test module.
""",
'author': "peter",
'website': "",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/odoo/addons/base/module/module_data.xml
# for the full list
'category': 'Test',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base','mail'],
# always loaded
'data': [
'views/assets.xml',
],
'qweb': [
'static/src/xml/thread.xml',
],
}
The javascript is loaded because I can see the text Hello World written on the browser console.
However, I cannot see the <div>Hello World</div> in the chat thread. What did I miss?
Try this:
<t t-name="mail.Attachment" t-extend="mail.Attachment">
<t t-jquery="o_image" t-operation="inner">
<div>Hello world</div>
</t>
</t>
Hope it will help you.

Odoo - Change create button text

I am using Odoo 10e. In tree view or in form view for my particular model, i want to change the create button text to Add New User. How can we achieve this?
I tried to use Xpath for this, but as far as i know Xpath is use to inherit from a view and add something in the view not to change the item in the parent view
Create one xml file and write this below code in it.
For listview and formview it will change the name of create button as per your custom string.
Add this xml file path to qweb section in manifest file.
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery=".o_list_button_add" t-operation="replace">
<button type="button" class="btn btn-primary btn-sm o_list_button_add" accesskey="c">
<t t-if="widget.model === 'sale.order'">
Your String
</t>
<t t-if="widget.model !== 'sale.order'">
<t t-esc="widget.options.addable"/>
</t>
</button>
</t>
</t>
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_button_create" t-operation="replace">
<button t-if="widget.is_action_enabled('create')" type="button"
class="btn btn-default btn-sm o_form_button_create" accesskey="c">
<t t-if="widget.model === 'sale.order'">
Your String
</t>
<t t-if="widget.model !== 'sale.order'">
Create
</t>
</button>
</t>
</t>
</templates>
I hope this answer will help you.
Simply just xpath to that button.
Then give position replace and change the string to Add New User from Create.
Try the code like this.
But remember the name of the button will be as it is.
Thanks
<xpath expr="//button[#name='action_set_create']" position="replace">
<button name="action_set_create" string="Add New User"/>
</xpath>

Uncaught Error: QWeb2: Error while extending template 'ClientDetailsNo expression given

Getting this error when trying to extend a qweb template. Has anyone come across something like this. I've not been able to find anything related to this.
Uncaught Error: QWeb2: Error while extending template 'ClientDetailsNo expression given
http://localhost:8069/web/content/246-17d551a/web.assets_common.js:2444Traceback:
Error: QWeb2: Error while extending template 'ClientDetailsNo expression given
at Object.exception (http://localhost:8069/web/content/246-17d551a/web.assets_common.js:2444:7)
at Engine.extend (http://localhost:8069/web/content/246-17d551a/web.assets_common.js:2482:507)
at Engine._render (http://localhost:8069/web/content/246-17d551a/web.assets_common.js:2477:454)
at Engine.render (http://localhost:8069/web/content/246-17d551a/web.assets_common.js:2477:151)
at Class.display_client_details (http://localhost:8069/web/content/313-25bfa95/point_of_sale.assets.js:337:1375)
at Class.line_select (http://localhost:8069/web/content/313-25bfa95/point_of_sale.assets.js:332:528)
at HTMLTableRowElement.<anonymous> (http://localhost:8069/web/content/313-25bfa95/point_of_sale.assets.js:327:86)
at HTMLTableSectionElement.dispatch (http://localhost:8069/web/content/246-17d551a/web.assets_common.js:740:451)
at HTMLTableSectionElement.elemData.handle (http://localhost:8069/web/content/246-17d551a/web.assets_common.js:713:173)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ClientDetails">
<t t-query="div.client-details-right" t-operation="append">
<div class="client-detail">
<span class="label">RNC</span>
<span class="detail client-phone">Test</span>
</div>
</t>
</t>
There is a typo in the attribute name for the jQuery selector -- it should be t-jquery, not t-query:
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ClientDetails">
<t t-jquery="div.client-details-right" t-operation="append">
<div class="client-detail">
<span class="label">RNC</span>
<span class="detail client-phone">Test</span>
</div>
</t>
</t>
</templates>

Hide EXPORT option in more button in OPENERP 7

How to hide the EXPORT Option in the more button for specific user group, and how to hide the 'MORE' button for specific user group in openerp 7.
Hide "Export in More Option"
in OpenERP-7
Create XML File Under static/src/base.xml in your module and add this code:
<templates>
<t t-extend="Sidebar">
<t t-jquery="a.oe_sidebar_action_a" t-operation="replace">
<t t-if="widget.session.uid !== 1">
<a t-if="item.label !== 'Export'" class="oe_sidebar_action_a" t-att-title="item.title or ''" t-att-data-section="section.name" t-att-data-index="item_index" t-att-href="item.url" target="_blank">
<t t-raw="item.label"/>
</a>
</t>
<t t-if="widget.session.uid === 1">
<a class="oe_sidebar_action_a" t-att-title="item.title or ''" t-att-data-section="section.name" t-att-data-index="item_index" t-att-href="item.url" target="_blank">
<t t-raw="item.label"/>
</a>
</t>
</t>
</t>
</templates>
Add this in File __openerp__.py:
'qweb': [
"static/src/base.xml",
]
Now restart the server and update your database and refresh the page.