Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
language: fail
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
- repo: https://github.com/oca/maintainer-tools
rev: d5fab7ee87fceee858a3d01048c78a548974d935
rev: 71aa4caec15e8c1456b4da19e9f39aa0aa7377a9
hooks:
# update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons
Expand All @@ -54,14 +54,14 @@ repos:
- --if-source-changed
- --keep-source-digest
- repo: https://github.com/OCA/odoo-pre-commit-hooks
rev: v0.0.25
rev: v0.1.7
hooks:
- id: oca-checks-odoo-module
- id: oca-checks-po
args:
- --disable=po-pretty-format
- repo: https://github.com/myint/autoflake
rev: v1.5.3
rev: v2.3.1
hooks:
- id: autoflake
args:
Expand All @@ -72,7 +72,7 @@ repos:
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 25.11.0
hooks:
- id: black
- repo: local
Expand Down Expand Up @@ -106,7 +106,7 @@ repos:
- "eslint-plugin-jsdoc@"
- "globals@"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
# exclude autogenerated files
Expand All @@ -128,20 +128,20 @@ repos:
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
rev: v3.21.2
hooks:
- id: pyupgrade
args: ["--keep-percent-format"]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 7.0.0
hooks:
- id: isort
name: isort except __init__.py
args:
- --settings=.
exclude: /__init__\.py$
- repo: https://github.com/acsone/setuptools-odoo
rev: 3.1.8
rev: 3.3.1
hooks:
- id: setuptools-odoo-make-default
- id: setuptools-odoo-get-requirements
Expand All @@ -151,13 +151,13 @@ repos:
- --header
- "# generated from manifests external_dependencies"
- repo: https://github.com/PyCQA/flake8
rev: 5.0.0
rev: 7.3.0
hooks:
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==20.1.4"]
- repo: https://github.com/OCA/pylint-odoo
rev: 7.0.2
rev: v9.3.22
hooks:
- id: pylint_odoo
name: pylint with optional checks
Expand Down
64 changes: 62 additions & 2 deletions hr_data_import/models/hr_data_import_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ class ImportEmployee(models.Model):
comodel_name="hr.policy.group",
)
related_employee_id = fields.Many2one("hr.employee")
state = fields.Selection([("new", "New"), ("imported", "Imported")], default="new")
state = fields.Selection(
[("new", "New"), ("imported", "Imported"), ("updated", "Updated")],
default="new",
)
company_id = fields.Many2one("res.company", default=lambda s: s.env.company)
currency_id = fields.Many2one(
string="Currency", related="company_id.currency_id", readonly=True
Expand All @@ -94,18 +97,33 @@ class ImportEmployee(models.Model):
anlv_used = fields.Float("Used", digits=DA_LEAVE, default=0.00)
anlv_remain = fields.Float("Remaining", digits=DA_LEAVE, default=0.00)
anlv_date = fields.Date("As of")
rest_day = fields.Selection(
selection=[
("Monday", "Monday"),
("Tuesday", "Tuesday"),
("Wednesday", "Wednesday"),
("Thursday", "Thursday"),
("Friday", "Friday"),
("Saturday", "Saturday"),
("Sunday", "Sunday"),
("out", False),
]
)

def action_import_employees(self):
if self.filtered(lambda so: so.state != "new"):
raise UserError(_("Only new records can be imported."))
self.import_records()
self.write({"state": "imported"})

def action_update_employees(self):
self.update_records()
self.write({"state": "updated"})

def import_records(self):

partner_obj = self.env["res.partner"]

# Create the basic hr.employee record
values_list = []
for rec in self:
# Create contact
Expand All @@ -119,6 +137,8 @@ def import_records(self):
"vat": (rec.taxid) and rec.taxid or False,
}
)

# Create the basic hr.employee record
val = {
"name": rec.name,
"import_data_id": rec.id,
Expand Down Expand Up @@ -165,6 +185,18 @@ def import_records(self):
# Additional changes to system
self.create_contracts(employees)
self.create_annual_leave_allocation(employees)
self.set_rest_day(employees)

return employees

def update_records(self):

employees = self.env["hr.employee"].search(
["id", "in", self.mapped("related_employee_id.id")]
)

# Additional changes to system
self.set_rest_day(employees)

return employees

Expand Down Expand Up @@ -244,3 +276,31 @@ def get_leave_days_accrued(self, employee, hire_date):
accrued_todate += (delta.days / 30) * monthly_accrual

return accrued_todate

def set_rest_day(self, employees):

mon = self.env.ref("resource_schedule.wd_mon")
tue = self.env.ref("resource_schedule.wd_tue")
wed = self.env.ref("resource_schedule.wd_wed")
thu = self.env.ref("resource_schedule.wd_thu")
fri = self.env.ref("resource_schedule.wd_fri")
sat = self.env.ref("resource_schedule.wd_sat")
sun = self.env.ref("resource_schedule.wd_sun")

for ee in employees:
resource = ee.resource_id
data_id = self.filtered(lambda s, ee=ee: s.related_employee_id.id == ee.id)
if data_id.rest_day == "Monday" and mon not in resource.dayoff_ids:
resource.dayoff_ids = [(4, mon.id)]
elif data_id.rest_day == "Tuesday" and tue not in resource.dayoff_ids:
resource.dayoff_ids = [(4, tue.id)]
elif data_id.rest_day == "Wednesday" and wed not in resource.dayoff_ids:
resource.dayoff_ids = [(4, wed.id)]
elif data_id.rest_day == "Thursday" and thu not in resource.dayoff_ids:
resource.dayoff_ids = [(4, thu.id)]
elif data_id.rest_day == "Friday" and fri not in resource.dayoff_ids:
resource.dayoff_ids = [(4, fri.id)]
elif data_id.rest_day == "Saturday" and sat not in resource.dayoff_ids:
resource.dayoff_ids = [(4, sat.id)]
elif data_id.rest_day == "Sunday" and sun not in resource.dayoff_ids:
resource.dayoff_ids = [(4, sun.id)]
26 changes: 26 additions & 0 deletions hr_data_import/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def setUpClass(cls):
"name": "Default Policy Group",
}
)
cls.default_rest_day = "Friday"
cls.data = cls.DataImport.create(
[
{
Expand All @@ -87,6 +88,7 @@ def setUpClass(cls):
"struct_id": cls.pay_structure.id,
"pps_id": cls.pps.id,
"policy_group_id": cls.policy_group.id,
"rest_day": cls.default_rest_day,
},
{
"name": "John Doe",
Expand Down Expand Up @@ -119,6 +121,7 @@ def setUpClass(cls):
"struct_id": cls.pay_structure.id,
"pps_id": cls.pps.id,
"policy_group_id": cls.policy_group.id,
"rest_day": cls.default_rest_day,
}

def test_workflow(self):
Expand Down Expand Up @@ -178,6 +181,18 @@ def test_workflow(self):
"trial",
f"Employee's contract is in 'trial' state: {rec.name}",
)
if rec.rest_day:
self.assertEqual(
rec.related_employee_id.resource_id.dayoff_ids[0].name,
self.default_rest_day,
f"Employee's rest day matches imported record: {rec.name}",
)
else:
self.assertFalse(
rec.related_employee_id.resource_id.dayoff_ids,
f"Employee's rest day is empty as no value was imported: {rec.name}",
)

self.assertEqual(
rec.state,
"imported",
Expand Down Expand Up @@ -221,3 +236,14 @@ def test_set_value_calendar(self):
self.std_calendar,
f"Calendar correctly set on employee contract: {ee.name}",
)

def test_rest_day(self):
self.data[1].rest_day = self.default_rest_day
self.data.import_records()
ee = self.Employee.search([("name", "=", self.data[1].name)])
self.assertTrue(ee, f"Found employee: {self.data[1].name}")
self.assertEqual(
ee.resource_id.dayoff_ids[0].name,
self.default_rest_day,
f"Calendar correctly set on employee contract: {ee.name}",
)
19 changes: 19 additions & 0 deletions hr_data_import/views/hr_data_import_employee_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
name="state_imported"
domain="[('state', '=', 'imported')]"
/>
<filter
string="State: Updated"
name="state_updated"
domain="[('state', '=', 'updated')]"
/>
<separator />
<group expand="0" string="Group By">
<filter
Expand Down Expand Up @@ -75,6 +80,7 @@
<field name="hire_date" />
<field name="department_id" />
<field name="job_id" />
<field name="rest_day" />
<field name="date_start" />
<field name="wage" />
<field name="contract_type_id" />
Expand Down Expand Up @@ -116,6 +122,7 @@
<field name="private_phone" />
<field name="hire_date" />
<field name="resource_calendar_id" />
<field name="rest_day" />
</group>
<group>
<field name="wage" />
Expand Down Expand Up @@ -174,4 +181,16 @@
<field name="code">action = records.action_import_employees()</field>
</record>

<record id="action_update_records" model="ir.actions.server">
<field name="name">Update HR Records</field>
<field name="model_id" ref="hr_data_import.model_hr_data_import_employee" />
<field
name="binding_model_id"
ref="hr_data_import.model_hr_data_import_employee"
/>
<field name="binding_view_types">list,form</field>
<field name="state">code</field>
<field name="code">action = records.action_update_employees()</field>
</record>

</odoo>
12 changes: 6 additions & 6 deletions resource_schedule/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Employee Shift Scheduling
.. |badge2| image:: https://img.shields.io/badge/license-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-trevi--software%2Ftrevi--hr-lightgray.png?logo=github
:target: https://github.com/trevi-software/trevi-hr/tree/14.0/resource_schedule
:alt: trevi-software/trevi-hr
.. |badge3| image:: https://img.shields.io/badge/github-TREVI Software%2Ftrevi--hr-lightgray.png?logo=github
:target: https://github.com/TREVI Software/trevi-hr/tree/14.0/resource_schedule
:alt: TREVI Software/trevi-hr

|badge1| |badge2| |badge3|

Expand All @@ -48,10 +48,10 @@ Known issues / Roadmap
Bug Tracker
===========

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

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -72,6 +72,6 @@ Other credits
Maintainers
~~~~~~~~~~~

This module is part of the `trevi-software/trevi-hr <https://github.com/trevi-software/trevi-hr/tree/14.0/resource_schedule>`_ project on GitHub.
This module is part of the `TREVI Software/trevi-hr <https://github.com/TREVI Software/trevi-hr/tree/14.0/resource_schedule>`_ project on GitHub.

You are welcome to contribute.
8 changes: 4 additions & 4 deletions resource_schedule/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ <h1>Employee Shift Scheduling</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:aab37bcd04a753c60d86ce355854f9ef0080171ee9158e60ab0d97be904f3cf1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/trevi-software/trevi-hr/tree/14.0/resource_schedule"><img alt="trevi-software/trevi-hr" src="https://img.shields.io/badge/github-trevi--software%2Ftrevi--hr-lightgray.png?logo=github" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/TREVISoftware/trevi-hr/tree/14.0/resource_schedule"><img alt="TREVI Software/trevi-hr" src="https://img.shields.io/badge/github-TREVISoftware%2Ftrevi--hr-lightgray.png?logo=github" /></a></p>
<p>Easily create, manage, and track employee shift planning.</p>
<ol class="arabic simple">
<li>Work Detail Templates - templates describe a shift for one day. For example: 8 a.m to 5 p.m.</li>
Expand Down Expand Up @@ -405,10 +405,10 @@ <h2><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h2>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/trevi-software/trevi-hr/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/TREVISoftware/trevi-hr/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/trevi-software/trevi-hr/issues/new?body=module:%20resource_schedule%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/TREVISoftware/trevi-hr/issues/new?body=module:%20resource_schedule%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -428,7 +428,7 @@ <h3><a class="toc-backref" href="#toc-entry-5">Other credits</a></h3>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
<p>This module is part of the <a class="reference external" href="https://github.com/trevi-software/trevi-hr/tree/14.0/resource_schedule">trevi-software/trevi-hr</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/TREVISoftware/trevi-hr/tree/14.0/resource_schedule">TREVI Software/trevi-hr</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
</div>
Expand Down
Loading