SlideShare a Scribd company logo
1 of 3
odoo11如何在TreeView的左上角新增按鈕
想在TreeView的左上角新增按鈕,在網路上搜尋到的解答大部份都無法正執行,可能是只用於舊版本,以下是適合於odoo11的作法。
1。在ListView的template增加了兩個按鈕
新增檔案:staticsrcxml tree_view_button.xml
<?xml version="1.0" encoding="UTF-8"?>
<template id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="before">
<button t-if="widget.modelName == 'tennen100.customer'" class="btn btn-primary btn-sm oe_new_buttonxxx" type="button"><t t-esc="widget.modelName"/></button>
<button t-if="widget.modelName == 'tennen100.customer'" class="btn btn-primary btn-sm oe_new_buttonxxx2" type="button">test</button>
</t>
</t>
</template>
2。Javascript的程式用來處理按鈕要處理的要做什麼事,第一個按鈕會跑出另一個actiion視窗,第二個執行一個method
新增檔案: staticsrcjs tree_view_button.js
odoo.define('tennen100.tree_view_button', function (require){
"use strict";
var core = require('web.core');
var ListController = require('web.ListController');
var QWeb = core.qweb;
var rpc = require('web.rpc');
ListController.include({
renderButtons: function($node) {
this._super.apply(this, arguments);
if (this.$buttons) {
let filter_button = this.$buttons.find('.oe_new_buttonxxx');
filter_button && filter_button.click(this.proxy('filter_button')) ;
let filter_button2 = this.$buttons.find('.oe_new_buttonxxx2');
filter_button2 && filter_button2.click(this.proxy('filter_button2')) ;
}
},
filter_button: function () {
//執行action
this.do_action({type: "ir.actions.act_window", name: "product", res_model: "tennen100.order",
views: [[false,'form']], target: 'current', view_type : 'form', view_mode : 'form',
flags: {'form': {'action_buttons': true, 'options': {'mode': 'edit'}}}
});
},
filter_button2: function () {
//執行function
var args = [{"data1":"1","data2":"2"}];
rpc.query({ model: 'tennen100.customer', method: 'do_test', args: [args]}).then(function(data){
alert(data);
});
}
});
core.action_registry.add('tennen100.tree_view_button', ListController);
return ListController;
});
3。設定會使用到的javascript程式
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend" name="tree view menu" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/tennen100/static/src/js/tree_view_button.js"></script>
</xpath>
</template>
</data>
</odoo>
4。設定檔案:__manifest__.py 把會用到的程式檔配置好
# -*- coding: utf-8 -*-
{
'name': "tennen100",
'category': 'Uncategorized',
'version': '0.1',
'depends': ['base','web'],
'data': [
'views/tree_view_asset.xml',
'views/views.xml',
],
'qweb': ['static/src/xml/tree_view_button.xml'],
],
}

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

odoo11如何在TreeView的左上角新增按鈕

  • 1. odoo11如何在TreeView的左上角新增按鈕 想在TreeView的左上角新增按鈕,在網路上搜尋到的解答大部份都無法正執行,可能是只用於舊版本,以下是適合於odoo11的作法。 1。在ListView的template增加了兩個按鈕 新增檔案:staticsrcxml tree_view_button.xml <?xml version="1.0" encoding="UTF-8"?> <template id="template" xml:space="preserve"> <t t-extend="ListView.buttons"> <t t-jquery="button.o_list_button_add" t-operation="before"> <button t-if="widget.modelName == 'tennen100.customer'" class="btn btn-primary btn-sm oe_new_buttonxxx" type="button"><t t-esc="widget.modelName"/></button> <button t-if="widget.modelName == 'tennen100.customer'" class="btn btn-primary btn-sm oe_new_buttonxxx2" type="button">test</button> </t> </t> </template> 2。Javascript的程式用來處理按鈕要處理的要做什麼事,第一個按鈕會跑出另一個actiion視窗,第二個執行一個method 新增檔案: staticsrcjs tree_view_button.js odoo.define('tennen100.tree_view_button', function (require){ "use strict"; var core = require('web.core'); var ListController = require('web.ListController'); var QWeb = core.qweb; var rpc = require('web.rpc'); ListController.include({ renderButtons: function($node) { this._super.apply(this, arguments); if (this.$buttons) { let filter_button = this.$buttons.find('.oe_new_buttonxxx'); filter_button && filter_button.click(this.proxy('filter_button')) ; let filter_button2 = this.$buttons.find('.oe_new_buttonxxx2'); filter_button2 && filter_button2.click(this.proxy('filter_button2')) ; } },
  • 2. filter_button: function () { //執行action this.do_action({type: "ir.actions.act_window", name: "product", res_model: "tennen100.order", views: [[false,'form']], target: 'current', view_type : 'form', view_mode : 'form', flags: {'form': {'action_buttons': true, 'options': {'mode': 'edit'}}} }); }, filter_button2: function () { //執行function var args = [{"data1":"1","data2":"2"}]; rpc.query({ model: 'tennen100.customer', method: 'do_test', args: [args]}).then(function(data){ alert(data); }); } }); core.action_registry.add('tennen100.tree_view_button', ListController); return ListController; }); 3。設定會使用到的javascript程式 <?xml version="1.0" encoding="utf-8"?> <odoo> <data> <template id="assets_backend" name="tree view menu" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <script type="text/javascript" src="/tennen100/static/src/js/tree_view_button.js"></script> </xpath> </template> </data> </odoo>
  • 3. 4。設定檔案:__manifest__.py 把會用到的程式檔配置好 # -*- coding: utf-8 -*- { 'name': "tennen100", 'category': 'Uncategorized', 'version': '0.1', 'depends': ['base','web'], 'data': [ 'views/tree_view_asset.xml', 'views/views.xml', ], 'qweb': ['static/src/xml/tree_view_button.xml'], ], }