Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Food & Hospitality
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Guest House
    • Distribuidor de bebidas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consulting
    • Accounting Firm
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Trades
    • Handyman
    • Hardware y asistencia informática
    • Solar Energy Systems
    • Zapatero
    • Servicios de limpieza
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Filter field domain one2many to many2one

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
pythonpython2.7odooodoo10
1 Responder
10308 Vistas
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
Mejor respuesta

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,

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
[SOLVED] How to Hide or Delete Trash Icon in One2many field Resuelto
python python2.7 odoo odoo10
Avatar
Avatar
2
ago 25
12878
Filter value 2 field of Many2one
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
5
sept 20
6938
[Solved] Inherit fields to existing tables Resuelto
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
4
ene 19
10280
How to calculate the value of results in one2many field
python python2.7 odoo odoo10
Avatar
Avatar
1
ene 19
7114
Generate XLSX(Excel) report in odoo 10 from custom module?
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
2
jul 18
15324
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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