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

How to hide some fields in Form View if no record found in many2many relationship?

Abonare

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

Această întrebare a fost marcată
filterattrsdomainmany2many
7 Răspunsuri
21852 Vizualizări
Imagine profil
Juris Malinens

Basic idea: Hide few fields in client form view for OpenERP users which are not defined as VIP users in my custom many2many table (user_id, partner_id)

What I've already done:

In res.partner form view:

<field name="vip_ids" widget="many2many_tags" placeholder="VIP users..."/>

My custom module which adds many2many relationship for res.partner module:

from openerp.osv import orm, fields
from osv import fields, osv
class res_partner_users_vip_rel2(osv.osv):
    _inherit = 'res.partner'
    _description = "VIP status for partner (users)"
    _columns = {
        'vip_ids': fields.many2many(
            'res.users',
            'res_partner_users_vip_rel2',
            'partner_id',
            'users_id',
            'VIP status'),
    }
res_partner_users_vip_rel2()

In Form View I can successfully save multiple users in newly created field, but I am stuck at hiding other fields for users who are not defined in my many2many relationship.

As I understand, I need to use attrs attribute but I don't understand how to use it with many2many relationship.

This doesn't work:

<field name="mobile" attrs="{'invisible': [('uid','in', vip_ids)]}"/>
<field name="fax" attrs="{'invisible': [('uid','in', vip_ids)]}"/>
<field name="email" widget="email" attrs="{'invisible': [('uid','in', vip_ids)]}"/>

Any advice would be greatly appreciated :)

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

I have try this and working :

       <record id="view_0001" model="ir.ui.view">  
            <field name="name">XXXXXXX</field>
            <field name="model">res.partner</field>
            <field name="arch" type="xml">
                <form string="XXXXXXXXXX" version="7.0">
                    <group col="4" colspan="2">
                        <field name="ids_count"/> 
                        <field name="mobile" attrs="{'invisible': [('ids_count','=', 0)]}"/>
                        <field name="fax" attrs="{'invisible': [('ids_count','=', 0)]}"/>
                        <field name="email" widget="email" attrs="{'invisible': [('ids_count','=',0)]}"/> 
                    </group>
                    <field name="vip_ids"></field>

                </form> 
            </field>
       </record>

with modified model definiton

from openerp.osv import fields, osv
class res_partner_users_vip_rel2(osv.osv):
    _inherit = 'res.partner'
    _description = "VIP status for partner (users)"
    def getcount(self, cr, uid,ids,name,arg,context):
        res={}
        sql="""
            SELECT partner_id id, count(*) cnt FROM res_partner_users_vip_rel2 
            WHERE partner_id = """+str(ids[0])+""" GROUP BY partner_id """
        cr.execute(sql)
        res.update(dict(cr.fetchall()))
        if res!={}:
            return res 
        return {ids[0]:0}
    _columns = {                
        'ids_count':fields.function(getcount,type="integer",string='Count'),

        'vip_ids': fields.many2many(
            'res.users',
            'res_partner_users_vip_rel2',
            'partner_id',
            'users_id',
            'VIP status'),
         }

0
Imagine profil
Abandonează
Juris Malinens
Autor

Thanks, but doesn't seem to work. Field is shown both when user is added in many2many relation and also when he s not

aharoen

I have edited my previous answer, and i have tried. It work.

Juris Malinens
Autor

thank You! Only I added AND users_id= """+str(uid)+""" to the query

Imagine profil
Alf Olsen
Cel mai bun răspuns

You can also just compare to an empty array (I'm using Odoo 11)

<div attrs="{'invisible':[ ('boats', '=', []) ]}">
<label for="boats" class="o_ff_header"/>
<field name="boats"/>
</div>

3
Imagine profil
Abandonează
CARLOS ALBERTO GARCIA BRIZUELA

This way works great for me in Odoo 11, thanks !!

Imagine profil
Yogesh
Cel mai bun răspuns

Hello, 

It could be achieved without function field and only with xml. You can use attrs attribute like

attrs="{'invisible': [('m2m_field', '=', [(6, False, [])])]}"attrs="{'invisible': [('m2m_field', '=', [(6, False, [])])]}" 
            

On webclient m2m field outputs like [(6, False, [list_of_record_ids])], when there is no record list becomes empty and it outputs like [(6, False, [])] . It can be used in xml condition.

0
Imagine profil
Abandonează
Imagine profil
Juris Malinens
Autor Cel mai bun răspuns

Thanks aharoen. Yesteday evening I came up with similar solution:

def _get_active_ids(self, cr, uid, ids, field_name, arg, context=None):
      result = {}
      for clase in self.browse(cr, uid, ids, context=context):
         result[clase.id] = False
         for membre in clase.vip_ids:
            if membre.id == uid:
                result[clase.id] = True
      return result

class res_partner_users_vip_rel2(osv.osv):
    _inherit = 'res.partner'
    _description = "VIP2 status for partner (users)"
    _columns = {
        'vip_ids': fields.many2many(
            'res.users',
            'res_partner_users_vip_rel2',
            'partner_id',
            'users_id',
            'VIP2 status'),
        'is_current_user_vip': fields.function(
            _get_active_ids,
            type='boolean',
            string="Does current user have VIP access?"),
    }

res_partner_users_vip_rel2()
0
Imagine profil
Abandonează
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
What is diff between domain, domain filter and attr ?
filter attrs domain
Imagine profil
1
ian. 24
16021
How to Use Domain Filter with Many2Many field
filter domain many2many
Imagine profil
Imagine profil
1
aug. 24
8597
filter many2many field
filter domain many2many v14
Imagine profil
Imagine profil
1
sept. 23
2990
Fied be Invisible if Many2Many value is selected. Rezolvat
filter domain many2many invisible
Imagine profil
Imagine profil
Imagine profil
7
iun. 20
7635
How to filter Many2Many field containing zero items
filter domain many2many followers
Imagine profil
Imagine profil
2
iul. 17
4098
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