Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Filter field domain one2many to many2one

Subscriure's

Get notified when there's activity on this post

This question has been flagged
pythonpython2.7odooodoo10
1 Respondre
10298 Vistes
Avatar
Fazryan Fareka Riznendi

Hiiii...

I have a one2many field which contains 3 fields with 2 different values, for example. Here let's say the Zone is a one2many field.

Query;

Zone A = Car = 3000, Bike = 2000.
Zone B = Car = 2500, Bike = 1500.
Zone C = Car = 2000, Bike = 1000.

and I have many2one fields for the chosen field later (Ex. Car and Bike)

and rate_fields as trigger fields for calculations(a place to store value later)

the point is I want to select the "A" zone, then I select "Car" in many2one fields

the output at the rate field is 3000,

and if I select zone "B" then select "Bike" the output at the rate field is 1500

if written with code, then the implementation uses filter by domain with domain syntax Multiple Conditions.

Can anyone help me to make an example code?

maybe this is a reference but I can't make the appropriate code

Multiple Conditions

In Programming

if a = 5 or (b != 10 and c = 12)

In Open ERP domain filter

['|',('a','=',5),('&',('b','!=',10),('c','=',12))]

https://stackoverflow.com/a/19070664/9228786

Thank you in advance!! :D

0
Avatar
Descartar
Avatar
La Jayuhni Yarsyah
Best Answer

Is Your structure like this:

ZOne Table

Zone
A
B
C

Vehicle Table

Vehicle Name
Car
Bike


Rates Table

Zone ID(m2o)Vehiche Type ID (M2o)Rates(monetary/float)
A
Car
3000
A
Bike
2000
B
Car
2500
B
Bike
1500
C
Car
2000
C
Bike
1000

(Constrains between vehicle and zone), no same vehicle on same zone,



Your Transaction Table

zone_id (M2o)Vehicle ID (M2o)Rates(monetary/float)
A
Car
3000                
A
Bike
1500


If the structure that i wrote was right, then you just only set a onchange action on vehicle_id and zone_id in your transaction

@api.onchange('zone_id','vehicle_id')
def onchange_get_rates(self):
    if self.zone_id.id and self.vehicle_id.id:
        # calculate here
        # find in rates table
        rates = self.env['rates.table'].search([('zone_id','=',zone), ('vehicle_type_id','=',vehicle_type_id)])
        self.rates = rates.rates


But..! if "rates table" doesn't had any constrains between vehicle and zone,,
i mean than maybe in same zone has many rates for 1 same vehicle (example: [id:1] Zone A - Car -Rates = 3000, Zone A, [id:2] Zone A - Car - Rates = 3500)
so let the user select the rates based on zone and vehicle type, you must use onchange too,, where change modify fields domain, but in this case rates field was many2one

Ex:

Your Transaction Table

zone_id (M2o)Vehicle ID (M2o)Rate ID (m2o)
A
Car
1
A
Bike
2



so return domain change in onchange method

return {
    'domain':{
        'field_name':[(domain,'=',value)]
    }
}

3
Avatar
Descartar
Fazryan Fareka Riznendi
Autor

I will try sir..

Big Thanks for response (Terimakasih banyak) :D

Fazryan Fareka Riznendi
Autor

i get error code ;

File "/home/fazryan/odoo/odoo/modules/registry.py", line 170, in __getitem__

return self.models[model_name]

KeyError: 'rates.table'

and this code that I implemented;

@api.onchange('parking_zone_rate_id','vehicle_typee_id')

def onchange_get_rates(self):

if self.parking_zone_rate_id and self.vehicle_typee_id:

# calculate here

# find in rates table

rates = self.env['rates.table'].search([('parking_zone_rate_id','=','name'), ('name','=','name')])

self.rates = rates.rates

please guide me, what should I do?

La Jayuhni Yarsyah

Usually in python, if that error showed up it caused by you try to call an attribute that not defined in object

And as you need to know that, not all that syntax that i wrote before was correct because i never test the code,, it just only to show you to try the flow/concept,,

It very depends on your model structure

So please understand the concept/sructure and flow,,, not to copy the code that i wrote before

I suggest you to explain your model structure more detail..

In that error message that class model "'rates.table" doesn't not defined...

Regards,

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

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

Registrar-se
Related Posts Respostes Vistes Activitat
[SOLVED] How to Hide or Delete Trash Icon in One2many field Solved
python python2.7 odoo odoo10
Avatar
Avatar
2
d’ag. 25
12870
Filter value 2 field of Many2one
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
5
de set. 20
6922
[Solved] Inherit fields to existing tables Solved
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
4
de gen. 19
10262
How to calculate the value of results in one2many field
python python2.7 odoo odoo10
Avatar
Avatar
1
de gen. 19
7102
Generate XLSX(Excel) report in odoo 10 from custom module?
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
2
de jul. 18
15314
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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