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

compute/add selected fields in orderline

Suscribirse

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

Se marcó esta pregunta
order.linecomputed-fields10.0
6 Respuestas
7224 Vistas
Avatar
Dishon Kadoh

Hello guys i have inherited the account.analytic.line model and added a selection field on whether the duration affects the sla or not i want to compute the totals for the time that affects only sla i.e when the selection is yes the duration is computed if no it is not computed how do i go about it.Any assistance will be highly appreciated.

this is the link to my view https://ibb.co/eDr2Te

0
Avatar
Descartar
Avatar
Cyril Gaspard (GEM)
Mejor respuesta

Hi,

code of Ibrahim  optimized

@api.multi
@api.depends('timesheet_ids', 'timesheet_ids.sla', 'timesheet_ids.duration')

def _compute_total_duration(self):

    for record in self:

    record.total_duration = sum(record.timesheet_ids.filtered(lambda rec: rec.sla == 'yes').mapped('duration'))

Regards

1
Avatar
Descartar
Ibrahim Boudmir

+1

Cyril Gaspard (GEM)

Hi Ibrahim,

thank you ^^,

bye

Dishon Kadoh
Autor

Thanks Cyril and Ibrahim.THe code is running Perfectly

Cyril Gaspard (GEM)

Hi,

I recommand you to store the value for better performance, y adding strore=True in the definition of your field. To avoid ir.rule test, and better performance, you can add compute_sudo=True too.

Bye

Avatar
subbarao
Mejor respuesta

add dependency to total compute field

ex:

api.dependency('your sla filed from line',....etc fields)

def _amount_total()

0
Avatar
Descartar
Avatar
Ibrahim Boudmir
Mejor respuesta

Hi, 
you want to calculate the Total of the time that affects only sla. 
Considering that : 
your O2M field is :  timesheet_ids

the total field is : total_duration

the affects SLA :  sla

the Duration : duration

then : 

add (compute='_compute_total_duration', store=True) to total_duration

and 

@api.multi
@api.depends('timesheet_ids', 'timesheet_ids.sla', 'timesheet_ids.duration')
def _compute_total_duration(self):
    for record in self:
        total = False
        // Filter only on record with sla = Yes
        timesheets = record.timesheet_ids.filtered(lambda rec: rec.sla == 'yes')
        if timesheets:
            for timesheet in timesheets:
                total += timesheet.duration     // here, you may want to check how to add durations based on your field's signature
        record.total_duration = total                    
0
Avatar
Descartar
Cyril Gaspard (GEM)

Hi,

I think you forgot something in your code :

total += timesheet

should be

total += timesheet.duration

Bye

Cyril Gaspard (GEM)

second error, :

total = False

should be not before but in for record in self:

Ibrahim Boudmir

I agree Cyril. I have updated my answer

Thank you

Cyril Gaspard (GEM)

Hi,

I add @api.muti in your code

bye

¿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
How is caching working ?
cache compute computed-fields 10.0
Avatar
0
oct 17
7558
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR
computed-fields
Avatar
Avatar
1
jun 25
17395
Make stored compute filed recompute after changing it logic but not depedencies.
computed-fields
Avatar
Avatar
Avatar
Avatar
3
abr 25
7968
Compute Fields Resuelto
computed-fields
Avatar
Avatar
2
jul 24
9506
Odoo computed field
computed-fields
Avatar
Avatar
1
ene 24
2909
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 empresariales de código abierto que cubre 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