Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
3865 Vistas

Hello Guys I am using Odoo  13  enterprise and I  am trying to compute the number of days that an employee spent serving the company to use it in the calculation payroll that will calculate the number of days that an employee spends working for a company based on the Hiring date and current date.

I don't know the python code that I can use to do a rule in the payslip calculation or to create a field in the employee view screen that computes the current working days (up to date automatically)
hope that someone can point me in the right direction

Avatar
Descartar
Mejor respuesta

Hello Ahmed Naji,

You should try this for get employee spends days in company with 2 way depends on data.

Option 1)
If you create new functionality with a fresh database or you don't have any records in the employee, then you can calculate days such a way like below.

from datetime import date

hiring_date = fields.Date(string='Hiring Date' , default=lambda self: date.today())
spend_day = fields.Integer('Spend Days', compute='_compute_days')

def _compute_days(self):
for record in self:
record.spend_day = (date.today() - record.hiring_date).days

Option 2)
If you are using database with already employee data, then you can calculate days such a way like below.

from datetime import date

hiring_date = fields.Date(string='Hiring Date')
spend_day = fields.Integer('Spend Days', compute='_compute_days')

def _compute_days(self):
for record in self:
record.spend_day = (date.today() - record.hiring_date).days if record.hiring_date else 0

Thanks & Regards,

Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

Avatar
Descartar
Autor

Hello Jainesh Shah,

Thank you for replying to my post. I am using Odoo SaaS so I don't have access to the server backend.so I don't know how I can apply this code from the user interface. I only can do custom fields and do the computing in the advanced property in the user interface.so if you know of a way or how to do it, I will really appreciate it
Thank you in advance

in which model should I put it into?

Mejor respuesta

Hi Ahmed, 

What was the solution you found? 

Avatar
Descartar
Autor Mejor respuesta

Thank you for everyone try to help 


I solve this by myself.


Avatar
Descartar

may we know, how did you solve it?

Publicaciones relacionadas Respuestas Vistas Actividad
3
mar 15
10392
2
nov 24
1563
2
mar 24
1949
0
sept 23
1802
2
ago 23
21538