I want to hide delete button from Export Data form view in odoo. Button that i want to hide also highlighted in attached image.
I'll be very thankful...
You will need to override Odoo's QWeb templates for such customizations.
Create a xml under mymodule/static/src/xml (e.g. your_customization.xml) with following content:
<template>
<t t-extend="Exists.ExportList">
<t t-jquery="button[id|='delete_export_list']" t-operation="replace" />
</t>
</template>
And then don't forget to call that file in your manifest (__openerp__.py) like
{
# other things like author, name, data
'qweb': ['static/src/xml/your_customization.xml'],
}
Related
I'm trying to make some debugging in a Form view, I wrote something like this inside the notebook section of a form view:
<page string="test">
<template>
<t t-esc="Logging!"/>
<t t-log="Logging!"/>
<t t-raw="Logging" > </t>
</template>
</page>
But nothing happens as if the section doesn't exist.
Can't we use Qweb template inside other views?
template tag will not render in form view. You can check this answer for more details
You can use templates in Activity, Gantt and Kanban views
I want to create a custom button in the odoo employee model, which creates and downloads a pdf with the working contract of this employee. I tried to reverse engineer the given buttons in odoo, but every approach of mine failed. Does someone have a tip on where to start? Thanks a lot!
I usually return an URL action with the download button, and write a controller for the URL. The result is clicking the button actually downloading a file.
First step is to write your Qweb report. I'll write a sample one here. Note that the report ID is action_report_test_contract which is used later in the controller.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<report string="Test Contract" id="action_report_test_contract" model="hr.contract" name="your_module_folder_name.test_contract_report" file="your_module_folder_name.test_contract_report" report_type="qweb-pdf" print_report_name="'%s - Contract' % (object.name)" />
<template id="test_contract_report">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.internal_layout">
<div class="page">
<h1><t t-esc="doc.name"/></h1>
<h2>Employee: <t t-esc="doc.employee_id.name"/></h2>
<h2>Start Date: <t t-esc="doc.date_start"/></h2>
</div>
</t>
</t>
</t>
</template>
</odoo>
Don't forget to add the report file path to your manufest. Test print the report from a contract, yes the sample works. Now inherit the hr.employee module to add the download method.
class HrEmployee(models.Model):
_inherit = "hr.employee"
def button_download_contract(self):
if not self.contract_id:
return
return {
'type' : 'ir.actions.act_url',
'url': '/web/download/test-contract-report?contract_id=%s'%(self.contract_id.id),
'target': 'self',
}
Also, inherit the view to add the download button:
<button name="button_download_contract" type="object" string="Download Contract" icon="fa-download"/>
Finally, finish the controller:
from odoo import http
from odoo.http import request, content_disposition, route
class testDownload(http.Controller):
#route(['/web/download/test-contract-report'], type='http', auth="user")
def download_pdf(self, contract_id, **kw):
employee_contract = request.env['hr.contract'].sudo().search([('id','=',contract_id)], limit=1)
if not employee_contract:
return None
pdf, _ = request.env.ref('your_module_folder_name.action_report_test_contract').sudo().render_qweb_pdf([int(contract_id)])
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)),('Content-Disposition', content_disposition('%s - Contract.PDF' % (employee_contract.name)))]
return request.make_response(pdf, headers=pdfhttpheaders)
Note that the method render_qweb_pdf relies on the report object. So action_report_test_contract is used, not test_contract_report.
I have created a test form and displayed using sitefinity's default mvc form widget and when submitting the form it displays thank you message(directly as text) without any html. I want to add some html with it so that i can style it as per my liking.
Change the form on the page to use UseAjaxSubmit from the widget designer model. After this go to "\ResourcePackages\Bootstrap\MVC\Views\Form\Index.cshtml" and find this piece of code.
if (Model.UseAjaxSubmit)
{
<h3 data-sf-role="success-message" style="display: none;">
#Model.SuccessMessage
<div>my customized message</div>
</h3>
You can change the rendering directly in the default template but I would recommend you to create a new template for the widget and keep the default one.
The Sitefinity Knowledgebase contains workarounds to override this when using AjaxSubmit or not.
If using AjaxSubmit is not enabled:
Create a new file under the Form folder (again, ResourcePackages > Bootstrap > MVC > Views > Form) with the following name: "Form.SubmitResultView.cshtml"
Use the following to display the styled text:
#Html.Raw(HttpUtility.HtmlDecode(ViewBag.SubmitMessage))
I ended up having to add my Form.SubmitResultView.cshtml under Mvc > Views > Forms and used the following markup as I needed a consistent wrapper div:
<div class="some-class">
#ViewBag.SubmitMessage
</div>
I am trying to add a button in the tree view of sale order module, next to create and import buttons. That button will execute a python method.
I have created my custom module, extending sale order module and then, I have followed these steps:
Step 1: Create the button in my_module/static/src/xml/qweb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<t t-if="widget.model=='sale.order'">
<button class="btn btn-sm btn-primary update_sales_button" type="button">Run my stuff</button>
</t>
</t>
</t>
</templates>
Step 2: Add the file to the qweb section in __openerp.py__ of my module:
'depends': ['sale'],
'data': [],
'qweb': ['static/src/xml/qweb.xml'],
Now, the button appears.
Step 3: Create the python method to give functionality to the button in my_module/my_python_file.py:
from openerp import api, fields, models, _
class SaleOrderExtended(models.Model):
_inherit = ['sale.order']
#api.multi
def update_sales_button(self):
...
Note: The python method has been tested outside of odoo and works fine.
How can I link this python method with the button?
You need to extend the 'ListView' widget adding a click listener.
Also add the '#api.model' decorator to your method, so you can call it from js with the 'call' method.
Something like this:
ListView = require('web.ListView')
ListView.include({
render_buttons: function() {
// GET BUTTON REFERENCE
this._super.apply(this, arguments)
if (this.$buttons) {
var btn = this.$buttons.find('.update_sales_button')
}
// PERFORM THE ACTION
btn.on('click', this.proxy('do_new_button'))
},
do_new_button: function() {
instance.web.Model('sale.order')
.call('update_sale_button', [[]])
.done(function(result) {
< do your stuff, if you don't need to do anything remove the 'done' function >
})
})
I'm using odoo 11 and I had to replace widget.model with widget.modelName in the topic starter's template (the former is an object, the latter is a string). Also, to append the button to the end of row I've changed t-operation to "append" while looking for the parent div:
<t t-extend="ListView.buttons">
<t t-jquery="div.o_list_buttons" t-operation="append">
<t t-if="widget.modelName=='sale.order'">
<button class="btn btn-sm btn-default import_email_button" type="button">
Import E-mail Order
</button>
</t>
</t>
</t>
I am trying to extend dijit.form.Button with an extra attribute but this is not working.Code is given below
In file1.js
dojo.require('dijit.form.Button');
dojo.extend(dijit.form.Button,{xyz: ''});
In file2.jsp
<script type="text/javascript" src="file1.js"></script>
<div dojoType="dijit.form.Button" xyz="abc"></div>
However when I look at the HTML of the created button (In chrome seen by right click and then selecting 'inspect element' option), it doesn't show xyz attribute.
You need to keep in mind that there's a distinction between the widget object and its HTML representation. When you extend dijit.form.Button, the xyz attribute is added to the widget class, but not automatically to the HTML that the widget will render. So in your case, if you do
console.debug(dijit.byId("yourWidgetId").get("xyz"));
.. you'll see that the button object does have the xyz member, but the HTML (like you point out) does not.
If you also want it do be visible in the HTML, you have to manually add it to the HTML rendering of the button. One way to do that is to subclass dijit.form.Button and override the buildRendering method.
dojo.declare("my.Button", dijit.form.Button, {
xyz: '',
buildRendering: function() {
this.inherited(arguments);
this.domNode.setAttribute("xyz", this.xyz);
}
});
If you add an instance of your new Button class in the HTML, like so:
<div dojoType="my.Button" xyz="foobar" id="mybtn"></div>
.. then the HTML representation (after Dojo has parsed it and made it into a nice looking widget) will contain the xyz attribute. Probably something like this:
<span class="..." xyz="foobar" dir="ltr" widgetid="mybtn">
<span class="..." dojoattachevent="ondijitclick:_onButtonClick">
<input class="dijitOffScreen" type="button" dojoattachpoint="valueNode" ...>
</span>