Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

How to use domains for required fields of many2one when having multiple many2ones?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
domainmany2onemodelsdomain_filterodoo8.0
4 Antwoorden
7503 Weergaven
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys,

I have two different many2one relations. This are the fields that I define in my model:

     _columns = {
        'product_id': fields.many2one('product.product','Product'),
        'car_id': fields.many2one('fleet.vehicle', 'Car'),
        'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account'),
        'analytic_car_account_id': fields.many2one('account.analytic.account', 'Analytic Account 2'),
        'name': fields.text('Description', required=True),
        'quantity': fields.float('Quantity', required=True),
        'uom_id': fields.many2one('product.uom', 'Unit of Measure',required=True),
        'price_unit': fields.float('Unit Price', required=True),
        'price_subtotal': fields.function(_amount_line, string='Sub Total', type="float",digits_compute= dp.get_precision('Account')),
        'car_license_plate': fields.text('Nummerplaat', required=True),
        'car_rent_price': fields.float('Prijs', required=True),
        'car_number_of_units': fields.integer('Aantal'),
    }

As you can see I have multiple fields that are required, since they really need to be filled in. Most of these fields are used in the many2one product_id and four of these fields are for the many2one car_id.
As you can see in the XML view:

 <div attrs="{'invisible': [('recurring_invoices','=',False)]}">
                        <field name="recurring_invoice_line_ids" >
                            <tree string="Account Analytic Lines" editable="bottom">
                                <field name="product_id" on_change="product_id_change(product_id, uom_id, quantity, False, parent.partner_id, False, parent.pricelist_id, parent.company_id)"/>
                                <field name="name"  attrs="{'required':[('product_id', '=', True)]}"/>
                                <field name="quantity" attrs="{'required':[('product_id', '=', True)]}"/>
                                <field name="uom_id" attrs="{'required':[('product_id', '=', True)]}"/>
                                <field name="price_unit" attrs="{'required':[('product_id', '=', True)]}"/>
                                <field name="price_subtotal"/>
                            </tree>
                        </field>
                        <field name="recurring_invoice_car_line_ids">
				<tree string="Account Analytic Lines" editable="bottom">
					<field name="car_id" on_change="car_id_change(car_id, car_license_plate, car_rent_price)"/>
					<field name="car_license_plate" attrs="{'required':[('car_id', '=', True)]}"/>
					<field name="car_rent_price" attrs="{'required':[('car_id', '=', True)]}"/>
					<field name="car_number_of_units" attrs="{'required':[('car_id', '=', True)]}"/>
				</tree>
			</field> 
</div>

My question is now how can I guarantee that the fields must be filled in, depending on the requirements?
All the samples:
A user wants to add one product to the many2one product_id but nothing to car_id. 
=> Only the fields for the many2one product are required (as specified in the model).
A user wants to add one car to the many2one car_id but nothing to product_id
=> Only the fields for the many2one car_id are required (as specified in the model).
A user wants to add both product(s) and car(s) to both many2one relations  (as specified in the model).
=> All fields on the many2one product_id should be filled in and all fields on the many2one car_id should be filled in.

How exactly should I do this? I know I need domains but I don't know how to only force the user to fill in fields when something in the many2one is filled in..
I've tried a few ways but I keep getting this dialog


0
Avatar
Annuleer
Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Auteur Beste antwoord

The problem is in the domains logic and where they're applied.
You can make a field in the many2one required by doing something along these lines:

 <field name="recurring_invoice_car_line_ids">
				<tree string="Account Analytic Lines" editable="bottom">
					<field name="car_id" on_change="car_id_change(car_id, car_license_plate, car_rent_price)" attrs="{'required':[('car_id', '!=', '')]}"/>
					<field name="car_license_plate"/> <field name="car_rent_price" attrs="{'required':[('car_id', '!=', '')]}"/>
					<field name="car_number_of_units" attrs="{'required':[('car_id', '!=', '')]}"/>
				</tree>
			</field>
This means you only need to fill in the fields car_number_of_units and car_rent_price when there is an id set in the many2one. If there are no records it is not required. The fields that have no domain are not required to be filled in at any time.

attrs="{'required':[('car_id', '!=', '')]}" 

This statement literally says that the field should only be required when there is some id on the field car_id. When there is nothing it shouldn't be required.

1
Avatar
Annuleer
Avatar
Zbik
Beste antwoord

You replace '==' by '=' and verify solutions again.

1
Avatar
Annuleer
Yenthe Van Ginneken (Mainframe Monkey)
Auteur

Thanks for the reply Zbik! I've changed this but no succes. I've updated my whole question with all the new code but there is still something wrong. Any idea?

Zbik

In _column definition you have many ... required=True, remove them if possible.

Yenthe Van Ginneken (Mainframe Monkey)
Auteur

Since your answer did help me I've upvoted it! I've made an own answer on this topic too with the solution and the explenation. Who knows somebody will need it one day! Thanks Zbik!

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
How to set this specific domain in XML?
domain xml many2one odoo8.0
Avatar
Avatar
3
apr. 15
39864
Dynamic domain depending on user selection Opgelost
partner domain many2one domain_filter relation
Avatar
Avatar
Avatar
3
sep. 23
9722
How can i use a field from 3th model for Domain ?
domain many2one domain_filter odoo v15
Avatar
0
mrt. 23
2419
Many2one Domain (Filter by user security groups)
security domain many2one domain_filter domains
Avatar
0
aug. 16
4923
How to fill up Many2Many after user took an option from a selection? Opgelost
domain many2one selection many2many odoo8.0
Avatar
Avatar
1
mrt. 15
18883
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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