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

Odoo 16 : can many2many use api depends?

Abonare

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

Această întrebare a fost marcată
many2manymail_threadmessage.subsribe
2 Răspunsuri
2570 Vizualizări
Imagine profil
Dimas Aditya Kristianto

As the title says


I have many2many field 

user_ids = fields.Many2many(
        'res.users', 
        string='Users', 
        store=True, 
        readonly=False,
        compute="_compute_user_ids"
        )

And compute method

    @api.depends('user_ids')
    def _compute_user_ids(self):
        for rec in self:
            user_list = []
            for user in rec.user_ids:
                user_list.append(user.id)
            rec.message_subscribe(partner_ids=user_list)




As you can see, I put the debug in line 2150. But when I change , it's not stuck in the debug


If I use onchange, the debug is triggered. But it will errror because message_subscribe​ cannot use NewID

My goal is to make user_ids field is subscribed to this model. 







0
Imagine profil
Abandonează
Imagine profil
Cybrosys Techno Solutions Pvt.Ltd
Cel mai bun răspuns

Hi,

This issue is because the compute method is typically called when the fields specified in the @api.depends decorator are modified, but not when the computed field itself is modified. For solving this issue we can use inverse metod instead of compute method. The inverse method is called when the computed field is modified, which is what you want in this case.


Use the following code:

user_ids = fields.Many2many(

    'res.users',

    string='Users',

    store=True,

    readonly=False,

    inverse="_inverse_user_ids"

)


def _inverse_user_ids(self):

    for rec in self:

        user_list = rec.user_ids.mapped('partner_id.id')

        rec.message_subscribe(partner_ids=user_list)



Hope it helps.

0
Imagine profil
Abandonează
Dimas Aditya Kristianto
Autor

Wow... I didn't know this method exist. Thank you very much. It works like charm

Dimas Aditya Kristianto
Autor

Somehow I can't debug the method. But fine. I will do trial and error. This is more than enough

Imagine profil
Dishant Mistry
Cel mai bun răspuns

The use of @api.depends('user_ids') in the _compute_user_ids method appears unnecessary and might not be the best approach for the intended functionality. The @api.depends decorator is typically used when the computation depends on the field specified, but in this case, you might want to consider using an @api.onchange method instead. This will trigger the logic when the user_ids field is modified, which seems more appropriate for updating subscriptions.

Here's a revised approach using @api.onchange:

user_ids = fields.Many2many(
    'res.users', 
    string='Users', 
    store=True, 
    readonly=False
)

@api.onchange('user_ids')
def _onchange_user_ids(self):
    for rec in self:
        user_list = [user.id for user in rec.user_ids]
        rec.message_subscribe(partner_ids=user_list)




0
Imagine profil
Abandonează
Dimas Aditya Kristianto
Autor

I got this error when trying your code `psycopg2.ProgrammingError: can't adapt type 'NewId'`

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
ODOO V16 Associate Parts to a Finished Good
many2many
Imagine profil
Imagine profil
1
feb. 24
2942
"mail.thread", "mail.activity.mixin" in an inherited class is throwing an OWL Error
mail_thread
Imagine profil
0
iun. 23
3866
Custom Model Data in Many2many field without storing in Database
many2many
Imagine profil
0
iul. 24
4395
Why a new record is creating when selecting in Many2Many field
many2many
Imagine profil
0
iul. 22
60
How to overwrite field many2many?
many2many
Imagine profil
Imagine profil
1
iul. 22
4062
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