Odoo Help


1 Answer
Barış Erdoğan Turkey
10/4/18, 8:54 AM


I'm faced with a similar scenario. But I need to move staff leave to the next year.

So, I wrote a scheduled action for this situation based on start dates and ages. But I'm not sure of the accuracy, maybe it can give you an idea.

I created two fields in hr.employee object : 

class HrEmployee(models.Model):

    _inherit = 'hr.employee'

    age = fields.Char(string='Yaş')

    annual_leave_calc_number = fields.Integer(string="Annual Leave Calculation Number")

    annual_leave_calc_date = fields.Datetime(string="Annual Leave Calculation Date")

After , method for ir_cron  


    def _cron_employee_remaining_leaves(self):

      for employee in self.search([('active', '=', True)]):

            _emp_leave_right = 0

            _emp_age = employee.age

            _emp_date_job_start = datetime.strptime(employee.ise_giris_tarihi, '%Y-%m-%d').date()

            _current_date = datetime.now().date()

            if int(_emp_age) >= 15:

               .... (some calculations )


                temp_start_date = _emp_date_job_start

                if employee.annual_leave_calculation_number > 0:

                    temp_start_date = employee.annual_leave_calculation_date

                while _current_date == self.addYears(temp_start_date, 1):

                    employee.remaining_leaves += _emp_leave_right

                    employee.annual_leave_calc_date = _current_date

                    employee.annual_leave_calc_number += 1


                _logger.info('15 yaşından küçük personel çalıştıramazsınız ve izin hakkı yoktur.')



    # This method for getting next year or years from the starting date 

    def addYears(self, date_start, years):


            return date_start.replace(year=date_start.year + years)

        except ValueError:

            return date_start + (date(date_start.year + years, 1, 1) - date(date_start.year, 1, 1))

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now