Skip to Content
Menu
This question has been flagged
3 Replies
2663 Views

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
Discard
Best Answer

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
Discard
Author

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?

Best Answer

Hi Ahmed, 

What was the solution you found? 

Avatar
Discard
Author Best Answer

Thank you for everyone try to help 


I solve this by myself.


Avatar
Discard

may we know, how did you solve it?

Related Posts Replies Views Activity
3
Mar 15
8993
2
Nov 24
77
2
Mar 24
477
0
Sep 23
610
2
Aug 23
19974