Skip to content

Commit

Permalink
Adding new module hr_timesheet_mass_generate
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Nov 14, 2017
1 parent deeaec0 commit 7996e26
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 0 deletions.
38 changes: 38 additions & 0 deletions hr_timesheet_mass_generate/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. 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

=======================
Mass Generate Timesheet
=======================

This module adds a wizard to mass generate timesheet.

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 *Mass Generate Timesheet*
6. Install the module

Credits
=======

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

* Michael Viriyananda <viriyananda.michael@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_timesheet_mass_generate/__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 wizards
16 changes: 16 additions & 0 deletions hr_timesheet_mass_generate/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Mass Generate Timesheet",
"version": "8.0.1.0.0",
"category": "Human Resources",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": ["hr_timesheet_sheet"],
"data": [
"wizards/hr_timesheet_mass_generate.xml"
],
}
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_timesheet_mass_generate/wizards/__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.html).

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

from openerp import models, fields, api, _
from datetime import datetime
from openerp.exceptions import ValidationError


class HrTimesheetMassGenerate(models.TransientModel):
_name = "hr.timesheet_mass_generate"
_description = "HR Timesheet Mass Generate"

date_from = fields.Date(
string="Date From",
default=datetime.now().strftime("%Y-%m-%d"),
required=True,
)

date_to = fields.Date(
string="Date To",
default=datetime.now().strftime("%Y-%m-%d"),
required=True,
)

employee_ids = fields.Many2many(
string="Employee",
comodel_name="hr.employee",
relation="hr_employee_generate_manual_rel",
column1="wizard_id",
column2="employee_id",
required=True,
)

@api.constrains(
"date_from", "date_to")
def _check_date(self):
strWarning = _(
"Date From must be greater than Date To")
if self.date_from and self.date_to:
if self.date_from > self.date_to:
raise ValidationError(strWarning)

@api.multi
def button_generate(self):
obj_hr_timesheet_sheet =\
self.env["hr_timesheet_sheet.sheet"]

for employee in self.employee_ids:

if not employee.user_id:
raise ValidationError(
_("Employee {name} must be linked to a user.".format(
name=employee.name)))
elif not employee.journal_id:
raise ValidationError(
_("Employee {name} must have analytic journal.".format(
name=employee.name)))
else:
criteria = [
("employee_id", "=", employee.id),
("date_from", "<=", self.date_from),
("date_to", ">=", self.date_to)
]

timesheet_sheet =\
obj_hr_timesheet_sheet.search(criteria)

if timesheet_sheet:
raise ValidationError(
_("Timesheet already exists for {name}.".format(
name=employee.name)))
else:
value = {
"employee_id": employee.id,
"date_from": self.date_from,
"date_to": self.date_to
}
obj_hr_timesheet_sheet.create(value)

return {"type": "ir.actions.act_window_close"}
42 changes: 42 additions & 0 deletions hr_timesheet_mass_generate/wizards/hr_timesheet_mass_generate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="hr_timesheet_mass_generate_view_form" model="ir.ui.view">
<field name="name">HR Timesheet Mass Generate Form</field>
<field name="model">hr.timesheet_mass_generate</field>
<field name="arch" type="xml">
<form string="Generate Timesheet">
<group colspan="2" col="2">
<field name="date_from"/>
<field name="date_to"/>
<field name="employee_ids"/>
</group>
<footer>
<button string="Generate" name="button_generate" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>

<record id="hr_timesheet_mass_generate_action" model="ir.actions.act_window">
<field name="name">Generate Timesheet</field>
<field name="res_model">hr.timesheet_mass_generate</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="hr_timesheet_mass_generate_view_form"/>
<field name="target">new</field>
</record>

<menuitem
id="hr_timesheet_mass_generate_menu"
name="Generate Timesheet"
parent="hr_attendance.menu_hr_time_tracking"
action="hr_timesheet_mass_generate_action"
sequence="1000"
/>

</data>
</openerp>

0 comments on commit 7996e26

Please sign in to comment.