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
    • eLearning
    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
    • Información
    • 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
    Food & Hospitality
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Guest House
    • Distribuidor de bebidas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consulting
    • Accounting Firm
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Trades
    • Handyman
    • Hardware y asistencia informática
    • Solar Energy Systems
    • Zapatero
    • Servicios de limpieza
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • 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
    • Services for 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

when to use new api decorators??????

Suscribirse

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

Se marcó esta pregunta
v8newapi
2 Respuestas
25225 Vistas
Avatar
jhony

i'm really confused about the decorators in new api....

if anyone is clear about this concept please correct me because currently i'm using this when...

@api.model > method not use ids and no recordset operation done in method...

@api.one > don't know exactly

@api.multi > when method do operaton with multiple records..

if i'm wrong or incorrect please correct my knowledge.. :)

thanks in advance 

 

3
Avatar
Descartar
jhony
Autor

Thanks Mansi for your useful answer..., but i'm still confused with @api.model in definition what it means by "content is not relevant " ?? can you please explain?!

jhony
Autor

ok thnaks mansi now it's more clear to me. and yes you can upvote question if it is useful...

Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Mejor respuesta

If I am not mistaking it is very easy and clear.
The @api.one is specific for one record and can not be used for multiple records. It automaticly loops on records of a Recordset for you. 
@api.many is for multiple records, where you can loop through it etc. It will be the current Recordset without the itiration. So any looping would need to be programmed by yourself, for whatever you want
@api.model is basicly a converter from the old API to the new API. (Odoo V7 -> Odoo V8) Its for migrating code.
@api.depends will trigger the call to the decorated function if any of the fields specified in the decorator is altered by ORM or changed in the form..

An example of @api.one:

@api.one def _compute_name(self):
      self.name = str(random.randint(1, 1e6))

An example of @api.multi:

@api.multi def subscribe(self):
     for session in self.session_ids:
         session.attendee_ids |= self.attendee_ids
     return {}

An example of @api.decorator:

@api.returns('res.partner')
def afun(self):
    ...
    return x # a RecordSet

An example of @api.model:

@api.model
def afun(self):
    pass

An example of @api.depends:

@api.depends('name', 'an_other_field')
def afun(self):
     pass

You can read more about all the decorators and methods here: http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html

3
Avatar
Descartar
Avatar
Mansi Kariya (mka)
Mejor respuesta

Hello Jhony,

@api.one:  Decorate a record-style method where self is expected to be a singleton instance. The decorated method automatically loops on records, and makes a list with the results. In case the method is decorated with @returns, it concatenates the resulting instances. Such a method:

@api.one

def method(self, args): return self.name

may be called in both record and traditional styles, like:

# recs = model.browse(cr, uid, ids, context)

names = recs.method(args)

names = model.method(cr, uid, ids, args, context=context)

 

@api.multi: Decorate a record-style method where self is a recordset. The method typically defines an operation on records. Such a method:

@api.multi

def method(self, args):

...

may be called in both record and traditional styles, like:

# recs = model.browse(cr, uid, ids, context)

recs.method(args)

model.method(cr, uid, ids, args, context=context)

 

@api.model: Decorate a record-style method where self is a recordset, but its contents is not relevant, only the model is. Such a method:

@api.model

def method(self, args):

...

may be called in both record and traditional styles, like:

# recs = model.browse(cr, uid, ids, context)

recs.method(args)

model.method(cr, uid, args, context=context)

For more details, Go through Doc.

Hope this will help you.

4
Avatar
Descartar
Mansi Kariya (mka)

@api.model decorator will convert old API calls to decorated function to new API signature. It allows to be polite when migrating code. And also if you see example when you override orm create method, @api.model is used where id is not used or you can understand not created yet as id did'n generated for that record.

¿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
Is possible to call function decorated with @api.one inside function decorated with @api.model ?
v8 newapi
Avatar
0
mar 15
3667
when inherit sale order, onchange('product_id') can't work
v8 onchange newapi
Avatar
Avatar
Avatar
2
ene 16
5703
How do you implement the Associations: Members website module? Resuelto
v8
Avatar
Avatar
Avatar
3
jul 25
9711
How to Integrate a Full-Screen Color Testing Tool with Odoo Website Builder?
v8
Avatar
Avatar
1
may 25
1954
Odoo V8 integrate with Microsoft O365 Email
v8
Avatar
0
ene 24
2565
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