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

get current model id in controller odoo17

Suscribirse

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

Se marcó esta pregunta
modelsidcontrollerodoo17
2 Respuestas
3122 Vistas
Avatar
Muhammad Ihza Putra Handayani

im trying to get the id of the current model that i edit or created but i cant get it
below is my code

def _get_basic_product_information_purchase(self, product_or_template, pricelist, combination, **kwargs):
        basic_information = dict(
            **product_or_template.read(['description_purchase', 'display_name'])[0]
        )
       
        if not product_or_template.is_product_variant:
            basic_information['id'] = False
            combination_name = combination._get_combination_name()
            if combination_name:
                basic_information.update(
                    display_name=f"{basic_information['display_name']} ({combination_name})"
                )
       
        price = product_or_template.standard_price

        purchase_order_id = int(kwargs.get('id', 0))
   
        if purchase_order_id:
            purchase_order = request.env['purchase.order'].browse(purchase_order_id)
           
            if purchase_order:
                seller = product_or_template.seller_ids.filtered(lambda s: purchase_order.partner_id.id)
                if seller:
                    price = seller[0].price

        return dict(
            **basic_information,
            price=price
        )
0
Avatar
Descartar
Avatar
Nikhil Nakrani
Mejor respuesta

Hi,

can you check this,

https://www.odoo.com/forum/help-1/get-current-model-informations-in-the-controller-249734

Thanks

0
Avatar
Descartar
Avatar
Jainesh Shah(Aktiv Software)
Mejor respuesta

Hello Muhammad Ihza Putra Handayani, 


    The issue seems to stem from the way you're handling the ID of the current model (product_or_template). 

    To ensure that you're getting the correct ID of the product or template, you should add a mechanism to 

    extract it directly from the product_or_template object, especially when product_or_template.is_product_variant is True.


    Here's how you can modify your function to correctly extract and use the ID of the product_or_template object.

// Code in comment //

    Hope this helps.

    

    If you need any help in customization feel free to contact us.

        

Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari 

0
Avatar
Descartar
Jainesh Shah(Aktiv Software)

Code :

def _get_basic_product_information_purchase(self, product_or_template, pricelist, combination, **kwargs):
# Initialize basic information dictionary
basic_information = dict(
**product_or_template.read(['description_purchase', 'display_name'])[0]
)

# Add the product_or_template ID to the basic_information dictionary
basic_information['id'] = product_or_template.id

# If the product_or_template is not a product variant
if not product_or_template.is_product_variant:
basic_information['id'] = False # Reset ID to False
combination_name = combination._get_combination_name()
if combination_name:
basic_information.update(
display_name=f"{basic_information['display_name']} ({combination_name})"
)

# Get the standard price of the product_or_template
price = product_or_template.standard_price

# Get the purchase order ID from kwargs
purchase_order_id = int(kwargs.get('id', 0))

if purchase_order_id:
# Browse the purchase order using the ID
purchase_order = request.env['purchase.order'].browse(purchase_order_id)

if purchase_order:
# Find the seller linked to the purchase order partner
seller = product_or_template.seller_ids.filtered(lambda s: s.name.id == purchase_order.partner_id.id)
if seller:
# Use the seller's price if available
price = seller[0].price

# Return the basic information along with the price
return dict(
**basic_information,
price=price
)

Muhammad Ihza Putra Handayani
Autor

thank you very much for your helps but it seems that it not reach what i desire. actually the id of what i am going to get is from purchase.order and if i try your below code i dont even get any id
but if try straight search of id in purchase order it worked well
price = product_or_template.standard_price
purchase_order = request.env['purchase.order'].search([('id', '=', self.id)])

for rec in purchase_order:
seller = product_or_template.seller_ids.filtered(lambda x: x.partner_id.id == rec.partner_id.id)
if seller:
price = seller[0].price

any idea? im stuck in this

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

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

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
model ir.translation present in odoo 17 or not Resuelto
models odoo17
Avatar
Avatar
Avatar
3
jun 24
5674
How i can get ID from Object
models id
Avatar
0
jul 19
5574
object has no attribute '_ids' Resuelto
models id
Avatar
Avatar
2
may 15
21529
Request for Compatible Low Stock Alerts Module for Odoo 17.0-20240718 Community Edition
community models odoo17
Avatar
Avatar
Avatar
2
jun 25
2074
attributeerror '_unknown' object has no attribute 'id' odoo Resuelto
models id v15
Avatar
Avatar
Avatar
Avatar
3
abr 23
13536
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.

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