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

How to access the vals dict.

Suscribirse

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

Se marcó esta pregunta
createvals
4 Respuestas
7752 Vistas
Avatar
Tarek Mohamed Ibrahim

I created a new record in a one2many field in a view, e.g. the order.line in a sales order screen. I need after each new line added in the detail, the one2many field, to sum the total amount of the order via an onchange method in the qty or price fields. I don't need to go to the 'update' button and click it each time I need to update the total amount. How to do that?

----

My idea is to access the vals array that is sent to the 'create' method when saving a record, I need to access it before saving.

0
Avatar
Descartar
Avatar
Axel Mendoza
Mejor respuesta

The one2many fields store the values in a format described on the write method of the model. For this task you need to pass the one2many field for the on_change method and check the state of their records in order to properly sum your total, something like this:

 def onchange_line_ids(self, cr, uid, ids, order_lines, context=None):  
    total = 0
    line_pool = self.pool.get('sale.order.line')
   for line in order_lines: 
if line[0] == 0:
             total += line[2].get('qty', 0)
        elif line[0] == 4:
            total += line_pool.browse(cr, uid, line[1], context=context).qty
        elif line[0] == 1:
             if line[2].get('qty', False):
                 total += line[2].get('qty', 0)
            else:
                 total += line_pool.browse(cr, uid, line[1], context=context).qty  
   return {'value': {'total': total}}

2
Avatar
Descartar
Tarek Mohamed Ibrahim
Autor

in the onchange method of the price I passed the 'order_id.order_line' and it didn't recognize it. I then passed only the 'order_id' on hope to access 'order_line' in the method, but it gave me what is called 'Newid' and was not able to accomplish my task

Axel Mendoza

You cannot do that, you need to put the onchange on the main form level to be able to pass order_line field, you could put the onchange to the order_line field itself because it's the main source of changes that you need to monitor, and pass only order_line instead of order.order_line, in the view you cannot move very easily over relation fields

Tarek Mohamed Ibrahim
Autor

thx Axel for answer, it has worked. I accepted the answer and gave you an upvote

Avatar
Pawan
Mejor respuesta

Hi Tarek, 

If i am wright, you want to sum of total price/qty in your one2many field. you can simply add an attribute "sum" at the qty/price field under tree tag, like:

<tree> [your one2many field tree view]

<field name="[your field]" sum="Total" />

........

</tree>

it will show sum of your fields data at the end of tree view.....

Hope it helps!!    

0
Avatar
Descartar
Tarek Mohamed Ibrahim
Autor

I've already did that and I can see the sum of the amounts every time I do a change in qty or price in any line. My case is different, that is, I have a field that defines the upper limit of a Sales Order amount, this field is per customer, and I read this field in the sale_order class via a function and display it on the order header. When saving the order, the create/write method checks if the sum of the line amounts exceeded this limit, then it raises an exception and stops the save action. The user then have to go to lines and reduce qtys until the amounts sum go below the upper limit allowed. I need this be done automatically via an onchange method. I checked the last reply from Axel and still didn't try it. I think it would work

¿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
Can't get some values from vals
create vals
Avatar
0
sept 17
4663
What does vals mean ,and how to use it in the case of overriding the create() & write() methods ? Resuelto
create write vals
Avatar
Avatar
1
ago 16
11583
Create new bug
create
Avatar
0
abr 24
2835
vals for relationship fields (one2many) Resuelto
one2many create v7 vals
Avatar
Avatar
1
dic 22
6818
how i can update value of field in create method in Odoo v13 CE
create
Avatar
0
dic 19
5364
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