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í
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • 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

Many2many field filtering based on selected contact id?

Odebírat

Get notified when there's activity on this post

This question has been flagged
domainmany2manyodoo10
1 Odpovědět
11968 Zobrazení
Avatar
Samo Arko

I'm trying to get projects where the selected contact is the follower. I need it so I can select for which projects I should generate the report. For this I'm using a wizard with a Many2One field for selecting the contact and a Many2many field I want to use for checkboxes in the view.

Is it possible to set a dynamic domain that will filter the Many2many field?

contact_id = fields.Many2one('res.partner', domain="[('customers_tic_id', '!=', False)]")
project_ids = fields.Many2many(comodel_name='project.project',
                                   relation='project_document_wizard_rel',
                                   column1='document_wizard_id',
                                   column2='project_id',
                                   string='Contacts following projects',
                                   domain="[('project_id', 'in', self.followers_search_to_list())]")




def followers_search_to_list(self):
        tmp_list = list()
        followers = self.env['mail.followers'].sudo().search([('partner_id', '=', contact_id.id), ('res_model', '=', 'project.project')])

        for follower in followers:
            tmp_list.append(follower.res_id)

        return tmp_list

So what I'm doing wrong?

0
Avatar
Zrušit
Avatar
Ibrahim Boudmir
Nejlepší odpověď

Hi, 

Your question is : can we set a dynamic domain that will filter M2M field based on Another M2O field? 

Answer : Yes you can. 

First, remove the domain from the M2M declaration. Then add a onchange function like this:

@api.onchange('contact_id')
 _onchange_contact_id(self):
    if self.contact_id:
        domain = [('project_id', 'in', self.followers_search_to_list())]
        return {'domain': {'project_ids': domain}}

Upvote if this helps. If not, you can write back for further analysis.
Regards.
5
Avatar
Zrušit
Samo Arko
Autor

Thanks! I only needed to change 'project_id' to 'id'. And you forgot to say that I needed to add compute='_on_change_contact_id' to M2M field. Is there a way to not show any M2M records until the contact is selected? Now I get all existing projects until I select the contact.

Samo Arko
Autor

I can't click on any of the checkboxes!?

Ibrahim Boudmir

Hi,

1- I did not forget to mention that the field should have compute attribute because simply it should not.

2- Not show M2M record until contact is selected : in onchange_contact_id, i only added the condition where contact is set. In this case, you can add 'else' then apply another domain that suits your need.

3- you can't click on any of the checkboxes because you made the field compute... compute field is readonly. Since that is not what i suggested, remove compute attribute.

but to enlighten you more, even if a field is computed, you can still add records manually by adding the attribute "inverse".

Hope this helps you.

Samo Arko
Autor

yeah I figured that about compute field out, so I removed it and it saves. But the problem that I've got now is when the record is saved and when I open it again (go to a different view and back) there are again displayed all projects. But at least the ones that were selected remain selected.

Vysakh B Thottarath

@Tabla : I also have the same problem while using onchange for domain.You got any other solutions ?

Samo Arko
Autor

You need to specify the problem a bit more. But mostly the solution suggested worked for me. If you created a post with the problem explained and some code then post me the link in the comment.

Yeison X

Hi.

Can I do this with Automated Actions?

I have a many2one field (res.partner) and a many2many field (account.move)

When I select the partner, I want only to show the account move documents related with the partner selected.

I'm wondering if it's possible to achieve this with a automated actions and a python code.

Thanks

ahmadsalih7

Thank you, it works !!

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
Many2many domain works when click search more but wrong values in dropdown
domain many2many
Avatar
0
lis 22
80
[SOLVED] Create rule using many2many - how to? Vyřešeno
domain many2many
Avatar
1
čvn 22
8125
Many2many domain not working Vyřešeno
domain many2many
Avatar
1
čvc 21
3524
Many2many domain not working Vyřešeno
domain many2many
Avatar
Avatar
1
čvc 21
5036
How to Update Many2Many Relation Table Records in Odoo 10 Vyřešeno
many2many odoo10
Avatar
Avatar
2
kvě 17
11863
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