Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Set domain for one2Many for different views in Odoo12

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
odoo12
14 Besvarelser
9078 Visninger
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
Kassér
Sehrish

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

Avatar
Bruce Rochester
Forfatter Bedste svar

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
Kassér
Avatar
Zbik
Bedste svar

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

1
Avatar
Kassér
Bruce Rochester
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Odoo Mail Sending Limit Løst
odoo12
Avatar
Avatar
Avatar
2
dec. 23
16359
(Document type: Invoice, Operation: write) - (Records: [], User: 2)
odoo12
Avatar
0
okt. 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
okt. 23
790
Remove duplicate record when importing data from excel to Odoo
odoo12
Avatar
Avatar
1
okt. 23
569
Multiple group on field Odoo12
odoo12
Avatar
Avatar
1
aug. 23
3341
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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