Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Set domain for one2Many for different views in Odoo12

Subscriure's

Get notified when there's activity on this post

This question has been flagged
odoo12
14 Respostes
9075 Vistes
Avatar
Bruce Rochester

I've added a new partner type:

type = fields.Selection(selection_add=[('service', 'Service address')])  

I would like to hide this new partner type from the "Contacts & Addresses" one2Many on the res.partner form, using the following XML:

<xpath expr="//field[@name='child_ids']" position="attributes"><attribute name="domain">[('active', '=', True), ('type', '!=', 'service')]</attribute>            </xpath> 

In debug mode, I can see the domain has been updated on the form, but it is still showing all records here. I've even tried the domain [('id', '=', False)], but all records are still showing.

Anyone know what's going on here?

As Zbik helpfully pointed out below, domain can not be set through XML for a one2Many. How can I create two different one2Many fields in different views that show a different subset of the list items?

0
Avatar
Descartar
Sehrish

Use Context: https://goo.gl/XXg5D3

Avatar
Bruce Rochester
Autor Best Answer

Turns out this is apparently a lot more complicated than it should be. My workaround was to create 2 computed one2many fields. One for service addresses and one for other addresses.

    service_addresses = fields.One2many(
        'res.partner', string="Service Addresses",
        compute='_compute_address_types'
        )
    other_addresses = fields.One2many(
        'res.partner', string="Contacts & Addresses",
        compute='_compute_address_types'
        )

    @api.depends('child_ids')
    def _compute_address_types(self):
        for res in self:
            service_addresses = res.child_ids.filtered(lambda x: x.type == 'service')
            other_addresses = res.child_ids.filtered(lambda x: x.type != 'service')
            res.service_addresses = [(6, 0, [x.id for x in service_addresses])]
            res.other_addresses = [(6, 0, [x.id for x in other_addresses])] 

I replaced the one2many on the partner form with other_addresses, and service_addresses on a separate tab.

Of course, these computed fields then didn't have an add button, so I also added child_ids one2many below each of them with a blank kanban template, so the kanban list doesn't show up, only the "ADD" button.

Clunky, but seems to work.


0
Avatar
Descartar
Avatar
Zbik
Best Answer

One2many domain not works in XML. Try it in python code.

1
Avatar
Descartar
Bruce Rochester
Autor

Thanks, the service addresses no longer show up, but this now seems entirely pointless - service addresses will never show up in ANY view if I can't change the domain per view.

Bruce Rochester
Autor

Is it not possible to create 1 one2Many field, then have 2 different views that show a different subset of the list?

Zbik

You can have many views depending on the permissions or the action being called.

Bruce Rochester
Autor

I understand I can have many views, but the domain will always be the same because I can't set it in the XML. I have set the domain in Python:

child_ids = fields.One2many('res.partner', 'parent_id', string='Contacts', domain=[('type', '!=', 'service')])

Now, any time I display that One2many field it will not show the service addresses.

I would like 1 view to have the domain: [('type', '!=', 'service')] and the other one with domain [('type', '=', 'service')]...

Zbik

Maybe build an additional computed domain control field?

Bruce Rochester
Autor

Thanks, but I'm not quite sure I understand. I've tried assigning the domain using a lambda function, which seems to work but I'm not sure how to determine which view is triggering the function.

child_ids = fields.One2many('res.partner', 'parent_id', string='Contacts', domain=lambda x: x._get_contacts_domain())

def _get_contacts_domain(self):

print("debug")

print(self)

return [('type', '!=', 'service')]

I put a breakpoint on the print lines, and there is nothing I can see in the context that tells me which view is requesting the domain. Is there some other variable I should be looking at?

Zbik

You pass a context from views ==> view set a context and domain get it ==> self._context.get('xxx')

or nwe field is default set from context and domain use it

Bruce Rochester
Autor

None of the context information is being passed to my _get_contacts_domain function

Zbik

Then modify xml and build this context yourself!

Bruce Rochester
Autor

But the context already exists in the XML! My code:

<field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer, 'default_lang': lang, 'default_user_id': user_id}">

When I load the page, it triggers my function _get_contacts_domain() several times, and the context is never being passed.

Here is all I get when I print self._context from that function:

{'lang': 'en_CA', 'tz': 'Canada/Eastern', 'uid': 2, 'base_model_name': 'res.partner', 'view_is_editable': None}

Zbik

Context defined in XML line child_ids is used when subviews (defined in this line) are prepared to view.

When your view is builded, and when your _get_contacts_domain is called, context is defined and get from parent action.

In your case, probably this is action == 'contacts.action_contacts'

Bruce Rochester
Autor

Helpful, but also raises another issue. If we can't use field-level context, we can't differentiate between the 2 lists if they are on the same view. This should help if I want to include only 1 list per view, but won't allow me to have different domains on the two lists. I've ended up using a work-around since this functionality doesn't seem to exist in Odoo.

Zbik

I really don't understand why you add a new type = "service" if you already have "delivery" and "other"

Bruce Rochester
Autor

Because we have customers with thousands of service addresses that we don't want mixed in with the few other addresses they have.

Bruce Rochester
Autor

And if we use "delivery" or "other" address we still have to deal with the exact same problem. Using a new type of address is NOT the root of the issue.

Zbik

Ok, but the new type will probably create problems for you in many other cases.

Bruce Rochester
Autor

OK thanks for that input. I will make sure to investigate the possible side-effects of using a custom partner type by analyzing the source code. Cheers.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Odoo Mail Sending Limit Solved
odoo12
Avatar
Avatar
Avatar
2
de des. 23
16355
(Document type: Invoice, Operation: write) - (Records: [], User: 2)
odoo12
Avatar
0
d’oct. 23
33
Error while importing data in Odoo12: An unknown issue occurred during import (possibly lost connection, data limit exceeded or memory limits exceeded)
odoo12
Avatar
Avatar
Avatar
Avatar
3
d’oct. 23
790
Remove duplicate record when importing data from excel to Odoo
odoo12
Avatar
Avatar
1
d’oct. 23
569
Multiple group on field Odoo12
odoo12
Avatar
Avatar
1
d’ag. 23
3340
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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