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

Why do i get a value of 0?

Suscribirse

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

Se marcó esta pregunta
holidaysmethodcompute
3581 Vistas
Avatar
Steven Salty

Hi Forum!


I don't understand why i get a value of 0 in the method 1 below.


                                                                         Method 1                                                       


yearly_holidays_ids = fields.One2many('hr.employee.yearly.holidays', 'employee_id')
current_holiday_pool = fields.Integer(compute="_get_current_holiday_pool", store=True)


field in hr.employee.yearly.holidays:

holidays_ids = fields.Many2many('hr.holidays',compute='_compute_holidays_ids')


field in hr.holidays:

holiday_status_id = fields.Many2one("hr.holidays.status", string="Leave Type", required=True, readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]})

@api.multi
@api.depends('yearly_holidays_ids')
def _get_current_holiday_pool(self):
for record in self:
current_year = datetime.date.today().year
total_holidays = record.yearly_holidays_ids.filtered(lambda lm: lm.year == current_year)
total_record = total_holidays.mapped("holidays_ids").filtered(lambda lm: lm.holiday_status_id.name == 'Annual')
if len(total_record) > 1:
total_record = total_record[0]
record.current_holiday_pool = total_record.remaining_count
elif len(total_record) == 1:
record.current_holiday_pool = total_record.remaining_count
elif len(total_record) == 0:
record.current_holiday_pool = 0


                                                                                Method 2                                                             


with this method:

@api.multi
@api.depends('yearly_holidays_ids')
def _get_current_holiday_pool(self):
for record in self:
current_year = datetime.date.today().year
total_record = record.yearly_holidays_ids.filtered(lambda lm: lm.year == current_year)
if len(total_record) > 1:
total_record = total_record[0]
record.current_holiday_pool = total_record.remaining_count
elif len(total_record) == 1:
record.current_holiday_pool = total_record.remaining_count
elif len(total_record) == 0:
record.current_holiday_pool = 0

I get the correct value, which is 20, that would be the base I started from.


In the first method (Method 1), I tried to achieve this:

The process is to collect the remaining annual leave for your employees, which is 20 days. This method should be supplemented so that if, for example, the employee takes sick leave, the remaining limit is 20 days, stay 20 days, but if he takes annual leave, he subtracts the remaining limit from the 20 days according to the date of the taken leave. So if an employee has 20 days of remaining leave and takes 1 day of remaining leave, he has 20 days of remaining leave, but if he takes 1 day of annual leave, he has 19 days of remaining leave.

This should extend the _get_current_holiday_pool method (Method 1)


In essence, the method should only be deducted from the number of leave (20) if the employee takes annual leave.


I hope i was clear,

Thank you for your help

Regards,

Steven



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
Publicaciones relacionadas Respuestas Vistas Actividad
How should I change the method?
leaves method compute
Avatar
Avatar
1
oct 21
3106
TypeError: 'int' object is not iterable Resuelto
method typeerror compute
Avatar
Avatar
Avatar
Avatar
4
ene 18
37372
Why isn't the field updated?
fields update method compute
Avatar
0
dic 21
2649
Why this computed field doest not work? Resuelto
field method compute computed
Avatar
Avatar
1
dic 21
6772
Public Holiday - Time Off request does not show during of PTO requested (v17)
holidays
Avatar
0
jul 24
1876
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