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

Odoo docs Chapter 12: Inheritance

Suscribirse

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

Se marcó esta pregunta
developmentdebug
1 Responder
1745 Vistas
Avatar
Kareem
Python Inheritance -> 

 Exercise

Add business logic to the CRUD methods.

  • Prevent deletion of a property if its state is not ‘New’ or ‘Cancelled’

Tip: create a new method with the example)

any help of what self do

vals : data send from form

self : ?????

it's a way to query the data from the data base .

​or

​it 's have the context send from ui and if it's the context how can i debug or print this object to navigate throw it's member




@api.model_create_multi
def create(self, vals):
for val in vals:
# get estate_property
estate_property = self.env["estate.property"].browse(val["property_id"])

estate_property.state = "offer_Received"
# get list of estate_property_offers from estate_property
estate_property_offers = estate_property.offer_ids

new_val = val["price"]
max_all_value_before_save = max(estate_property_offers.mapped("price"), default=0.0)

if new_val < max_all_value_before_save:
raise UserError("Price must bigger than the highest offers")

return super().create(vals)
1
Avatar
Descartar
Kareem
Autor

thank u  Chathura , your answer help me lot 


In your code, create(self, vals) is a method being decorated with @api.model_create_multi, which means,

  • self is the model class ===> estate.property
  • vals is a list of dictionaries containing the values to create multiple records --> = offer_ids with id == 0 
  • print(vals)


estate_property = self.env["estate.property"].browse(val["property_id"])

so this code working because  estate.property is the model class 

 and i get estate_property_offers from estate.property


self.env["estate.property.type"].browse(val["property_type_id"]) --> throw error 

but this not, so if i want to get to any look up i need deal with model class estate.property  first

is that's right  and if i want to query estate_property_offers  it's have another  method 

@api.model_create_multi


def create(self, vals):
for val in vals:
# get estate_property
estate_property = self.env["estate.property"].browse(val["property_id"])

estate_property.state = "offer_Received"
# get list of estate_property_offers from estate_property
estate_property_offers = estate_property.offer_ids

new_val = val["price"]
max_all_value_before_save = max(estate_property_offers.mapped("price"), default=0.0)

if new_val < max_all_value_before_save:
raise UserError("Price must bigger than the highest offers")

return super().create(vals)



Avatar
Chathura Munasinghe
Mejor respuesta

Hello Kareem,

In Odoo, self represents the current object instance. When you define methods in an Odoo model, self is the first parameter and it refers to,

  1. In a regular method - The recordset (collection of records) you're working with
  2. In the @api.model decorated methods - The model class itself (not a specific record)

In your code, create(self, vals) is a method being decorated with @api.model_create_multi, which means,

  • self is the model class
  • vals is a list of dictionaries containing the values to create multiple records

Hope this helps.

1
Avatar
Descartar
¿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
(((guia-ayuda)))¿Cómo llamar a Latam Chile desde celular?
development debug
Avatar
0
dic 25
1
Testing of computed field in Odoo 18 extension dev
development debug
Avatar
1
nov 25
629
How do I correctly create a calculated field to sum two other field values in Odoo Studio (Odoo Online)? Resuelto
development debug
Avatar
Avatar
2
nov 25
746
How can I make buttons in Odoo 18? Resuelto
development debug
Avatar
Avatar
Avatar
3
sept 25
1736
Problem when creating my first module locally
development debug
Avatar
Avatar
Avatar
Avatar
Avatar
4
ago 25
2199
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