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 store field readonly in database with onchange method

Suscribirse

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

Se marcó esta pregunta
8 Respuestas
18307 Vistas
Avatar
oussama

Hi

How to store field readonly in database with onchange method

my code :

 def fret_change (self,cr, uid,ids ,tva_p,t_c,prix_d,fret_p,context):
        vals={}
        vals['p_achat_ht']= (t_c*prix_d)*(1+(fret_p/100))
         
        return {'value': vals}

def write(self,cr, uid, ids, vals, context=None):
        for rec in self.browse(cr, uid, ids, context=context):
            #Pass required value of fields in onchange
           
            res = self.fret_change(cr, uid, [rec.id], rec.tva_p, rec.t_c,rec.prix_d,rec.fret_p,context)
            if res.has_key('p_achat_ht'):
                vals.update({'p_achat_ht': res.get('p_achat_ht')})
        return super(product_product, self).write(cr, uid, ids, vals, context=context)

    def create(self,cr, uid, vals, context=None):
        #Pass required value of fields in onchange
        res = self.fret_change(cr, uid, [], vals.get('tva_p'),vals.get('t_c'), vals.get('prix_d'),vals.get('fret_p'),context)
        if res.has_key('p_achat_ht'):
            vals.update({'p_achat_ht': res.get('p_achat_ht')})
        return super(product_product, self).create(cr, uid, vals, context=context)

thanks

1
Avatar
Descartar
Sehrish

Try this: https://learnopenerp.blogspot.com/2021/10/onchange-method-readonly-field-not-store-database-odoo.html

Avatar
Annadurai
Mejor respuesta

Hey! guys. We found a solution to store readonlyonchange in DB through below code.. CREATE edit, it will store in DB

samp_cal1=fields.Integer(string="a")

samp_cal2=fields.Integer(string="b")

samp_cal3=fields.Integer(string="c",readonly=True)

@api.onchange('samp_cal1','samp_cal2')

def adding_samp(self):

self.samp_cal3=self.samp_cal1+self.samp_cal2

@api.model

def create(self,vals):

    if self.samp_cal3:

        vals['samp_cal3']=self.samp_cal1+self.samp_cal2

    res = super(tokenreservation, self).create(vals)

    return res

@api.multi

def write(self,vals):

    if not self.samp_cal3:

        vals['samp_cal3'] = self.samp_cal1+self.samp_cal2

    res = super(tokenreservation, self).write(vals)

    return res

5
Avatar
Descartar
Avatar
vadivel
Mejor respuesta

Hi friend, Usually when field is readonly and it gets input through on_change function after saving the record the value wont stored in database.So try below code:

addons/web/static/js/view_form.js:

In view_form.js:

in line: 840:

if (!f.get("readonly")) {

     values[f.name] = f.get_value(); }

else { readonly_values[f.name] = f.get_value(); }

     values[f.name] = f.get_value(); 

if (f.get("readonly")) 

   readonly_values[f.name] = f.get_value();

}

}

I think it will help you Thanks

1
Avatar
Descartar
Ben Bernard

Can you format your answer code more nicely. I think your solution could works.

Avatar
Bharat Devnani
Mejor respuesta

Dear All,

Kindly look at this blog post for solution https://bharatrdevnani.wordpress.com/2016/02/04/readonly-attributes-onchange-odoo/ surely it will help.


Regards,

Bharat

1
Avatar
Descartar
Avatar
meriem HAKKANI
Mejor respuesta

Hi

Try this : http://www.odooninja.com/readonly-field-onchange-method/

i try it its OK

0
Avatar
Descartar
Avatar
Deepa Venkatesh
Mejor respuesta

As the term indicates Readonly, meaning values are not changed in those fields, hence odoo will not consider those values while saving it into database....

So best way to handle is making it as Functional / Computational field... that way it will be readonly and as well value will computated and can be either stored or not-stored...

But still you wish to use basic/normal fields with readonly property, then in ORM methods both create & write method, call the onchange event and update your values for those readonly fields manually...

 

0
Avatar
Descartar
Annadurai

hey Dep..! we can change onchange readonly field and save it to DB.. look my code

Avatar
sameer alhwety
Mejor respuesta

If the field in new module you created you can making it functional field, but if the field already on system created by OpenERP/Odoo  don't change the field just create new field and save the value on it

0
Avatar
Descartar
¿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