Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Create e list from records on many2many relational field

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
filtermany2many
1 Răspunde
7691 Vizualizări
Imagine profil
Paulo Matos

Good day everyone,
I am working on a report for Odoo v12.
I have a related many2many field on my model, which collects information from res.users.
When I browse and print records from this field, i get results like:

[[res.users(2,)]]
[[res.users(39,)]]
[[res.users(2,37,)]]
[[res.users(37,39)]]
[[res.users(37,7,2)]]
[[res.users(39,7)]]

From the list above, I can see that I have several duplicated values which is expactable and are correct.
Everytime I try to use the append() method on the loop, all new records are replacing the old ones, but I am sure I am not using it correctly.

My problems:
1. I need to browse through the records and collect all values, creating a new list and remove all duplicates.
2. After that, I will need to browse through the list and compare with the record on the relational field (for instance [[res.users(37,39)]]) and check if any of the list values exists on the relational field.
Doing that, I will be able to process my report, since it is sorted by users on "res.users".

How can I achieve that?

Thank you all once again in advance

Best regards

Paulo

0
Imagine profil
Abandonează
Imagine profil
faOtools
Cel mai bun răspuns

Odoo let you work directly with recordsets (extend, union, intersect, difference), so my suggestion is to avoid browsing over your many2many lists. Let me make a few assumptions to make clear examples:

  • You have 'records' over you iterate

  • Each record has 'user_ids' field (res.users, many2many)

  • You want to compare aggregation of those users to another  field (let assume 'mymodel.user_ids', also res.users, many2many).

Then, to aggregate all users over all records into a single recordset you need just:

final_user_ids = records.mapped("user_ids")

It will return res.users(2,7,37,39,) - so, a recordset without duplicates.

Then, you can simply compare this set to your custom field set as:

intersected_user_ids = final_user_ids & mymodel.user_ids

It will return all the elements which are in both recordsets. To check whether it is empty:

if intersected_user_ids:
print ("The same users", intersected_user_ids)
# >> res.users(2,7)

So, the goal is achieved in 4 lines. 




1
Imagine profil
Abandonează
Paulo Matos
Autor

Dear @Odoo Tools,

Thank you very much for your help.

Using your approach I have successfully reached my initial goal.

With it, I have browsed to all records and finished my report for all users.

Now for the part: intersected_user_ids = final_user_ids & mymodel.user_ids

I am not comparing to a model recordset.

I am trying to compare with a variable and try to see if "variable_value is in final_user_ids" but I am unable to do it.

So, until now I have (based on you example):

my_recordset : which contains all records to be filtered and shown on report, based on final_user_ids

final_user_ids : which lists all desired users from my recordset with no duplicates;

report data : I have successfully browsed from all desired records on my_recordset and collect data for every record on final_user_ids.

At this stage I am able to print the report for all users, but I am unable to filter the records on final_user_ids based on a variable in order to collect the data just for that particular user.

PS: I will mark your answer as correct because it is correct and working as expected.

Thank you once again

Best regards

Paulo

faOtools

In order to check whether a specific user is inside a recordset you can check "if user_id in final_user_ids". If user_id is an ID - integer (not record) then "if user_id in final_user_ids.ids". If you rely upon a current user (who prints): "if self.env.user in final_user_ids"

Paulo Matos
Autor

@Odoo Tools,

Thank you very much once again.

The problem was on "if user_id in final_user_ids.ids". I was using "final_user_ids.ID" instead of "final_user_ids.IDS"

Best regards

Paulo

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Remove a value from many2many related field. How to do that? Rezolvat
filter many2many
Imagine profil
Imagine profil
Imagine profil
2
iul. 19
12021
How to Use Domain Filter with Many2Many field
filter domain many2many
Imagine profil
Imagine profil
1
aug. 24
8617
Filter and group_by for many2many fields. How to do that? Rezolvat
filter many2many group_by
Imagine profil
Imagine profil
1
feb. 25
21868
cbbbbggf
filter
Imagine profil
0
nov. 25
2
Factura en estado "EN PROCESO DE PAGO"
filter
Imagine profil
0
nov. 25
2
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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