Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

using name_get how to shows two different display values?

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
4 Antworten
55095 Ansichten
Avatar
Prakash

I have two fields related with res.partner.addreess

_name = "contact_details"
_columns = {
        'contact_id': fields.many2one('res.partner.address', 'Contact Name'),
        'contact_address_id': fields.many2one('res.partner.address', 'Contact Address'),
 }

In the contact_details Form:-

Currently display

Contact Name --> Contact Name with address

Contact Address --> Contact Name with address

Actual Requirement

Contact Name --> Contact Name only

Contact Address --> Contact Name with address

Using name_get Is it possible using name_get to show contact Name and Contact Address in Field 1 and field 2 ???

Thanks

0
Avatar
Verwerfen
Niyas Raphy (Walnut Software Solutions)

See: https://www.youtube.com/watch?v=kzgjurEkemI

Sehrish

Hope this will helps: https://www.youtube.com/watch?v=qtoEE6IUZBw

Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Beste Antwort

Hi all,

While the answer from Fabien is technically correct I've noticed something interesting. If you set the context on a field the name_get() function is only changed when you're in edit mode and atleast touched the field ones. If you're not in editable mode or didn't touch the field atleast once the context is not passed along to the name_get() function and thus it shows the default rec_name value. If you pass the context on the menuitem itself it will alter the name_get values as the context is set before the name_get() goes off. 

An example (tested in V12 & V13):

    <record id="your_action" model="ir.actions.act_window">
        <field name="name">Your action</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">res.partner</field>
        <field name="context">{'custom_search': True}</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="your_view_search"/>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click to add a new record.
            </p>
        </field>
    </record>

def name_get(self): result = [] for record in self:
if self.env.context.get('custom_search', False):
# Only goes off when the custom_search is in the context values. result.append((record.id, "{} {}".format(record.name, record.address)))
else:
result.append((record.id, record.name))
return result

Regards,

Yenthe

6
Avatar
Verwerfen
Sugeesh Ps

I have used name_get() function and i could change the default value, But i need this change in only one many2one all the other many2one with the same relation should show the rec_name value. How can i make this possible ?

Nicolas de Moreau

Hi Yenthe, thanks for your answer. Maybe you could consider adding "return result" in the name_get. I know it's obvious but I copy-pasted it and it took me some time finding the error... ;-)

BT-amascherpa

Hi Yenthe, the Fabien solution works fines if you add: options={'always_reload': True} on the field, as stated on his answer. This way it works fine on edit and save mode

Avatar
Fabien Pinckaers (fp)
Beste Antwort

Yes, you must put a context on one of the two fields (in the view or in the field) and develop a name_get on thre res.partner object that returns different values according to the context.

OpenERP has already such an implementation for partners. This should work in your view, for v7:

<field name="contact_id"/>
<field name="contact_address_id" context="{'show_address': 1}" options='{"always_reload": True}'/>
10
Avatar
Verwerfen
omprakash

Hi Fabien Pinckaers , I have doubt regards passing context value in XML file . Can you please explain with example .

Mahmoud

now in odoo 14 it is partner_category_display

and it is not working when you set it to short

Avatar
Abegail Sanchez
Beste Antwort

Hi Fabien,

this helped me, thanks

this was he meant

def name_get(self,cr,uid,ids,context=None):
        if context is None:
            context ={}
        res=[]
        record_name=self.browse(cr,uid,ids,context)
        for object in record_name:

                if object.name
                   if context.get('show_address',False):
                          //name for contact_address_id field

                         res.append((object.id,object.name+object.address))
                  else:
                       //name for contact_id field                     

                      res.append((object.id,object.name))
        return res

0
Avatar
Verwerfen
Avatar
Brodynt IT
Beste Antwort

Hi everyone.
We're facing this issue as well, exactly the same as described by Yenthe, but although I see some comments saying it works, we've not managed to make it work, even playing with the 'always_reload' option. (Odoo 12!)

name_get function does not trigger unless you're in edit mode (talking about m2m and o2m in my case)

Example: wizard.compose.mail has a res.partner many2many field shown as tags to display the recipients of the email. If we search partners by emails in the m2m, it works in edit mode, but after we've selected any record it keeps showing as "Companyname, name". 

Context is properly set in an inherited name_get func, that works in other places, but not here. Always_reload option is also to set to True.

Got any idea?  BT-amascherpa replied saying it worked, but on which version? This used to work for me as well in v8 even without always_reload, but we've not managed to make it work in v12.

Thanks.



0
Avatar
Verwerfen
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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