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

Odoo v12 Many2one field widgets

Subscribe

Get notified when there's activity on this post

This question has been flagged
formmany2onewidget12.0v12
10209 Views
Avatar
notteccon

Hi!

I want to know how to render a Many2one field like a kanban card, something similar to the   'partners' model 'child_ids' field in 'form' view.





I tried using the very same code but this widget only works in Many2many or One2many fields.


 <field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer, 'default_lang': lang, 'default_user_id': user_id}">
        <kanban>
            <field name="id"/>
            <field name="color"/>
            <field name="name"/>
            <field name="title"/>
            <field name="type"/>
            <field name="email"/>
            <field name="parent_id"/>
            <field name="is_company"/>
            <field name="function"/>
            <field name="phone"/>
            <field name="street"/>
            <field name="street2"/>
            <field name="zip"/>
            <field name="city"/>
            <field name="country_id"/>
            <field name="mobile"/>
            <field name="state_id"/>
            <field name="image_small"/>
            <field name="lang"/>
            <!-- fields in form x2many view to diminish requests -->
            <field name="comment"/>
            <field name="customer"/>
            <field name="display_name"/>
            <field name="supplier"/>
            <templates>
                <t t-name="kanban-box">
                    <t t-set="color" t-value="kanban_color(record.color.raw_value)"/>
                    <div t-att-class="color + (record.title.raw_value == 1 ? ' oe_kanban_color_alert' : '') + ' oe_kanban_global_click'">
                        <div class="o_kanban_image">
                            <img alt="" t-if="record.image_small.raw_value" t-att-src="kanban_image('res.partner', 'image_small', record.id.raw_value)"/>
                            <t t-if="!record.image_small.raw_value">
                                <img alt="Delivery" t-if="record.type.raw_value === 'delivery'" t-att-src="_s + &quot;/base/static/img/truck.png&quot;"/>
                                <img alt="Invoice" t-if="record.type.raw_value === 'invoice'" t-att-src="_s + &quot;/base/static/img/money.png&quot;"/>
                                <t t-if="record.type.raw_value !== 'invoice' &amp;&amp; record.type.raw_value !== 'delivery'">
                                    <img alt="Logo" t-if="record.is_company.raw_value === true" t-att-src="_s + &quot;/base/static/img/company_image.png&quot;"/>
                                    <img alt="Avatar" t-if="record.is_company.raw_value === false" t-att-src="_s + &quot;/base/static/img/avatar.png&quot;"/>
                                </t>
                            </t>
                        </div>
                        <div class="oe_kanban_details">
                            <field name="name"/>
                            <div t-if="record.function.raw_value"><field name="function"/></div>
                            <div t-if="record.email.raw_value"><field name="email" widget="email"/></div>
                            <div t-if="record.type.raw_value != 'contact'">
                                <div>
                                    <field name="zip"/>
                                    <field name="city"/>
                                </div>
                                <field t-if="record.state_id.raw_value" name="state_id"/>
                                <field name="country_id"/>
                            </div>
                            <div t-if="record.phone.raw_value">Phone: <field name="phone" widget="phone"/></div>
                            <div t-if="record.mobile.raw_value">Mobile: <field name="mobile" widget="phone"/></div>
                        </div>
                    </div>
                </t>
            </templates>
        </kanban>
 </field>


I also tried with a new widget extending from FieldMany2One



odoo.define('web_widget_many2one_template', function (require) {
"use strict";

var FieldMany2One = require('web.relational_fields').FieldMany2One;
var fieldRegistry = require('web.field_registry');

var core = require('web.core');
var qweb = core.qweb;

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

var webWidgetMany2oneTemplate = FieldMany2One.extend({
className: 'o_m2o_template',
supportedFieldTypes: ['many2one'],
init: function () {
this._super.apply(this, arguments);
this.rpc_rec = false;
this.readOnlyTemplate = 'many2one_template';

if ( this.nodeOptions.hasOwnProperty('template') && this.nodeOptions.template ) {
this.readOnlyTemplate = this.nodeOptions.template;
}
},
willStart: function () {
var self = this;
var self_qweb = qweb;
var def;
if ( this.hasOwnProperty('value') && this.value.hasOwnProperty('data') && this.value.data.hasOwnProperty('id')) {
var def = this._rpc({
model: this.value.model,
method: 'search_read',
domain: [
['id', '=', this.value.data.id]
],
}).then(function (result) {
if (Array.isArray(result) && result.length > 0) {
self.rpc_rec = result[0];
}
});
}
return $.when(this._super.apply(this, arguments), def);
},
_renderReadonly: function () {
var _this = this;
var self_qweb = qweb;
return $.when(this._super.apply(this, arguments)).then(function () {
var template_render = self_qweb.render(_this.readOnlyTemplate, {record: _this.rpc_rec});
_this.$el.empty().css({"width":"100%"}).append(template_render);
});
},
});

fieldRegistry.add('m2o_template', webWidgetMany2oneTemplate);
return webWidgetMany2oneTemplate;
});


But if the model has 40 many2one fields then there are 40 rpc calls


Thanks.



0
Avatar
Discard
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 create many2one field ??
form many2one
Avatar
Avatar
Avatar
Avatar
4
Jul 23
3112
Odoo 10: How to filter on a Many2one field?
many2one widget
Avatar
Avatar
4
Sep 20
9882
odoo v18, Odoo Many2XAutocomplete Problem: Unable to Retrieve Current Line ID, Only Line Records When Updating Purchase Requisition Lines via RPC
code many2one widget
Avatar
0
Jul 25
1189
Help with customizing Many2one dropdown background color in Odoo
javascript many2one widget
Avatar
0
Apr 25
1598
Display a desired column in a Many2One field Solved
form many2one format
Avatar
Avatar
1
Feb 25
11392
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