Odoo Help

Welcome!

This community 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.

0

how to add a button/field on the header of "tree" view?

By
vx2008
on 7/27/16, 3:19 AM 424 views

I want to add a button and a field on the header of "tree" view at "create" and "import" button; 

how shall I do / set for this? or shall I to do this?

0
shameem@axon
On 7/27/16, 4:12 AM


Create an xml file for qweb and also add in __openerp__.py

Example:

 'qweb':  ['static/src/xml/qweb.xml'],



In qweb.xml


<?xml version="1.0" encoding="UTF-8"?> 

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

 <T t-extend = "ListView.buttons">


     <T t-jquery = "button.oe_list_add" t-operation = "after">
        <T t if = "widget.model == 'YOUR.MODEL'">
             <Button class = "oe_button" type = "button"> YOU BUTTON </ button>
         </ T>
     </ T>
</ T>

there something eroro:

ERROR MeiTek openerp.http: Exception during JSON request handling.

ParseError: not well-formed (invalid token): line 10, column 67

<T t if = "widget.model == 'YOUR.MODEL'"> modified into <T t-if = "widget.model == 'Detection'">, <Button class = "oe_button" type = "button"> YOU BUTTON </ button> modified into <Button class = "oe_button" type = "button"> register</ button>

When I delete the "qweb" file, all is ok;

Maybe shall I add a common "field" instead of "button"?

vx2008
on 7/27/16, 9:54 AM

I have modified a little about your code as below:

<?xml version="1.0" encoding="UTF-8"?>

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

<T t-extend = "ListView.buttons">

<T t-jquery = "button.oe_list_add" t-operation = "after">

<T t-if = "widget.model == 'Detection'">

<button class = "oe_button" type = "button" string="Test"> register</button>

</T>

</T>

</T>

</templates>

in .py file:

@api.multi

def register(self):

print 'just a test!'

return True

my this module name: "Detection"; and I also created an qweb file as your request in "../addons/Detection/static/src/xml/qweb.xml";

when I modified the file and restart Odoo and update the "Detection" module; there is no error, but when I open the "tree", nothing changed.

vx2008
on 7/27/16, 10:15 AM

You add your model name here .(Not module name)

Example :

<T t if = "widget.model == 'sale.order'">

The button will be appear in the tree view of sale.order

shameem@axon
on 7/27/16, 11:52 PM

Thank you for you constant support; I have a try for that, but I still can;t see the button in tree view; now I will show all files here:

__init__.py : from . import meeting_model

__openerp__.py:

'name': 'Meeting Application',

'description': 'Publish a meeting',

'author': 'Odoo',

'application': True,

'qweb': ['qweb.xml'],

'data': ['meeting_view.xml']

}

meeting_model.py:

# -*- coding: utf-8 -*-

from openerp import models, fields,api

class MeetingTask(models.Model):

_name = 'meeting.task'

_description = 'Meeting task'

Theme = fields.Char('theme')

@api.multi

def register(self):

self.Theme='Just a test!'

qweb.xml:

<?xml version="1.0" encoding="utf-8"?>

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

<T t-extend = "ListView.buttons">

<T t-jquery = "button.oe_list_add" t-operation = "after">

<T t-if = "widget.model == 'meeting.task'">

<button class = "oe_button" type = "button" >register</button>

</T>

</T>

</T>

</templates>

meeting_view.xml:

<?xml version="1.0"?>

<openerp>

<data>

<!-- Action to open To-Do Task list -->

<act_window id="action_meeting_task"

name="Meeting Tasks"

res_model="meeting.task"

view_mode="tree,form" />

<!-- Menu Item to open To-Do Task list -->

<menuitem id="menu_meeting_task"

name="Meeting"

sequence="20"

action="action_meeting_task" />

<!-- To-Do Task Form view -->

<record id="view_form_meeting_task" model="ir.ui.view">

<field name="name">Meeting Task Form</field>

<field name="model">meeting.task</field>

<field name="arch" type="xml">

<form>

<button name="register" type="object" string="Participate" />

<group name="group_top">

<field name="Theme"/>

</group>

</form>

</field>

</record>

<!-- To-Do Task List view -->

<record id="view_tree_meeting_task" model="ir.ui.view">

<field name="name">Meeting Task Tree</field>

<field name="model">meeting.task</field>

<field name="arch" type="xml">

<tree>

<field name="Theme"/>

</tree>

</field>

</record>

</data>

</openerp>

in addition, could you give me an example which add button/fields at create/import buttons on "tree" view? my email: 116599778@qq.com; thank you again!

vx2008
on 7/29/16, 10:55 AM

I created the following module in odoo v9 and it works.

==================================================

◰ button_tree

-|___◰static

-|-----|___◰description

-|-----|___◰src

-|---------|___◰xml

-|--------------|___☐qweb.xml

-|___☐__init__.py

-|___☐__openerp__.py

==================================================

1) __init__.py : <empty>

2) __openerp__.py:

{

'name': 'Button at top of Tree',

'version': '1.0',

'author': 'Shameem',

'category': '',

'description': """ """,

'depends': ['sale'],

'data': [],

'qweb': ['static/src/xml/qweb.xml'],

'demo': [],

'installable': True,

'auto_install': False,

}

3) 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="oe_button oe_highlight"

type="button">Custom Button</button>

</t>

</t>

</t>

</templates>

shameem@axon
on 7/30/16, 1:35 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/27/16, 3:19 AM
Seen: 424 times
Last updated: 7/30/16, 6:51 AM