Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Why do i get a value of 0?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
holidaysmethodcompute
3599 Vistes
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
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
How should I change the method?
leaves method compute
Avatar
Avatar
1
d’oct. 21
3132
TypeError: 'int' object is not iterable Solved
method typeerror compute
Avatar
Avatar
Avatar
Avatar
4
de gen. 18
37421
Why isn't the field updated?
fields update method compute
Avatar
0
de des. 21
2663
Why this computed field doest not work? Solved
field method compute computed
Avatar
Avatar
1
de des. 21
6803
Public Holiday - Time Off request does not show during of PTO requested (v17)
holidays
Avatar
0
de jul. 24
1894
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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