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

Changing one2many widget to many2many causes error on creation, many2many on 2 models seems to not relate them (all web UI)

Subscribe

Get notified when there's activity on this post

This question has been flagged
1 Reply
4640 Views
Avatar
Roberto Cocchiararo

Hi

First of all, I would like to clarify that I am working with the web interface and not "programing" an instalable module, since I know programing basics, but no python.

My objective is to add functionality to the fleet management module.
I created 2 additional models, "events" and "fleet insurance" (the built in contracts can be used for other objectives, but the actual insurance is managed differently, only 2 companies are used and this allows keeping the vehicles up to date easier).

One is for listing events (name, date, description). Each event can have "x" number of vehicles participating (each vehicle can participate in any number of events, and this is a log).

The other is for registering insurance contracts (number, expiration and company). Each contract can have "y" vehicles associated (but one vehicle can have only 1 fleet insurance contract active).

I then need to extend the fleet.vehicle model, adding a list of all the events where it has participated, and the information of the current insurance contract (it can have only one).

My issues start here.

I first tried using many2many fields. This allowed me to pick vehicles in the events/fleet insurance, or events/fleet insurance from the vehicle form, but changing one entity has no effect on the other.

I then tried with one2many in the vehicles, many2one in events/fleet insurance. Now I could pick correctly from the vehicles, but could only have one on the other models (and it was a selection showing just one field, not all the info). Also, from the events/fleet insurance, the "add new" opened the vehicle creatin form, instead of listing the existing ones.

Finally I went with many2one in vehicles, one2many on the other side. This time the problem was inverted.
Then u tried setting the widget on both ends to "many2many", which seemed to be the answer. Too bad now I can't create new vehicles or events/fleet insurance because I get an " unhashable: list" error.

I tries also having many2many on one end, one2many on the other. Similar error when creating.

Can you helpe fix my issue or instruct on the correct way of achieving my objective, using only the web interface of course?

The XML code i ended up with (with some variations, like read only for the fleet insurance on the vehicle form view) was:

Fleet insurance form view:
<?xml version="1.0"?>
<form>
<group string="Seguro">
<field name="x_compania"/>
<field name="x_numeropoliza"/>
<field name="x_fechavencimiento"/>
</group>
<group string="Asegurados">
<field name="x_vehiculos" nolabel="1" widget="many2many"/>
</group>
</form>

Events form view:
<?xml version="1.0"?>
<form>
<group string="Evento">
<field name="x_nombreevento"/>
<field name="x_fechaevento"/>
</group>
<group string="Descripción">
<field nolabel="1" name="x_descripcion" placeholder="Escriba aquí información del evento"/>
</group>
<group string="Participantes">
<field name="x_vehiculos" nolabel="1" widget="many2many"/>
</group>
</form>

Vehicle form view addition (i tried with and without notebook, but with notebook it looked better):

<notebook>
<page string="Seguro de Flota" attrs="{'invisible': [('x_aseguradoflota','=',False)]}">
<group>
<field name="x_seguroflota" nolabel="1" widget="many2many" readonly="1"/>
</group>
</page>
<page string="Eventos" attrs="{'invisible': [('model_id','=',False)]}">
<group>
<field name="x_eventos" nolabel="1" widget="many2many"/>
</group>
</page>
</notebook>

 

0
Avatar
Discard
Avatar
Roberto Cocchiararo
Author Best Answer

I have been doing more experiments, and i believe now that what i tried was not supported, and that is the reason it failed in the first place :P

In any case, now i have:

Events (one2many) > Vehicles (many2many)

Fleet insurance (one2many) > Vehicles (many2one)

Doing it this way, i can have every vehicle participate in any number of events, and modifying one list, does the same on the other. Only downside is i had to change the form view for the events so that the vehicle list is "readonly", because the "one2many" list widget tries to create a new vehicle instead of picking existing ones.

At the same time, each vehicle can have only one fleet insurance active at any moment, which is good. My only issue is that since i am using just the web interface, and these are all custom models/fields, it seems like only "luck" decides what field is displayed in "vehicles" for the "many2one" field relating to "fleet insurance". This time, it was the policy number (more or less usefull), but i had another case where the "user that created the record" was displayed, which was not good at all.

Can i manage this in any way when i am not defining the model/field in python code? If i where, i could set the "_rec_name" of each custom "many2one" field i needed to display the 2 or 3 fields from the "fleet insurance" model in the "vehicle" form view.

 

 

 

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
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