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

Giving value to the selection field

Suscribirse

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

Se marcó esta pregunta
valuesselectionmany2manyselect
5 Respuestas
9199 Vistas
Avatar
Nazrin Guliyeva

Hey guys,

I am sending a post request to the res.partner model. And I want to give value to category_id which is selection field (many2many). How I can achieve it?

My code is below:

id = models.execute_kw(db, uid, password, 'res.partner', 'create', [{
'name': name, 'x_customer_register_date': my_date, 'x_customer_id': customerId, 'category_id': tags,
'zip': postcode, 'street': address,
}])



0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

Hi,

Follow the below syntax for filling the values to many2many fields.


(0, 0, { values }) link to a new record that needs to be created with the given values dictionary

(1, ID, { values }) update the linked record with id = ID (write values on it)

(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

(4, ID) link to existing record with id = ID (adds a relationship)

(5) unlink all (like using (3,ID) for all linked records)

(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

5
Avatar
Descartar
Avatar
Haresh Kansara
Mejor respuesta

Hi Nazrin,

There are basically two way to add record to many2many field.

1) Add existing created record to many2many field

- Add single record:

tags = [(4, EXISTING_RECORD.id)]

'category_id': tags,

- Add multiple records:

tags = [EXISTING_RECORD1.id, EXISTING_RECORD2.id, EXISTING_RECORD3.id, EXISTING_RECORD4.id, EXISTING_RECORD5.id]

'category_id': [(4, tag, None) for tag in tags]


2) Create new record and add to many2many field


tag_vals = {
'name': "Tag-1",
}

'category_id': [(0, 0, tag_vals)]


For about how to fill value to x2many field: https://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html

I hope it will helpful for you

Thanks and regards
Haresh Kansara

1
Avatar
Descartar
Avatar
shalin wilson
Mejor respuesta

https://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html

1
Avatar
Descartar
shalin wilson

first read the doc and do like eg: 'x_id': [(6, 0, tax_ids)],

Haresh Kansara

6,0 will replace remove existing tags add new added tags. So i suggest to use 4,0 to add

shalin wilson

yeah thanks and i thought the person would go through the link to understand each,else they might ask how to remove on next question and so on

shalin wilson

Many2many fields always have an intermediary table where it's stored the foreign keys of the two tables, the actual were the field is m2m defined and the pointed table of the m2m field. Using that table the records of the other table can be retrieved. The following is a definition of a many2many field with the intermediary table in bold

invoice_line_tax_id = fields.Many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', string='Taxes', domain=[('parent_id', '=', False)])

In the case of the payment_ids of the model account.invoice it's a computed field so the records of the other table are retrieved using a the function _compute_payments of the account.invoice. The computed m2m fields don't have an intermediary table

Avatar
Nazrin Guliyeva
Autor Mejor respuesta

It is string in my variable, like B2B or B2C

and I want to choose accordingly, so in my case the solution above is not working

0
Avatar
Descartar
shalin wilson

many2many field right?

it stores ids in both side so u have to write the ids

shalin wilson

find id of B2B and B2C and store it

Nazrin Guliyeva
Autor

for small stuffs like B2B or B2C i did now like this. But there is one problem now. Now I want to do orders and connect it with customers, there is field which is one2many and I need to choose customer's id. And the number of customers are extremely big. In this case, what should I do?

Nazrin Guliyeva
Autor

many2one sorry

¿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
Open record selection form for One2Many-Field on button click Resuelto
selection many2many ir.actions.act
Avatar
Avatar
1
nov 24
3056
LINK A SELECTION FIELD SELECTION LIST WITH VALUES OF MANY2MANY FIELD
selection many2many onchange
Avatar
0
jul 20
3939
Create new many2many type field based on selection type field value ?
selection many2many convert
Avatar
0
jun 19
3906
SELECT QUERY ON SELECTION FIELD
selection sql select
Avatar
0
dic 16
5343
Dynamic values in Select fields
fields selection dynamic select
Avatar
Avatar
Avatar
2
nov 23
5683
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