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
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • 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

Access one2many list in many2one onchange event

Suscribirse

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

Se marcó esta pregunta
ormodooV8
7 Respuestas
13817 Vistas
Avatar
Harald F

i want to acccess a one2many field in the onchange event of the corresponding many2one field.

I have defined 2 Models:

class model_a(osv.osv_memory):
_name = "model.a"
_columns = {'b_ids' : fields.one2many('model.b', 'a_id')}

@api.onchange('b_ids')
def test(self):
print "Onchange Function model.a"
for line in self.b_ids:
print line.field1

class model_b(osv.osv_memory):
_name = "model.b"
_columns = {'a_id' : fields.many2one('model.a'),
'field1' : fields.char('field1')}

@api.onchange('field1', 'a_id')
def test(self):
print "Onchange Function model.b"
for line in self.a_id.b_ids:
print self.a_id
print line.field1

There is a view where you can edit the List:

        <record id="model_a_tree_view" model="ir.ui.view">
<field name="name">model_a_tree_view</field>
<field name="model">model.a</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test">
<group >
<group colspan="4">
<field name="b_ids" widget="one2many_list" colspan="4">
<tree string="b_s" editable="bottom" >
<field name="a_id" invisible="1" />
<field name="field1" />
</tree>
</field>
</group>
</group>
</form>
</field>
</record>

I expected to see all model.b entries in the one2many field b_ids. Instead i get only the current entry.

I could use the onchange funtion of  model.a field b_ids, but i cant see wich line has changed and i would have to revalidate all entries.

Output 1st Element added (the field1 text is still blank):

Onchange Function model.a
Onchange Function model.b
model.a(<openerp.models.NewId object at 0xad20f3ec>,)
False

Output 1st Element added (field1 = Test 1):

Onchange Function model.b
model.a(<openerp.models.NewId object at 0xad21658c>,)
Test 1
Onchange Function model.a
Test 1

Everything works like excpected so far. If i add another element (field1 = Test 2) the onchange function in Model b cant see the first entry:

Onchange Function model.b
model.a(<openerp.models.NewId object at 0xad2298ac>,)
Test 2
Onchange Function model.a
Test 1
Test 2

In the onchange function for model.a self.b_ids is:

b: model.b(<openerp.models.NewId object at 0xad1c73ec>, <openerp.models.NewId object at 0xad1c7b6c>)

in the onchange function for model.b self.a_id.b_ids is:

b: model.b(<openerp.models.NewId object at 0xad1d3b6c>,)

Is it possible to see all entries in the onchange function for field1 or see wich item was modified in the onchange function for a one2many field (including new lines without id)?  

0
Avatar
Descartar
Axel Mendoza

What version of Odoo are you using?

Harald F
Autor

I am using Verison 8.0 cloned today from GitHub Repository, created a new Database and wrote a Demo Module.

Avatar
Serpent Consulting Services Pvt. Ltd.
Mejor respuesta

Hello Harald,

In parameter of "api.onchange", you should pass those fields which you want to access in your onchange method.

It should be as follow:

@api.onchange('field1', 'a_id')
def onchange(self):
print self.a_id
print self.a_id.b_ids

Hope this helps.



0
Avatar
Descartar
Harald F
Autor

I tried you suggestion and edited the original post. Still the same problem :(

Serpent Consulting Services Pvt. Ltd.

Make sure "a_id" has some value.

Harald F
Autor

it has a value, the value(see the edited post) is: model.a(,)

Avatar
Rihene
Mejor respuesta

Hi friend :)

 the onchange() decorator is used to provide new field values: as shown through this example:

@api.onchange('field1', 'field2') # if these fields are changed, call method

def check_change(self):

if self.field1 < self.field2:

self.field3 = True

May this help you.

Here are some useful links:

https://www.odoo.com/fr_FR/forum/help-1/question/odoo-8-api-onchange-example-how-to-copy-field-value-to-other-field-74838

https://www.odoo.com/documentation/8.0/reference/orm.html

Regards.


0
Avatar
Descartar
¿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
Declare onchange method inside old API inherited model
orm odooV8
Avatar
Avatar
Avatar
2
abr 16
7618
how to use ORM methods in odoo v8.0 with efficient? Resuelto
orm odooV8
Avatar
Avatar
Avatar
3
mar 15
5097
Define index in Many2one relationships by default throughout the project?
orm openerp odooV8
Avatar
0
nov 16
4949
when to use name_get() and name_search method and When it get called!??! (V8)
orm methods odooV8
Avatar
Avatar
Avatar
4
ene 16
11175
EAV product attributes
product orm odooV8
Avatar
2
mar 15
5677
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