Skip to content

Commit

Permalink
Merge 3c58857 into 8844d7d
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Nov 2, 2020
2 parents 8844d7d + 3c58857 commit fdcf929
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 50 deletions.
22 changes: 13 additions & 9 deletions hr_timesheet_mass_generate/README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
.. 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.
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-open--synergy%2Fopnsynid--hr-lightgray.png?logo=github
:target: https://github.com/open-synergy/opnsynid-hr/tree/8.0/hr_timesheet_mass_generate
:alt: open-synergy/opnsynid-hr

|badge2| |badge3|

Installation
============
Expand All @@ -27,12 +30,13 @@ 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
.. image:: https://simetri-sinergi.id/logo.png
:alt: PT. Simetri Sinergi Indonesia
:target: https://simetri-sinergi.id.com

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

from . import wizards
from . import (
wizards,
)
15 changes: 11 additions & 4 deletions hr_timesheet_mass_generate/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# Copyright 2020 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# pylint: disable=locally-disabled, manifest-required-author
{
"name": "Mass Generate Timesheet",
"version": "8.0.1.0.0",
"version": "8.0.1.0.1",
"category": "Human Resources",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
"website": "https://simetri-sinergi.id",
"author": "OpenSynergy Indonesia, PT. Simetri Sinergi Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": ["hr_timesheet_sheet"],
"depends": [
"hr_timesheet_sheet",
],
"data": [
"wizards/hr_timesheet_mass_generate.xml"
],
"images": [
"static/description/banner.png",
],
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hr_timesheet_mass_generate/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions hr_timesheet_mass_generate/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- 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
# Copyright 2020 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import (
hr_timesheet_mass_generate,
)
76 changes: 45 additions & 31 deletions hr_timesheet_mass_generate/wizards/hr_timesheet_mass_generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2020 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api, _
from datetime import datetime
Expand Down Expand Up @@ -41,41 +42,54 @@ def _check_date(self):
if self.date_from > self.date_to:
raise ValidationError(strWarning)

@api.multi
def _prepare_data_timesheet(self, employee):
data = {}
if self._check_data(employee):
data = {
"employee_id": employee.id,
"date_from": self.date_from,
"date_to": self.date_to
}
return data

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

if not employee.user_id:
raise ValidationError(
_("Employee {name} must be linked to a user.".format(
name=employee.name)))

if not employee.journal_id:
raise ValidationError(
_("Employee {name} must have analytic journal.".format(
name=employee.name)))

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)))
return True

@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)
data = self._prepare_data_timesheet(employee)
obj_hr_timesheet_sheet.create(data)

return {"type": "ir.actions.act_window_close"}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
action="hr_timesheet_mass_generate_action"
sequence="1000"
/>

</data>
</openerp>

0 comments on commit fdcf929

Please sign in to comment.