Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita 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
  • Proyectos
  • 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

How to fix 'NoneType' object has no attribute '__getitem__' ?

Suscribirse

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

Se marcó esta pregunta
1 Responder
69683 Vistas
Avatar
Trai Doan

class vatlieu(osv.osv):
    _name = "vatlieu" 
    _columns = {
        'name': fields.char('Mã vật liệu',size=20,required=True), 
        'ten': fields.char('Tên vật liệu',size=100,required=True),

vatlieu()

class nguyenlieu(osv.osv):
    _name = "tt.nguyenlieu" 
    _columns = {
        'name': fields.many2one('vatlieu','Nguyên liệu',required=True),
        'ten': fields.char('Tên vật liệu',size=100,required=True),
        'soluong':fields.integer('Số lượng cần',required=True),

def on_change_nguyenlieu(self, cr, uid, ids,params):
        cr.execute('select ten from vatlieu where id =%d'%int(params))
        ten=cr.fetchone()[0]
        v={'ten':ten}
        return {'value':v}

nguyenlieu()

My xml 

<record id="nguyenlieu_form" model="ir.ui.view"> 
            <field name="name">nguyenlieu_form</field> 
            <field name="model">tt.nguyenlieu</field> 
            <field name="type">form</field> 
            <field name="arch" type="xml"> 
                <form> 
                        <group col="2">
                            <field name="name" style="width:350px" on_change="on_change_nguyenlieu(name)"/>
                            <field name="ten" style="width:350px"/>
                            <field name="soluong" style="width:350px"/> 
                        </group>
                </form> 
            </field> 
        </record>

When i create new nguyenlieu this error appear :

Traceback (most recent call last): File "C:\openerp-8.0rc1\openerp\http.py", line 496, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "C:\openerp-8.0rc1\openerp\http.py", line 513, in dispatch result = self._call_function(**self.params) File "C:\openerp-8.0rc1\openerp\http.py", line 279, in _call_function return checked_call(self.db, *args, **kwargs) File "C:\openerp-8.0rc1\openerp\service\model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "C:\openerp-8.0rc1\openerp\http.py", line 276, in checked_call return self.endpoint(*a, **kw) File "C:\openerp-8.0rc1\openerp\http.py", line 729, in __call__ return self.method(*args, **kw) File "C:\openerp-8.0rc1\openerp\http.py", line 372, in response_wrap response = f(*args, **kw) File "C:\openerp-8.0rc1\openerp\addons\web\controllers\main.py", line 941, in call_kw return self._call_kw(model, method, args, kwargs) File "C:\openerp-8.0rc1\openerp\addons\web\controllers\main.py", line 933, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "C:\openerp-8.0rc1\openerp\api.py", line 235, in wrapper return old_api(self, *args, **kwargs) File "C:\openerp-8.0rc1\openerp\api.py", line 358, in old_api result = method(recs, *args, **kwargs) File "C:\openerp-8.0rc1\openerp\models.py", line 5686, in onchange record._onchange_eval(name, field_onchange[name], result) File "C:\openerp-8.0rc1\openerp\models.py", line 5620, in _onchange_eval method_res = getattr(self._model, method)(*args) File "C:\openerp-8.0rc1\openerp\api.py", line 235, in wrapper return old_api(self, *args, **kwargs) File "C:\openerp-8.0rc1\openerp\addons\DoanERP\core.py", line 41, in on_change_nguyenlieu ten=cr.fetchone()[0]

TypeError: 'NoneType' object has no attribute '__getitem__'

How can i fix this problem ,plz help me ,i'm new in odoo .Thanks

0
Avatar
Descartar
Avatar
Maniganda
Mejor respuesta

HI , the error is because of this line of code ten=cr.fetchone()[0]

you need to check for the value exist in the cr.fetchone() and then you can assign to a variable,

ten=cr.fetchone()

ten = ten and ten[0] or False

you are trying to convert string to integer and passing for the query

cr.execute('select ten from vatlieu where id =%d'%int(params))

or instead you can search with the name field in the query. and make sure you declare the variable v={} in the starting of your code.

1
Avatar
Descartar
Trai Doan
Autor

thanks for your answer but error still happen .if i use ten=cr.fetchone()[0] this error always happen when i open form and after that it works fine (it returns right value). when i use your code . i can open form without error but when i select value from selection error happen and no value show .

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

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

Registrarse
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • 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 estar totalmente integrado.

Sitio web hecho con

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