How to add button in odoo? - odoo

I want to add a button before or after the "create" Button in Tree view That calls the action of another view.
But as I tried header tag is not working in xml to add the button in header of the odoo.

You need to extend ListView.buttons QWEB template.
Define a QWEB template under static/src/xml which adds the button:
<?xml version="1.0" encoding="utf-8"?>
<template xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.oe_list_add" t-operation="after">
<button t-if="widget.dataset.model == 'model_name'" class="oe_button oe_my_button oe_highlight" type="button">My Button</button>
</t>
</t>
</template>
Use JavaScript to define the logic of the button ( create a file under static/src/js):
openerp.module_name = function(instance){
instance.web.ListView.include({
load_list: function(data) {
this._super(data);
if (this.$buttons) {
this.$buttons.find('.oe_my_button').off().click(this.proxy('do_the_job')) ;
}
},
do_the_job: function () {
this.do_action({
name: _t("View name"),
type: "ir.actions.act_window",
res_model: "object",
domain : [],
views: [[false, "list"],[false, "tree"]],
target: 'new',
context: {},
view_type : 'list',
view_mode : 'list'
});
}
});
}
Define a new view that will add module assets (module_name_view.xml):
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend_module_name" name="module_name assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/module_name/static/src/js/script.js"></script>
</xpath>
</template>
</data>
Edit __openerp__.py and add the following sections:
'data': [
'module_name_view.xml',
...
],
'qweb': ['static/src/xml/*.xml'],
Look at Building Interface Extensions for more details.

Related

Odoo Qweb & javascript

I learn about Qweb and javascirpt in odoo through youtube channel and documnention, but it's too difficult, I can't understand how it works and the organizational structure and syntax. Is there any way you can help me?
Introduction to javascript in odoo :
https://www.youtube.com/watch?v=VuUMvzycXQY
Example of use in your module : my_module_custom
In my_module_custom/static/src/js/myclientscript.js :
odoo.define('my_module_custom.hidebadgepill', function(require)
{
"use strict";
$(document).ready(function() {
$(function() {
//your js or jquery script , for instance :
$('.o_web_index_topbar_filters').find('.badge-pill').hide();
});
});
in my_module_custom/views/assets_frontend.xml :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend"
inherit_id="website.assets_frontend" name="Date Check">
<xpath expr="." position="inside">
<script type="text/javascript" src="/my_module_custom
/static/src/js/myclientscript.js"/>
</xpath>
</template>
</odoo>
in my_module_custom/_manifest.py :
##-*- coding: utf-8 -*-
{
'name': 'my module custom name',
'version': '13.0.2.0.147',
...
'data': [
'views/assets_frontend.xml',
...

Odoo 10 change field colour

I am trying to change the color of a field in Odoo10. here is my code
<xpath expr="//field[#name='order_line']/form//field[#name='analytic_tag_ids']" position="after">
<label for="squarebox"/>
<div>
<field name="squarebox"/>
</div>
<label for="squaremtrsold"/>
<div>
<field name="squaremtrsold"/>
</div>
</xpath>
I tried <field name="squarebox"style="background:Blue;"/>
But this did not work?
Try adding the style for the div containing the field definition, since the field tag will not appear on the final html.
You could also add a class to the containing div and with some CSS rules you could target the field dom nodes to add the proper style rules
Try this module https://apps.odoo.com/apps/modules/10.0/web_widget_color_field/
using above module widget you can change the filed colour as per your interest.
You can give it a class, for instance 'squarebox', and then write your css code in your static folder, taking into account that your field will be rendered as an input tag later. So the next code should do the trick.
<label for="squarebox"/>
<div>
<field name="squarebox" class="squarebox"/>
</div>
And then in your css file:
input.squarebox {
background-color: blue;
}
Pay attention to append your custom css to the assets, something like this:
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_backend" name="My Module Assets" inherit_id="web.assets_backend">
<xpath expr="//link[last()]" position="after">
<link rel="stylesheet" href="your_module_name/static/src/css/styles.css"/>
</xpath>
</template>
</odoo>
And finally to the manifest.py
'data': [
'views/your_custom_assets.xml',
],
'css': ['static/src/css/styles.css'],
You should upgrade your modulea, and if not working, enter in ?debug=assets mode

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.

QWeb pdf report odoo 10

I am new in odoo I want to make a report pdf to my model, I have try all tuto I have find in net youtube, google but no one work for me please give me an advice.
there is my model :
# modelx.py file
from openerp import models, fields, api
class omega(models.Model):
_name = 'omega.model'
_description = 'No Description for now !!'
#api.model
def render_html(self, docids, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('report.external_layout')
docargs = {
'doc_ids': docids,
'doc_model': report.model,
'docs': self,
}
return report_obj.render('report.external_layout', docargs)
state = fields.Selection([
('Nouveau', 'Nouveau'),
('valid', 'Validation Responsable'),
('Termine', 'Termine'),
],default='Nouveau')
#api.one
def confirmer(self):
self.write({
'state': 'valid',
})
employe = fields.Many2one(comodel_name="res.users", string="Employe", required=True, delegate=True)
date = fields.Datetime(string="Date", required=True)
date2 = fields.Date(string="Date2", required=True)
day_number = fields.Integer(string="Nombre de jour", required=True)
transport = fields.Selection(string="Transport", selection=[('1', 'Train'), ('2', 'Voiture de Service'), ('3', 'Avion')])
sujet = fields.Char(string="Sujet", required=True)
lieu = fields.Char(string="Lieu", required=False)
I have also this two file XML:
<!-- report.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<openerp>
<data>
<report
id="action_report_omega"
model="omega.model"
string="Report"
report_type="qweb-pdf"
file="report.external_layout"
name="report.external_layout"
/>
</data>
</openerp>
and this file for template view as I find in net and odoo documentation
<!-- report_template.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<openerp>
<data>
<template id="report_omega_document">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<div class="oe_structure">
<div class="row">
<H1>Hi there hello</H1>
</div>
</div>
</div>
</t>
</t>
</template>
<template id="report_omega">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<t t-foreach="doc_ids" t-as="doc_id">
<div class="page">
<div class="oe_structure">
<div class="row">
<H3>Hi hello </H3>
</div>
</div>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>
when I execute the programme for printing the report I get an empty file, give me any advice please
You need to change file and name attribute of report tag. It always represent module_name.report_template_name
<report
id="action_report_omega"
model="omega.model"
string="Report"
report_type="qweb-pdf"
file="your_module_name.report_omega"
name="your_module_name.report_omega"
/>
Afterwards, upgrade your module and try it. It should work fine.
For more details, you may refer Qweb Reports - Odoo10 Document.

ParseError: External ID conflict while creating custom qweb report

I created a folder called Student. When i open this module i am getting the above said error. this is my opennerp file,
{
'name': "Student",
'version': '1.0',
'sequence': 7,
'depends': ['base','report'],
'author': "ZD",
'category': 'Testing',
'description': "Module used for testing purpose only",
'data': [
'student_custom_view.xml',
'views/Student_report123.xml',
'Student_report.xml',
],
'installable': True,
'auto_install': False,
}
Then in .py file,
class student(models.Model):
_name = 'student'
name = fields.Char(string='Number', compute='_compute_name')
total2 = fields.Char(string='Total in words', compute='_compute_total')
student_report.xml,
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="Student_report123"
string="Report"
model="student"
report_type="qweb-pdf"
file="Student.Student_report123"
name="Student.Student_report123"
attachment_use="False"
/>
</data>
</openerp>
Inside views folder i created a file called Student_report123.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="Student_report123">
<t t-call="report.external_layout">
<div class="page">
<div class="row">
<span t-field="o.total2"></span>
</div>
</div>
</t>
</template>
</data>
</openerp>
Under you student_report.xml file and student_report123.xml file the id provided are xml ids and no two xml ids are allowed same. Xml IDs must be unique throughout the database.
you can try this code:
<t t-name="student_report123">
<t t-call="report.external_layout">
<div class="page">
<div class="row">
<h2>Success</h2>
<span t-field="o.total2"/>
</div>
</div>
</t>
</t>