Skip to content

Commit

Permalink
Merge 20d4d7f into e757171
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Feb 7, 2017
2 parents e757171 + 20d4d7f commit 1ddbd5e
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 0 deletions.
39 changes: 39 additions & 0 deletions hr_worked_days_compute_holiday/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

==============================
HR Worked Days Compute Holiday
==============================

This module adds a public holidyas when compute worked days.

Installation
============

To install this module, you need to:

1. Clone the branch 8.0 of the repository https://github.com/open-synergy/opnsynid-hr
2. Add the path to this repository in your configuration (addons-path)
3. Update the module list
4. Go to menu *Setting -> Modules -> Local Modules*
5. Search For *HR Worked Days Compute Holiday*
6. Install the module

Credits
=======

Contributors
------------

* Michael Viriyananda <viriyananda.michael@gmail.com>
* Andhitia Rama <andhitia.r@gmail.com>

Maintainer
----------

.. image:: https://opensynergy-indonesia.com/logo.png
:alt: OpenSynergy Indonesia
:target: https://opensynergy-indonesia.com

This module is maintained by the OpenSynergy Indonesia.
5 changes: 5 additions & 0 deletions hr_worked_days_compute_holiday/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
17 changes: 17 additions & 0 deletions hr_worked_days_compute_holiday/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "HR Worked Days Compute Holiday",
"version": "8.0.1.0.0",
"category": "Human Resources",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": [
"hr_payroll",
"hr_holidays_compute_days"
],
"data": [],
}
5 changes: 5 additions & 0 deletions hr_worked_days_compute_holiday/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import hr_payslip
37 changes: 37 additions & 0 deletions hr_worked_days_compute_holiday/models/hr_payslip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api
from datetime import datetime
from datetime import timedelta


class HrPayslip(models.Model):
_inherit = 'hr.payslip'

@api.v8
def get_worked_day_lines(self, contract_ids, date_from, date_to):
res = super(HrPayslip, self).get_worked_day_lines(
contract_ids, date_from, date_to)
number_of_days = 0.0
day_from = datetime.strptime(date_from, "%Y-%m-%d")
day_to = datetime.strptime(date_to, "%Y-%m-%d")
nb_of_days = (day_to - day_from).days + 1
contract_id = res[0]['contract_id']
contract = self.env['hr.contract'].browse(contract_id)
for day in range(0, nb_of_days):
work_scheduled = contract.employee_id.work_scheduled_on_day(
date_dt=day_from + timedelta(days=day))
if work_scheduled:
number_of_days += 1.0
res[0].update({'number_of_days': number_of_days})
return res

@api.v7
def get_worked_day_lines(
self, cr, uid, contract_ids, date_from, date_to, context=None
):
recs = self.browse(cr, uid, context)
return HrPayslip.get_worked_day_lines(
recs, contract_ids, date_from, date_to)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions hr_worked_days_compute_holiday/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Michael Viriyananda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_get_worked_day_lines
142 changes: 142 additions & 0 deletions hr_worked_days_compute_holiday/tests/test_get_worked_day_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase


class TestGetWorkedDayLines(TransactionCase):
def setUp(self, *args, **kwargs):
super(TestGetWorkedDayLines, self).setUp(*args, **kwargs)
# Objects
self.obj_hr_employee = self.env['hr.employee']
self.obj_res_partner = self.env['res.partner']
self.obj_payslip = self.env['hr.payslip']
self.obj_contract = self.env['hr.contract']
self.obj_struct = self.env['hr.payroll.structure']
self.obj_holiday = self.env["hr.holidays.public"]
self.obj_holiday_line = self.env["hr.holidays.public.line"]

# Data
self.country = self.env.ref(
'base.id')
self.department = self.env.ref(
'hr.dep_rd')
self.company = self.env.ref('base.main_company')
self.type =\
self.env.ref('hr_contract.hr_contract_type_emp')
self.resource =\
self.env.ref('resource.timesheet_group1')
self.rule_1 = self.env.ref(
'hr_payroll.hr_salary_rule_houserentallowance1')
self.rule_2 = self.env.ref(
'hr_payroll.hr_salary_rule_convanceallowance1')
self.rule_3 = self.env.ref(
'hr_payroll.hr_salary_rule_professionaltax1')
self.rule_4 = self.env.ref(
'hr_payroll.hr_salary_rule_providentfund1')
self.rule_5 = self.env.ref(
'hr_payroll.hr_salary_rule_meal_voucher')
self.rule_6 = self.env.ref(
'hr_payroll.hr_salary_rule_sales_commission')

def _create_holiday(self):
holiday = self.obj_holiday.create({
'year': 2017,
'country_id': self.country.id
})
self.obj_holiday_line.create({
'name': 'Test Holiday #1',
'date': '2017-02-10',
'year_id': holiday.id
})

return True

def _create_employee(self):
vals_home_addr = {
'name': 'Home Address Alan',
'country_id': self.country.id
}
addr = self.obj_res_partner.create(
vals_home_addr)
vals = {
'name': 'Alan',
'department_id': self.department.id,
'birthday': '1967-01-01',
'gender': 'male',
'address_id': addr.id
}

employee = self.obj_hr_employee.create(vals)
return employee

def _create_structure(self):
vals = {
'name': 'Test Salary Structure',
'code': 'TST',
'company_id': self.company.id,
'rule_ids': [(6, 0, [
self.rule_1.id,
self.rule_2.id,
self.rule_3.id,
self.rule_4.id,
self.rule_5.id,
self.rule_6.id
])]

}

struct = self.obj_struct.create(vals)
return struct

def _create_contract(self, employee, struct):
vals = {
'name': 'Test Contract',
'date_start': '2017-02-1',
'date_end': '2017-12-31',
'wage': 7500000.0,
'type_id': self.type.id,
'employee_id': employee.id,
'struct_id': struct.id,
'working_hours': self.resource.id
}

contract = self.obj_contract.create(vals)
return contract

def test_get_worked_day_lines(self):
# Create Holiday
self._create_holiday()

# Create Employee
employee = self._create_employee()

# Create Structure
struct = self._create_structure()

# Create Contract
contract = self._create_contract(
employee=employee,
struct=struct)

# Create Payslip
vals = {
'employee_id': employee.id,
'contract_id': contract.id,
'struct_id': struct.id
}
new = self.obj_payslip.create(vals)
new.onchange_employee_id(
date_to=new.date_to,
date_from=new.date_from,
employee_id=new.employee_id.id,
contract_id=new.contract_id.id
)

worked_days_line_ids = new.get_worked_day_lines(
contract_ids=[contract.id],
date_from=new.date_from,
date_to=new.date_to)

self.assertEqual(19.0, worked_days_line_ids[0]['number_of_days'])

0 comments on commit 1ddbd5e

Please sign in to comment.