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

Giving value to the selection field

Subscriure's

Get notified when there's activity on this post

This question has been flagged
valuesselectionmany2manyselect
5 Respostes
9166 Vistes
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
Best Answer

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
Best Answer

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
Best Answer

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 Best Answer

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

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
Open record selection form for One2Many-Field on button click Solved
selection many2many ir.actions.act
Avatar
Avatar
1
de nov. 24
3039
LINK A SELECTION FIELD SELECTION LIST WITH VALUES OF MANY2MANY FIELD
selection many2many onchange
Avatar
0
de jul. 20
3925
Create new many2many type field based on selection type field value ?
selection many2many convert
Avatar
0
de juny 19
3894
SELECT QUERY ON SELECTION FIELD
selection sql select
Avatar
0
de des. 16
5301
Dynamic values in Select fields
fields selection dynamic select
Avatar
Avatar
Avatar
2
de nov. 23
5658
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