Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • e-learning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Cervecería
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y soporte técnico
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Explorar todos los sectores
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Servicios para partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

name get() not working ?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
nameget
10 Respuestas
19770 Vistas
Avatar
omprakash
Hai Friends ,
    First I thank everyone for such good support for newbies . I have Question regards name_get() . This is my sample custom code .Please let me know how to pass value for context (for many2one field i like to display to email instead of title) .

Notebook :
1. __init__.py
   import notebook
2.__openerp__.py
{
    "name" : "notebook",
    "version" : "0.1",
    "author" : "Prakash",
    "website" : "http://www.prakash.com/",
    "category" : "Generic Modules/Others",
    "depends" : ["base"],
    "description" : "Simple demo module",
    "init_xml" : ['notebook_view.xml'],
    "demo_xml" : [],
    "update_xml" : [],
    "active": False,
    "installable": False
}
3.notebook.py
 from osv import fields, osv
 class notebook(osv.osv):
    _name = "notebook"
    _description = "Simple Notebook"
    _rec_name = 'title'
    _columns = {
        'title' : fields.char('Title', size=30, required=True),
        'note' : fields.text('Note'),
        'note_date' : fields.date('Date'),
        'email': fields.char('Email', size=240),
    }
    def name_get(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        res = []
        for record in self.browse(cr, uid, ids, context=context):
            email = record.email
            title = record.title
            if context.get('email'):
                email = "%s <%s>" % (email, record.email)
                return res
            res.append((record.id, title))
        return res

notebook()

 4. notebook_view.xml
    <?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="notebook_tree_view">
            <field name="name">notebook.tree</field>
            <field name="model">notebook</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Notebook">
                    <field name="title"/>
                    <field name="note"/>
                    <field name="note_date"/>
                </tree>
            </field>
        </record>
        <record model="ir.ui.view" id="notebook_form_view">
            <field name="name">notebook.form</field>
            <field name="model">notebook</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Notebook">
                    <field name="title"/>
                    <field name="note"/>
                    <field name="note_date"/>
                    <field name="email"/>
                </form>
            </field>
        </record>
        <record model="ir.actions.act_window" id="action_notebook_form">
            <field name="name">notebook</field>
            <field name="res_model">notebook</field>
        </record>
        <menuitem name="NotebookParent" icon="terp-project" id="NotebookParent_menu"/>
    <menuitem name="NotesChild" parent="NotebookParent_menu" id="NotesChild_menu" />
        <menuitem name="Header" parent="NotesChild_menu" id="Header_menu_mainform" action="action_notebook_form"/>
    </data>
</openerp>



monitor:

1. __init__.py
    import monitor
2. __openerp__.py
{
    "name": "monitor",
    "version": "7.0",
    "depends": ["base"],
    "author": "author",
    "category": "category",
    "description": """
    This module provide : test
    """,
    "init_xml": [],
    'update_xml': [],
    'demo_xml': [],
    'installable': True,
    'active': False,
    "data" : ["monitor_view.xml"]
}
3. monitor.py

  from osv import fields,osv

class monitor(osv.osv):
    _name = 'monitor'
    _columns = {
            'name' : fields.char("name" , size = 10 , required = True),
            'email':fields.many2one('notebook', 'email'),
                    }
monitor()

4.monitor_view.xml
 <?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
               <record model="ir.ui.view" id="monitor_form_view">
                <field name="name">monitor.form</field>
                <field name="model">monitor</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="form_monitor">
                        <field name="name" select="1"/>
                         <field name="email" context="{'email':email}"/>
                    </form>
                </field>
            </record>    

        <act_window name="monitor"
            res_model="monitor"
            src_model="monitor"
            id="monitor_id"/>
    <menuitem id="one_id" name="one" />
    <menuitem id="two_id" name="two" parent="one_id" />
    <menuitem id="three_id" name="three" parent="two_id" action="monitor_id"/>
    </data>
</openerp>

Actually I like to display email instead of title (many2one) , but still it getting title as display for many2one . I don't know how to pass value for context .Please help me to move further . And once again i thank everyone .
1
Avatar
Descartar
Avatar
ClueLogics Technologies Pvt. Ltd.
Mejor respuesta

your method should be

   def name_get(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    res = []
    for record in self.browse(cr, uid, ids, context=context):
        email = record.email
        title = record.title
        tit = "%s <%s>" % (title, record.email)
        res.append((record.id, tit))
    return res
8
Avatar
Descartar
omprakash
Autor

Hi Sandeep , Thanks for your reply . I have doubt in < monitor_view.xml> line -> <field name="email" context="{'email':email}"/> how to pass value for def name_get(self, cr, uid, ids, context=None) . Actually I need how to pass context value ( need correct syntax) ...And once again thanks

ClueLogics Technologies Pvt. Ltd.

i think you no need to pass value for context for name get, just include above method and don't use context , as i think you want name get with email so email is already there

omprakash
Autor

Sandeep Thanks for reply . Basically if i use relation (many2one ) title will be displayed because i declared _rec_name = 'title' (notebook). But i need to display email for some module (monitor). So i want to pass context which decide what to display . But i don't know the syntax . If you understand my problem please help me .

ClueLogics Technologies Pvt. Ltd.

for some records email and some for only title ??

omprakash
Autor

Sandeep , For module < monitor > i like to display - email & if i have another module example <school> i want to display as title .

Solanki Shamji

@Sandeep. If I have large amount of data than it is possible to name_get method working? Its give memory error if I have more than 50000 records.

Avatar
Muhammad
Mejor respuesta

Hi,

Can I use this name_get() function as well?

I am using the Automated Actions module to create a project automatically when an opportunity is created.

The only problem I have is that I don't know how to name the project based on the name of the lead/opportunity automatically.

Can you tell me what function/python code I should use?

0
Avatar
Descartar
Avatar
Alexander
Mejor respuesta

Hi! It is too difficult to read unformated source code :)

Perhaps, using related email field instead of many2one field in view will be helpfull for you. Also it will be work faster, because no request will be send for every row.

-1
Avatar
Descartar
omprakash
Autor

Hi Alexander , Thanks for immediate reply . Now I formatted my code . Can you please help me

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
Disable GET parameters
get
Avatar
0
mar 15
4476
How to change displayed values in « deliver to » scroll list in a purchase order?
purchase search quotation name get
Avatar
Avatar
1
jun 15
5347
List view Resuelto
name Listview
Avatar
Avatar
1
feb 25
1714
GET/POST Requests in Odoo to External API
get post
Avatar
Avatar
1
feb 25
20576
Change the database name Resuelto
database name
Avatar
Avatar
Avatar
2
jun 23
16940
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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