Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

how open custom type view from kanban and tree when click on record?

Subscribe

Get notified when there's activity on this post

This question has been flagged
actiontreeviewxmlkanbanodoo12
8 Replies
13353 Views
Avatar
Mark Okolov

hi all

a created a custom type view, for example 'form2'

created action when i add this type view without 'form'

in this case when click on any record do nothing

if add 'form' type into action, opening record in form view

how i can open my custom type view 'form2' from tree or kanban when i click on any record?

1
Avatar
Discard
Avatar
Ravi Gadhia
Best Answer

when you click on the list view record it triggers up 'open_record' and it bubbles up to an abstract controller.
it always open default from view as it's hardcoded. 
https://github.com/odoo/odoo/blob/12.0/addons/web/static/src/js/views/abstract_controller.js#L460
override you _onOpenRecord controller and switch to your view from(2)
and same for the kanban record

2
Avatar
Discard
Mark Okolov
Author

i created new file and included AbstractController, when check if in context available view_type:

src/custom_module/static/src/js/abstract_controller.js

odoo.define('custom_module.AbstractController', function (require) {

"use strict";

var AbstractController = require('web.AbstractController');

AbstractController.include({

_onOpenRecord: function (event, params) {

event.stopPropagation();

var record = this.model.get(event.data.id, {raw: true});

var view_type = 'form'

if (this.initialState.context.view_type) {

view_type = this.initialState.context.view_type

}

this.trigger_up('switch_view', {

view_type: view_type,

res_id: record.res_id,

mode: event.data.mode || 'readonly',

model: this.modelName,

});

},

});

});

and add context in my action when i need other type view instead form

src/custom_module/views/model_views.xml

<record id="action_view_id" model="ir.actions.act_window">

<field name="name">any name</field>

<field name="res_model">model</field>

<field name="context">{'view_type': 'form2'}</field>

<field name="view_ids"

eval="[(5, 0, 0),

(0, 0, {'view_mode': 'kanban'}),

(0, 0, {'view_mode': 'tree'}),

(0, 0, {'view_mode': 'form2', 'view_id': ref('custom_view_id_form2')}),

(0, 0, {'view_mode': 'calendar'}),

(0, 0, {'view_mode': 'pivot'}),

(0, 0, {'view_mode': 'graph'}),

(0, 0, {'view_mode': 'activity'})]"/>

</record>

and added a new js file to assets.xml

Avatar
Jake Robinson
Best Answer

Hi Mark,

In the action, rather than just defining the view_mode, you should define view_ids. This allows you to specify the view to be used for each mode if you wish. Some can be defined while others can be blank, which will use the default.

<record id="action_res_company" model="ir.actions.act_window">
<field name="name">Company Test</field>
<field name="res_model">res.company</field>
<field name="view_mode">tree,form</field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree'}),
(0, 0, {'view_mode': 'form', 'view_id': ref('test.res_company_form2_view')})]"/>
</record>

Cheers
Jake Robinson

2
Avatar
Discard
Mark Okolov
Author

hi Jake, my view has type 'form2':

(0, 0, {'view_mode': 'form2', 'view_id': ref('test.res_company_form2_view')})]

if write

[(5, 0, 0),

(0, 0, {'view_mode': 'tree'}),

(0, 0, {'view_mode': 'form2', 'view_id': ref('test.res_company_form2_view')})]

from tree when click on any record - do nothing

Jake Robinson

Is there a reason for this? I don't think form2 is a valid view mode and I've never seen it used before. Have you tried changing it just to form?

Mark Okolov
Author

i using created custom type view because the customer does not fit the current version form, it has other styles and there are no buttons to create and edit, if open this new custom form from any button that calling view, all correct working, but i need also open form2 from kanban and tree

Mark Okolov
Author

By the way, in your version you can not write this line

<field name="view_mode">tree,form</field>

because the next line

(5, 0, 0)

will delete all values ​​anyway

Jake Robinson

Sorry, I thought you meant you have just created a new view, I didn't realised you'd created a new type. You'll need to dig around the javascript, it will explicitly call the form view mode on click.

From a quick glance, clicking a kanban calls trigger_up('openRecord') which I think ends up calling odoo/addons/web/static/src/js/views/abstract_controller.js _onOpenRecord() but I can't be sure.

These are two separate fields and conventionally Odoo always defines both.

Mark Okolov
Author

okay, thank you, I dig in there in the morning.

i testing this with and without <field name="view_mode">tree,form</field>, and both variants are working.

if i correct understood this line are equal to

<field name="view_ids" eval="[(0, 0, {'view_mode': 'tree'}),

(0, 0, {'view_mode': 'form'})"/>

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
how to make kanban view display no record until the user search ?
action views action.rule kanban odoo12
Avatar
0
Jun 20
3646
how to get current value of a record line in a XML tree view
action module treeview xml odoov11
Avatar
1
Oct 18
8597
Element cannot be located in parent view
xml odoo12
Avatar
0
Feb 22
2536
Odoo 12 Action Menu
action odoo12
Avatar
Avatar
1
Oct 19
6761
AssertionError: Element data has extra content: record, line 3 Solved
xml odoo12
Avatar
Avatar
Avatar
6
Aug 19
11154
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now