Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Filter and group_by for many2many fields. How to do that?

Odebírat

Get notified when there's activity on this post

This question has been flagged
filtermany2manygroup_by
1 Odpovědět
21859 Zobrazení
Avatar
Paulo Matos

Hello everyone,

I am trying to create a group for my search view which includes a many2many field.
When I try to load the "group by" option I have created for this many2many field, I get the error:

assert gb_field.store and gb_field.column_type, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True

My many2many field is declared as:
mechanic_ids = fields.Many2many('res.users', relation='timesheet_rel_users', column1='id',column2='name') 

On XML for the search view I have:

The above error is raised when I try to load this specific "group by" option.

Is there any way I can create a "group by" option which includes a many2many field?

Thank you in advance

Best regards

Paulo

0
Avatar
Zrušit
Avatar
faOtools
Nejlepší odpověď

It is not possible to group by many2many field.

In that case the line might be shown on the Odoo interface more than one time, what is not acceptable.

As alternative you can create a many2one field which would compute the 'main' record from many2many. For example, you can group partner by tags, but you can group by some computed 'main tag'.

Besides, search by many2many field would work. An example from res.partner: 

<field name="category_id" string="Tag" filter_domain="[('category_id','ilike', self)]"/>

Also you may generate some custom report for your model, which would join tables in the way you like (SQL statement).

UPDATE

@api.multi
@api.depends('mechanic_ids')
def _compute_mynewfield_id(self):
for record in self:
record.mynewfield_id = record.mechanic_ids and record.mechanic_ids[0] or False


mynewfield_id = fields.Many2one('mechanic_ids', compute=_compute_mynewfield_id, store=True) # it is possible to search only among stored fields

4
Avatar
Zrušit
Paulo Matos
Autor

Hi @Odoo Tools,

Thank you very much once again for your help on my path on learning Odoo development.

I have tried to create a "computed" field for this purpose I was unable to do it.

Can you please help me with a sample code?

My many2many field is declared as:

myfield_ids = fields.Many2many('res.users', relation='timesheet_rel_users', column1='id',column2='name')

I have tried to create a many2one computed field declared as:

mynewfield_id = fields.Many2one('mechanic_ids', compute='_get_values, store=False)

My incomplete function:

@api.one

@api.depends('mechanic_ids')

def _get_values(self):

value = self.mechanic_ids

for record in value:

I am stuck from this point forward.

From here, If I print the "value", I can get the desired value for every and each record, but do not know how to complete the function and pass it to XML view filter.

Thank you once again

Best regards

Paulo

faOtools

see the update

Paulo Matos
Autor

Dear @Odoo Tools,

Thank you very very much once again.

+1000 for you

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!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Remove a value from many2many related field. How to do that? Vyřešeno
filter many2many
Avatar
Avatar
Avatar
2
čvc 19
12014
Create e list from records on many2many relational field Vyřešeno
filter many2many
Avatar
Avatar
1
čvn 19
7680
How to add domain filter & default 'group by 'to the existing field in inherit model
filter group_by odoo16features
Avatar
0
úno 23
3347
Expand "group by" filter by default
filter group_by filtering
Avatar
Avatar
1
srp 21
12288
How to Use Domain Filter with Many2Many field
filter domain many2many
Avatar
Avatar
1
srp 24
8601
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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