SlideShare a Scribd company logo
2
Most read
4
Most read
6
Most read
How to add Many2Many
fields in odoo website form
Enterprise
Introduction
Enterprise
This feature dynamically links various pieces of data, creating
complex relationships between records. Users can enjoy a more
personalized and engaging experience on your website. For
instance, when a user interacts with one record, related records
are automatically shown.
Many2Many Field
Enterprise
This type of field is used to create bidirectional multiple
relationships between two different models. It can generate a
table that connects two models. Any record on one side of this
table can access multiple records on the other side.
Code
Enterprise
Create a custom model called custom_field, and along with it, develop a
controller and a static file to integrate a JavaScript function. Additionally, set
up a view to handle XML files.
<template id="many2many" inherit_id="portal.portal_my_details_fields">
<xpath expr="//input[@name='vat']/.." position="after">
<lable>Tags</lable>
<select class="js-example-basic-multiple col-xl-6 mb-1
new-get_data" multiple="multiple">
<t t-foreach="tags" t-as="tag">
<option t-att-value="tag" t-esc="tag.name"/>
</t></select>
</xpath>
</template>
Explanation
Enterprise
● This XML template customizes an existing view by extending
it with new elements.
● It uses the inherit_id attribute to specify that it is modifying
the portal_my_details_fields template.
● Within this template, it employs XPath.
● The dropdown, with the class js-example-basic-multiple, is
populated with options derived from a tags list, where each
option corresponds to a tag's name.
Code
Enterprise
Extending the default website portal form view to include our custom "tags"
field.
var CustomForm = publicWidget.Widget.extend({
selector: '.new-get_data',
start: function () {
$('.js-example-basic-multiple').select2();
}
});
publicWidget.registry.Many2many_tag = CustomForm;
return CustomForm;
Explanation
Enterprise
● This defines a custom widget named CustomForm by
extending the publicWidget.Widget class.
● When the widget is initialized, it executes the start function,
which applies the select2 plugin to elements with the class .js-
example-basic-multiple, enhancing them with additional
functionality for selecting multiple options.
● The custom widget is then registered in the
publicWidget.registry under the name Many2many_tag,
making it accessible for use within the application.
Many2many Field
Enterprise
Code
Enterprise
To fetch values from the backend, we import the Customer Portal and
override the account function.
from odoo.addons.portal.controllers.portal import CustomerPortal
from odoo.http import request, route
class CustomerPortal(CustomerPortal):
@route()
def account(self, redirect=None, **post):
res = super(CustomerPortal, self).account(self, **post)
values = self._prepare_portal_layout_values()
…..
Explanation
Enterprise
● Defines a new class CustomerPortal that inherits from the
imported CustomerPortal.
● Within this class, the account method is overridden.
● The method first calls the original account method from the
parent class using super(), and then updates the values
variable by calling _prepare_portal_layout_values() to prepare
layout-related data.
● The updated values can be used for rendering or processing
within the custom account method.
Code
Enterprise
The tags = request.env['crm.tag'] sets up a variable called "tags" and assigns it
the result of crm.tag.search([]), which retrieves all tags from the "crm.tag"
model.
tags = request.env['crm.tag'].sudo().search([])
values.update({
'partner': partner,
'countries': countries,
'states': states,
'tags': tags,
'has_check_vat': hasattr(request.env['res.partner'], 'check_vat'),
'partner_can_edit_vat': partner.can_edit_vat(),
'redirect': redirect,
'page_name': 'my_details',
})
Explanation
Enterprise
● Assign all records from the crm.tag model to the tags variable
using the search method.
● Updates a dictionary named values with several key-value
pairs.
● These include information about the partner, countries,
states, and the previously fetched tags.
● It also includes whether the partner can edit VAT, a redirect
URL, and sets the page name to 'my_details'.
Many2many Field
Enterprise
Enterprise
Conclusion
Hence this is how one can add Many2Many fields in odoo website
form .
For More Info.
Check our company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

More Related Content

PPTX
Pet-Friendly Policies | Pet-Friendly Hotels Guide
PDF
57804336 tax1-dimaampao-lecture-notes
PPT
Cbec - GST - Registration Application cancellation by tax payer and tax official
PPTX
Many2Many in Odoo 16
PPTX
How to Define Many2many Field in Odoo 15
PPTX
Relations Between Models-many2many
PPTX
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
PPTX
Many2One Fields in Odoo 16
Pet-Friendly Policies | Pet-Friendly Hotels Guide
57804336 tax1-dimaampao-lecture-notes
Cbec - GST - Registration Application cancellation by tax payer and tax official
Many2Many in Odoo 16
How to Define Many2many Field in Odoo 15
Relations Between Models-many2many
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
Many2One Fields in Odoo 16

Similar to How to add Many2Many fields in odoo website form.pptx (20)

PPTX
Develop an App with the Odoo Framework.pptx
PPTX
How to Convert Many2One Field into Selection field In Odoo 17
PPTX
How to Add a many2many Relational Field in Odoo 17
PPTX
What are the Basic Fields in the Odoo 17 ERP
PDF
Odoo Technical Concepts Summary
PPTX
How to Define Many2one Field in Odoo 15
PDF
How to customize views & menues of OpenERP online in a sustainable way. Frede...
PDF
Howtocustomizeviewsmenuesofopenerponlineinasustainablewayfredericgilson 13070...
PPTX
What is Property Fields in Odoo 17 ERP Module
PPTX
How to Set Up a One-to-Many Relationship Between Two Models in Odoo 17
PPTX
Relations Between Models - many2one
PPTX
Model Attribute Check Company Auto Property
PPTX
How To Update One2many Field From OnChange of Field in Odoo 17
PPTX
View Inheritance in Odoo 16
PPTX
HOW TO CREATE A MODULE IN ODOO
PPTX
How to Define One2Many Field in Odoo 15
PPTX
How to Empty a Many2Many Field in Odoo 17
PPTX
Dynamically Generate a CRUD Admin Panel with Java Annotations
PDF
PPT. Introduction & Views - Documentation.pdf
PPTX
Field Parameters in Odoo 18 - Odoo 18 Slides
Develop an App with the Odoo Framework.pptx
How to Convert Many2One Field into Selection field In Odoo 17
How to Add a many2many Relational Field in Odoo 17
What are the Basic Fields in the Odoo 17 ERP
Odoo Technical Concepts Summary
How to Define Many2one Field in Odoo 15
How to customize views & menues of OpenERP online in a sustainable way. Frede...
Howtocustomizeviewsmenuesofopenerponlineinasustainablewayfredericgilson 13070...
What is Property Fields in Odoo 17 ERP Module
How to Set Up a One-to-Many Relationship Between Two Models in Odoo 17
Relations Between Models - many2one
Model Attribute Check Company Auto Property
How To Update One2many Field From OnChange of Field in Odoo 17
View Inheritance in Odoo 16
HOW TO CREATE A MODULE IN ODOO
How to Define One2Many Field in Odoo 15
How to Empty a Many2Many Field in Odoo 17
Dynamically Generate a CRUD Admin Panel with Java Annotations
PPT. Introduction & Views - Documentation.pdf
Field Parameters in Odoo 18 - Odoo 18 Slides
Ad

More from Celine George (20)

PPTX
How to Implement OWL Notification Service in Odoo 18
PPTX
Tracking Profit Margins in Sales Orders with Odoo 18
PPTX
How to Configure Outgoing Shipment in 3 Steps Using Odoo 18
PPTX
How to Configure Outgoing Shipment in 1 Step Using Odoo 18.pptx
PPTX
How to Configure Outgoing Shipment in 2 Steps Using Odoo 18
PPTX
How to Add New Applicants in Odoo 18 Recruitment
PPTX
How to Analyze the Recruitment Process in Odoo 18 Recruitment
PPTX
How to Manage Referral Reporting in Odoo 18 Referrals
PPTX
How to Set, Track, & Review Employee Goals in Odoo 18 Appraisals
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PPTX
How to Manage Bill Control Policy in Odoo 18
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PPTX
Odoo 18 Sales_ Managing Quotation Validity
PPTX
How to Manage Global Discount in Odoo 18 POS
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
How to Implement OWL Notification Service in Odoo 18
Tracking Profit Margins in Sales Orders with Odoo 18
How to Configure Outgoing Shipment in 3 Steps Using Odoo 18
How to Configure Outgoing Shipment in 1 Step Using Odoo 18.pptx
How to Configure Outgoing Shipment in 2 Steps Using Odoo 18
How to Add New Applicants in Odoo 18 Recruitment
How to Analyze the Recruitment Process in Odoo 18 Recruitment
How to Manage Referral Reporting in Odoo 18 Referrals
How to Set, Track, & Review Employee Goals in Odoo 18 Appraisals
Revamp in MTO Odoo 18 Inventory - Odoo Slides
How to Manage Starshipit in Odoo 18 - Odoo Slides
How to Manage Bill Control Policy in Odoo 18
How to Manage Loyalty Points in Odoo 18 Sales
Odoo 18 Sales_ Managing Quotation Validity
How to Manage Global Discount in Odoo 18 POS
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Tips Management in Odoo 18 POS - Odoo Slides
How to Close Subscription in Odoo 18 - Odoo Slides
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
How to Track Skills & Contracts Using Odoo 18 Employee
Ad

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Computing-Curriculum for Schools in Ghana
PPTX
GDM (1) (1).pptx small presentation for students
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
master seminar digital applications in india
PPTX
Cell Structure & Organelles in detailed.
PDF
RMMM.pdf make it easy to upload and study
PPTX
Lesson notes of climatology university.
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
Renaissance Architecture: A Journey from Faith to Humanism
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O5-L3 Freight Transport Ops (International) V1.pdf
Basic Mud Logging Guide for educational purpose
01-Introduction-to-Information-Management.pdf
PPH.pptx obstetrics and gynecology in nursing
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Computing-Curriculum for Schools in Ghana
GDM (1) (1).pptx small presentation for students
STATICS OF THE RIGID BODIES Hibbelers.pdf
master seminar digital applications in india
Cell Structure & Organelles in detailed.
RMMM.pdf make it easy to upload and study
Lesson notes of climatology university.
Pharma ospi slides which help in ospi learning
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Anesthesia in Laparoscopic Surgery in India

How to add Many2Many fields in odoo website form.pptx

  • 1. How to add Many2Many fields in odoo website form Enterprise
  • 2. Introduction Enterprise This feature dynamically links various pieces of data, creating complex relationships between records. Users can enjoy a more personalized and engaging experience on your website. For instance, when a user interacts with one record, related records are automatically shown.
  • 3. Many2Many Field Enterprise This type of field is used to create bidirectional multiple relationships between two different models. It can generate a table that connects two models. Any record on one side of this table can access multiple records on the other side.
  • 4. Code Enterprise Create a custom model called custom_field, and along with it, develop a controller and a static file to integrate a JavaScript function. Additionally, set up a view to handle XML files. <template id="many2many" inherit_id="portal.portal_my_details_fields"> <xpath expr="//input[@name='vat']/.." position="after"> <lable>Tags</lable> <select class="js-example-basic-multiple col-xl-6 mb-1 new-get_data" multiple="multiple"> <t t-foreach="tags" t-as="tag"> <option t-att-value="tag" t-esc="tag.name"/> </t></select> </xpath> </template>
  • 5. Explanation Enterprise ● This XML template customizes an existing view by extending it with new elements. ● It uses the inherit_id attribute to specify that it is modifying the portal_my_details_fields template. ● Within this template, it employs XPath. ● The dropdown, with the class js-example-basic-multiple, is populated with options derived from a tags list, where each option corresponds to a tag's name.
  • 6. Code Enterprise Extending the default website portal form view to include our custom "tags" field. var CustomForm = publicWidget.Widget.extend({ selector: '.new-get_data', start: function () { $('.js-example-basic-multiple').select2(); } }); publicWidget.registry.Many2many_tag = CustomForm; return CustomForm;
  • 7. Explanation Enterprise ● This defines a custom widget named CustomForm by extending the publicWidget.Widget class. ● When the widget is initialized, it executes the start function, which applies the select2 plugin to elements with the class .js- example-basic-multiple, enhancing them with additional functionality for selecting multiple options. ● The custom widget is then registered in the publicWidget.registry under the name Many2many_tag, making it accessible for use within the application.
  • 9. Code Enterprise To fetch values from the backend, we import the Customer Portal and override the account function. from odoo.addons.portal.controllers.portal import CustomerPortal from odoo.http import request, route class CustomerPortal(CustomerPortal): @route() def account(self, redirect=None, **post): res = super(CustomerPortal, self).account(self, **post) values = self._prepare_portal_layout_values() …..
  • 10. Explanation Enterprise ● Defines a new class CustomerPortal that inherits from the imported CustomerPortal. ● Within this class, the account method is overridden. ● The method first calls the original account method from the parent class using super(), and then updates the values variable by calling _prepare_portal_layout_values() to prepare layout-related data. ● The updated values can be used for rendering or processing within the custom account method.
  • 11. Code Enterprise The tags = request.env['crm.tag'] sets up a variable called "tags" and assigns it the result of crm.tag.search([]), which retrieves all tags from the "crm.tag" model. tags = request.env['crm.tag'].sudo().search([]) values.update({ 'partner': partner, 'countries': countries, 'states': states, 'tags': tags, 'has_check_vat': hasattr(request.env['res.partner'], 'check_vat'), 'partner_can_edit_vat': partner.can_edit_vat(), 'redirect': redirect, 'page_name': 'my_details', })
  • 12. Explanation Enterprise ● Assign all records from the crm.tag model to the tags variable using the search method. ● Updates a dictionary named values with several key-value pairs. ● These include information about the partner, countries, states, and the previously fetched tags. ● It also includes whether the partner can edit VAT, a redirect URL, and sets the page name to 'my_details'.
  • 14. Enterprise Conclusion Hence this is how one can add Many2Many fields in odoo website form .
  • 15. For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com