Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][ADD]hr_attendance_work_model #213

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def test_employee_edit(self):
{"employee_id": self.employee.id, "check_in": dt.strftime(DF)}
)
self.hr_attendance.check_for_incomplete_attendances()
# worked_hours are now 10 hours, because Odoo adds 1 hour to lunch, see:
# https://github.com/odoo/odoo/commit/2eda54348de1bd42fc2a1bed94cd8b7a3ebf405d
self.assertEqual(att.worked_hours, 10.0, "Attendance not closed")
self.assertEqual(att.worked_hours, 11.0, "Attendance not closed")
reason = self.env.company.hr_attendance_autoclose_reason
reason.unlink()
dti += relativedelta(hours=10)
Expand Down
92 changes: 92 additions & 0 deletions hr_attendance_work_model/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
=====================
Attendance Work Model
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6925cd9b3a13b0f3fa4b20d5440b0ca7dee18cb408d7c6ef111362ccc93c6d64
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--attendance-lightgray.png?logo=github
:target: https://github.com/OCA/hr-attendance/tree/17.0/hr_attendance_work_model
:alt: OCA/hr-attendance
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-attendance-17-0/hr-attendance-17-0-hr_attendance_work_model
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-attendance&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon adds the field **Work Model Type** to Attendances, so the
work model of each attendance can be tracked.

**Table of contents**

.. contents::
:local:

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

In order to distinguish which are the Attendances are remote, it will be
needed to specify the IP Addresses that belong to the Office/s for each
company on it's form view.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-attendance/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/OCA/hr-attendance/issues/new?body=module:%20hr_attendance_work_model%0Aversion:%2017.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.

Credits
=======

Authors
-------

* ForgeFlow S.L.

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

- Guillem Casassas <guillem.casassas@forgeflow.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-GuillemCForgeFlow| image:: https://github.com/GuillemCForgeFlow.png?size=40px
:target: https://github.com/GuillemCForgeFlow
:alt: GuillemCForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-GuillemCForgeFlow|

This module is part of the `OCA/hr-attendance <https://github.com/OCA/hr-attendance/tree/17.0/hr_attendance_work_model>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions hr_attendance_work_model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions hr_attendance_work_model/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2025 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
{
"name": "Attendance Work Model",
"summary": """
Trace the Work Model of the attendances
""",
"version": "17.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/hr-attendance",
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
"maintainers": ["GuillemCForgeFlow"],
"license": "LGPL-3",
"depends": ["hr_attendance"],
"data": [
"security/ir.model.access.csv",
"views/hr_attendance_views.xml",
"views/res_company_views.xml",
],
}
86 changes: 86 additions & 0 deletions hr_attendance_work_model/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_attendance_work_model
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-03-10 12:56+0000\n"
"PO-Revision-Date: 2025-03-10 12:56+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: hr_attendance_work_model
#: model:ir.model,name:hr_attendance_work_model.model_hr_attendance
msgid "Attendance"
msgstr "Asistencia"

#. module: hr_attendance_work_model
#: model:ir.model,name:hr_attendance_work_model.model_res_company
msgid "Companies"
msgstr "Compañías"

#. module: hr_attendance_work_model
#: model:ir.model,name:hr_attendance_work_model.model_res_company_ip_address
msgid "Company's IP Addresses"
msgstr "Direcciones IP de la compañía"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company_ip_address__create_uid
msgid "Created by"
msgstr "Creado por"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company_ip_address__create_date
msgid "Created on"
msgstr "Creado el"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company_ip_address__display_name
msgid "Display Name"
msgstr "Nombre"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company_ip_address__id
msgid "ID"
msgstr "ID"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company_ip_address__write_uid
msgid "Last Updated by"
msgstr "Última actualización por"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company_ip_address__write_date
msgid "Last Updated on"
msgstr "Última actualización el"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company_ip_address__name
msgid "Name"
msgstr "Nombre"

#. module: hr_attendance_work_model
#: model:ir.model.fields.selection,name:hr_attendance_work_model.selection__hr_attendance__work_model_type__office
msgid "Office"
msgstr "Oficina"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_res_company__office_ip_address_ids
msgid "Offices' IP Addresses"
msgstr "Direcciones IP de las oficinas"

#. module: hr_attendance_work_model
#: model:ir.model.fields.selection,name:hr_attendance_work_model.selection__hr_attendance__work_model_type__remote
msgid "Remote"
msgstr "Remoto"

#. module: hr_attendance_work_model
#: model:ir.model.fields,field_description:hr_attendance_work_model.field_hr_attendance__work_model_type
msgid "Work Model"
msgstr "Modelo de trabajo"
3 changes: 3 additions & 0 deletions hr_attendance_work_model/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import hr_attendance
from . import res_company_ip_address
from . import res_company
40 changes: 40 additions & 0 deletions hr_attendance_work_model/models/hr_attendance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from odoo import api, fields, models


class HrAttendance(models.Model):
_inherit = "hr.attendance"

work_model_type = fields.Selection(
selection=[
("office", "Office"),
("remote", "Remote"),
],
string="Work Model",
compute="_compute_work_model_type",
store=True,
)

@api.depends(
"employee_id.company_id.office_ip_address_ids",
"in_ip_address",
"out_ip_address",
)
def _compute_work_model_type(self):
office_ip_address_by_company_dict = {
company.id: [
ip_address.name for ip_address in company.office_ip_address_ids
]
for company in self.env["res.company"].search([])
}
for attendance in self:
company_id = attendance.employee_id.company_id.id
office_ip_addresses = office_ip_address_by_company_dict.get(
company_id, False
)
work_model_type = "office"
ip_address = attendance.out_ip_address or attendance.in_ip_address
for office_ip_address in office_ip_addresses:
if office_ip_address and ip_address and ip_address != office_ip_address:
work_model_type = "remote"
break

Check warning on line 39 in hr_attendance_work_model/models/hr_attendance.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_work_model/models/hr_attendance.py#L38-L39

Added lines #L38 - L39 were not covered by tests
attendance.work_model_type = work_model_type
9 changes: 9 additions & 0 deletions hr_attendance_work_model/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

office_ip_address_ids = fields.Many2many(
comodel_name="res.company.ip.address", string="Offices' IP Addresses"
)
8 changes: 8 additions & 0 deletions hr_attendance_work_model/models/res_company_ip_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


class ResCompanyIPAddress(models.Model):
_name = "res.company.ip.address"
_description = "Company's IP Addresses"

name = fields.Char(required=True)
3 changes: 3 additions & 0 deletions hr_attendance_work_model/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions hr_attendance_work_model/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In order to distinguish which are the Attendances are remote, it will be needed to
specify the IP Addresses that belong to the Office/s for each company on it's form view.
1 change: 1 addition & 0 deletions hr_attendance_work_model/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Guillem Casassas \<<guillem.casassas@forgeflow.com>\>
2 changes: 2 additions & 0 deletions hr_attendance_work_model/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This addon adds the field **Work Model Type** to Attendances, so the work model of each
attendance can be tracked.
3 changes: 3 additions & 0 deletions hr_attendance_work_model/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_res_company_ip_address,access_res_company_ip_address,model_res_company_ip_address,base.group_user,1,0,0,0
access_res_company_ip_address_manager,access_res_company_ip_address_manager,model_res_company_ip_address,hr_attendance.group_hr_attendance_manager,1,1,1,1
Loading