Skip to content

Commit

Permalink
Merge 8a90a5f into 42bc43e
Browse files Browse the repository at this point in the history
  • Loading branch information
andhit-r committed Jan 12, 2017
2 parents 42bc43e + 8a90a5f commit 7e7d0c9
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 0 deletions.
73 changes: 73 additions & 0 deletions hr_worked_days_from_attendance/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.. 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

===========================
Worked Days From Attendance
===========================

This module adds functionality to import attendance into payslip
worked days computation

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 *Worked Days From Attendance*
6. Install the module

Configuration
=============

No configuration needed

Usage
=====

To import attendance into payslip you have to:

1. Go to *Human Resources -> Payroll -> Employee Payslip*
2. Open payslip data
3. Click *Import From Attendance* button

Odoo will import *one* worked days computation with *ATTN* code. That
computation is computed from *Timesheet By Period* thats match payslip
period

Known issues / Roadmap
======================


Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/open-synergy/opnsynid-hr/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/open-synergy/
opnsynid-hr/issues/new?body=module:%20
hr_worked_days_from_attendance%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

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

* Andhitia Rama <andhitia.r@gmail.com>

Maintainer
----------

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

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

from . import models
21 changes: 21 additions & 0 deletions hr_worked_days_from_attendance/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Worked Days From Attendance",
"summary": "Compute worked days from attendance",
"version": "8.0.1.0.0",
"category": "Human Resources",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"hr_timesheet_sheet",
"hr_payroll",
],
"data": [
"views/hr_payslip_view.xml",
],
}
5 changes: 5 additions & 0 deletions hr_worked_days_from_attendance/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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

from openerp import models, api, _


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

@api.multi
def button_import_attendance(self):
for payslip in self:
payslip._import_attendance()

@api.multi
def _import_attendance(self):
self.ensure_one()
wd_obj = self.env["hr.payslip.worked_days"]
day_obj = self.env["hr_timesheet_sheet.sheet.day"]
date_from = self.date_from
date_to = self.date_to

criteria1 = [
("payslip_id", "=", self.id),
("import_from_attendance", "=", True),
]
wd_obj.search(criteria1).unlink()

res = {
"name": _("Total Attendance"),
"code": "ATTN",
"number_of_days": 0.0,
"number_of_hours": 0.0,
"contract_id": self.contract_id.id,
"import_from_attendance": True,
"payslip_id": self.id,
}

criteria2 = [
("sheet_id.date_from", ">=", date_from),
("sheet_id.date_to", "<=", date_to),
("sheet_id.employee_id", "=", self.employee_id.id),
("sheet_id.state", "=", "done"),
]

for day in day_obj.search(criteria2):
if day.total_attendance >= 0.0:
res["number_of_days"] += 1
res["number_of_hours"] += day.total_attendance

wd_obj.create(res)
14 changes: 14 additions & 0 deletions hr_worked_days_from_attendance/models/hr_payslip_worked_days.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# © 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from openerp import models, fields


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

import_from_attendance = fields.Boolean(
string='Imported From Timesheet',
default=False,
)
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_from_attendance/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 OpenSynergy Indonesia <https://opensynergy-indonesia.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_worked_days_from_attendance
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
# © 2016 OpenSynergy Indonesia <https://opensynergy-indonesia.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase
from datetime import datetime, timedelta


class TestComputeWorkdays(TransactionCase):

def setUp(self):
super(TestComputeWorkdays, self).setUp()

self.company = self.env.ref('base.main_company')
self.analytic_journal = self.env.ref('hr_timesheet.analytic_journal')
self.user_admin = self.env.ref('base.partner_root')
self.company.update({'timesheet_range': 'month'})

user_dict = {
'name': 'User 1',
'login': 'tua@example.com',
'password': 'base-test-passwd',
}
self.user_test = self.env['res.users'].create(user_dict)

employee_dict = {
'name': 'Employee 1',
'user_id': self.user_test.id,
'journal_id': self.analytic_journal.id,
'address_id': self.user_test.partner_id.id,
}
self.employee = self.env['hr.employee'].create(employee_dict)

contract_dict = {
'name': 'Contract 1',
'employee_id': self.employee.id,
'wage': 0.0,
}
self.contract = self.env['hr.contract'].create(contract_dict)

analytic_dict = {
'name': 'Account 1',
'type': 'normal',
'use_timesheets': True,
}

self.analytic = self.env['account.analytic.account'].create(
analytic_dict)

ts_dict = {
'name': 'Test Timesheet',
'employee_id': self.employee.id,
'date_from': '2016-04-01',
'date_to': '2016-04-30',
}

ts_obj = self.env['hr_timesheet_sheet.sheet']
self.ts = ts_obj.create(ts_dict)

attn_obj = self.env['hr.attendance']

day_start = datetime.strptime('2016-04-01', '%Y-%m-%d')
day_end = datetime.strptime('2016-04-30', '%Y-%m-%d')
date_start = datetime.strptime(
'2016-04-01 07:00:00', '%Y-%m-%d %H:%M:%S')
date_end = datetime.strptime(
'2016-04-01 17:00:00', '%Y-%m-%d %H:%M:%S')
self.nb_days = (day_end - day_start).days + 1
for day in range(0, self.nb_days):

attn_dict_1 = {
'sheet_id': self.ts.id,
'name': date_start.strftime('%Y-%m-%d %H:%M:%S'),
'employee_id': self.employee.id,
'action': 'sign_in',
}
attn_obj.create(attn_dict_1)

attn_dict_2 = {
'sheet_id': self.ts.id,
'name': date_end.strftime('%Y-%m-%d %H:%M:%S'),
'employee_id': self.employee.id,
'action': 'sign_out',
}
attn_obj.create(attn_dict_2)
date_start = date_start + timedelta(days=1)
date_end = date_end + timedelta(days=1)
self.ts.button_confirm()
self.ts.signal_workflow("done")

def test_timesheet_import(self):
wd_obj = self.env['hr.payslip.worked_days']
payslip_dict = {
'employee_id': self.employee.id,
'contract_id': self.contract.id,
'date_from': '2016-04-01',
'date_to': '2016-04-30',
}
payslip = self.env['hr.payslip'].create(
payslip_dict)
payslip.button_import_attendance()

criteria = [
('payslip_id', '=', payslip.id),
('code', '=', 'ATTN'),
]
wd = wd_obj.search(criteria)
wd.ensure_one()
self.assertEqual(wd[0].number_of_days, 30.0)
19 changes: 19 additions & 0 deletions hr_worked_days_from_attendance/views/hr_payslip_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="hr_payslip_view_form" model="ir.ui.view">
<field name="name">hr.payslip.form</field>
<field name="model">hr.payslip</field>
<field name="inherit_id" ref="hr_payroll.view_hr_payslip_form"/>
<field name="arch" type="xml">
<field name="worked_days_line_ids" position="before">
<group>
<div class="oe_right oe_button_box">
<button string="Import from Attendance" name="button_import_attendance" type="object" states="draft" />
</div>
</group>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 7e7d0c9

Please sign in to comment.