Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita 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
  • Proyectos
  • 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
10346 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.

Registrarse
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
12929
Filter value 2 field of Many2one
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
5
sept 20
6981
[Solved] Inherit fields to existing tables Resuelto
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
4
ene 19
10312
How to calculate the value of results in one2many field
python python2.7 odoo odoo10
Avatar
Avatar
1
ene 19
7131
Generate XLSX(Excel) report in odoo 10 from custom module?
python python2.7 odoo odoo10
Avatar
Avatar
Avatar
2
jul 18
15346
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • 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 estar 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