Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Create e list from records on many2many relational field

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
filtermany2many
1 Atsakyti
7694 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
faOtools
Best Answer

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
Portretas
Atmesti
Paulo Matos
Autorius

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
Autorius

@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!

Registracija
Related Posts Replies Rodiniai Veikla
Remove a value from many2many related field. How to do that? Solved
filter many2many
Portretas
Portretas
Portretas
2
liep. 19
12021
How to Use Domain Filter with Many2Many field
filter domain many2many
Portretas
Portretas
1
rugp. 24
8617
Filter and group_by for many2many fields. How to do that? Solved
filter many2many group_by
Portretas
Portretas
1
vas. 25
21868
cbbbbggf
filter
Portretas
0
lapkr. 25
2
Factura en estado "EN PROCESO DE PAGO"
filter
Portretas
0
lapkr. 25
2
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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