Skip to content

Commit

Permalink
[IMP] hr_attendance_location_ip_check
Browse files Browse the repository at this point in the history
- Addressed issues related to pre-commit
- Updated existing documentation to be more concise
- Added roadmap planning multi-location setup and support for new odoo versions
  • Loading branch information
kongkea-aditi committed Dec 19, 2024
1 parent 4693dd4 commit d90ad1b
Show file tree
Hide file tree
Showing 20 changed files with 672 additions and 879 deletions.
282 changes: 120 additions & 162 deletions hr_attendance_location_ip_check/README.rst
Original file line number Diff line number Diff line change
@@ -1,210 +1,168 @@
==============================================
HR Attendance IP Check with Work Location CIDR
==============================================
===============================
HR Attendance Location IP Check
===============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7dbe93ccc314c4c16215d6736b4831aa7bd6d47cefce710261891c3db970622a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-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-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/16.0/hr_attendance_ip_check
:alt: OCA/hr
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--attendance-lightgray.png?logo=github
:target: https://github.com/OCA/hr-attendance/tree/16.0/hr_attendance_location_ip_check
:alt: OCA/hr-attendance
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-16-0/hr-16-0-hr_attendance_ip_check
:target: https://translation.odoo-community.org/projects/hr-attendance-16-0/hr-attendance-16-0-hr_attendance_location_ip_check
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/hr/16.0
:alt: Try me on Runbot
.. |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=16.0
:alt: Try me on Runboat

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

This module extends HR Attendance to validate check-in/out operations based on work locations' IP configuration.
It ensures employees can only record attendance when connected from authorized IP ranges, with support for
individual bypass permissions and multi-company environments.
This module adds IP-based validation to HR Attendance, ensuring employees can only check in or out from authorized work location IPs. Using CIDR ranges tied to work locations, it offers a scalable and flexible solution for managing attendance. You can configure global rules, location-specific settings, or even grant individual bypass permissions for employees. With support for multi-company environments and proper access controls, it’s designed to fit the needs of organizations with multiple locations or remote teams.

Key Features
------------
* IP-based attendance validation using CIDR ranges
* Employee-level IP check bypass with strict access control (HR Manager only)
* Prioritized evaluation of IP ranges using sequence numbers
* Multi-company security with proper access rules
* Flexible configuration at global and per-location levels
* Active/inactive network range management
* HR Manager/User permission separation
* Detailed validation messages and logging
* Scalable IP validation for enterprises with multiple work locations
* CIDR overlap detection and validation
* Comprehensive error handling and logging

Technical Features
------------------
* Extends hr.attendance for IP validation
* Implements hr.work.location.cidr for network management
* Advanced CIDR validation with overlap detection
* Extensive logging for troubleshooting
* Multi-company security enforcement
* Proper access control implementation
* Comprehensive test coverage including:
* Access control tests
* CIDR validation and overlap detection
* Multi-user scenarios
* Bypass feature validation
* Edge case handling
* Configuration changes
* Multi-company isolation

Why Work Location-Based Validation?
-----------------------------------
This module adopts a work location-based approach for IP validation by associating CIDR ranges with work locations.
This architectural decision offers several advantages:

* Scalability: Efficiently handles enterprises with multiple locations and complex network setups
* Centralized Management: Simplifies configuration and maintenance through work location grouping
* Flexible Application: Supports various deployment scenarios:
* Global policies through system settings
* Location-specific rules via work location configuration
* Individual exceptions through employee bypass settings
* Multi-company Support: Built-in isolation and security for multi-company environments
* Audit Capabilities: Comprehensive logging and tracking of attendance validations

This design particularly benefits organizations with:
* Distributed teams across multiple locations
* Complex work location structures
* Mixed office and remote work policies
* Multi-company operations
* Strict attendance compliance requirements

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

Global Settings
---------------
1. Enable IP-based attendance check:
* Navigate to Settings -> Human Resources -> Attendance
* Locate the "IP Attendance Check" section
* Activate "Enable IP-based Attendance Check"
* Work location-based IP validation using CIDR ranges
* Employee bypass options controlled by HR Managers
* Flexible setup for global and location-specific rules
* Scalable IP management for multi-location businesses
* Multi-company support with proper access controls

Work Location Setup
-------------------
1. Configure locations:
* Go to Settings -> Employees -> Work Locations
* Select or create a work location
* Enable "IP Check" option where needed
* Under "IP Attendance Check" section, add allowed IP ranges:
* Set a descriptive name (e.g., "Office Network")
* Define CIDR range (e.g., "192.168.1.0/24")
* Arrange priority using sequence handle
* Set active/inactive status as needed

For detailed configuration instructions and validation guidelines, refer to CONFIGURATION.rst.

Employee Configuration
----------------------
* Individual employees can be configured to bypass IP checks:
* Navigate to employee form -> HR Settings -> Attendance/Point of Sale
* Enable "Bypass IP Check" option (requires HR Manager access rights)
* When enabled, the employee can check in/out from any IP address
* Enables flexibility for employees who work remotely or across multiple locations

**Table of contents**

.. contents::
:local:

Usage
=====

Regular Usage
-------------
1. Employees attempt to check in/out through the Attendance interface
2. System validates:
* Global IP check status
* Work location IP check configuration
* Employee bypass status
* Current IP against allowed CIDR ranges (in sequence order)
3. Results:
* Success: Check-in/out proceeds if conditions met
* Failure: Operation blocked with specific error message

For detailed usage instructions and common scenarios, refer to USAGE.rst.

Administrator Usage
-------------------
1. Configure global settings:
* Enable/disable IP-based attendance check system-wide
* Manage work locations and their allowed IP ranges
* Configure employee bypass permissions
2. Location management:
* Configure allowed CIDR ranges per location
* Set priority order using sequence numbers
* Activate/deactivate specific ranges
3. Logs and validation:
* Validation results are logged in the backend for administrative review
* IP validation logs are available for troubleshooting but not in the UI

Example IP Configuration
------------------------
Common location setups:
* Name: "Main Office", CIDR: 192.168.1.0/24 (seq=10)
* Name: "VPN Network", CIDR: 10.0.0.0/8 (seq=20)
* Name: "Branch Office", CIDR: 172.16.0.0/12 (seq=30)

For remote locations:
* Disable IP Check to allow check-in/out from any IP address
* Or enable bypass for specific employees

Security Access Rights
----------------------
* HR Users can:
* View CIDR configurations
* View employee bypass settings
* HR Managers can:
* Create, edit, and delete CIDR configurations
* Manage all IP check settings
* Configure employee bypass permissions

Troubleshooting
Employee Check-in/out Process
-----------------------------
* Use standard attendance interface
* System validates IP address based on:
1. Global IP check status
2. Employee's work location configuration
3. Allowed CIDR ranges

* Results:
- Success: Check-in/out recorded
- Failure: Error message shown
- Bypass: Skips validation for authorized employees

Administrative Tasks
--------------------
* Configure CIDR ranges and priorities
* Manage bypass permissions
* Update or disable network ranges as needed

Development
===========

Core Components
---------------
If an employee cannot check in/out:
1. Check employee bypass status
2. Verify work location IP check status
3. For enabled locations:
* Check configured IP ranges
* Verify employee's IP against allowed ranges
* Check sequence order of IP ranges
1. Models:
* `hr_attendance.py`: IP validation logic
* `hr_work_location_cidr.py`: Network management
2. Security:
* `ir.model.access.csv`: Access control
* `security.xml`: Record rules
3. Views:
* `hr_employee_views.xml`: Employee form
* `hr_work_location_views.xml`: Location config

Testing Framework
-----------------
Includes access control tests, CIDR validation, multi-company scenarios, and bypass validations.

Contributing
------------
* Follow OCA guidelines
* Submit unit tests with changes
* Use proper commit messages

For detailed troubleshooting steps and error resolution, refer to USAGE.rst.
For technical details and logging information, consult DEVELOP.rst.
Known issues / Roadmap
======================

Current Features
----------------
- Single work location IP validation based on CIDR
- Support for bypass permissions managed by HR Managers
- Fully compatible with Odoo's default work location architecture

Future Enhancements
-------------------
- Develop a separate module to support multiple work locations per employee
- Integrate the multiple work locations module with this module for IP validation
- Ensure modularity for reuse across other HR functionalities
- Maintain backward compatibility with single work location setups
- Extend support for Odoo versions 17 and 18, including modular updates for compatibility

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_attendance_ip_check%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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_location_ip_check%0Aversion:%2016.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
=======

Contributors
~~~~~~~~~~~~

Authors
~~~~~~~

* Odoo Community Association (OCA)
* ADITI

Contributors
~~~~~~~~~~~~

* Kongkea Ouch <kongkea.ouch@camsolution.biz>
* Kongkea Ouch <kongkea.ouch@aditi.asia>
- Module design and implementation
- Test coverage
- Documentation

Acknowledgments
~~~~~~~~~~~~~~~
This module draws inspiration from the CIDR-based validation concepts proposed in `PR #168 <https://github.com/OCA/hr-attendance/pull/168>`_ by `sonhd91 <https://github.com/sonhd91>`. However, this implementation takes a different architectural approach by focusing on **work location-based IP validation**. By linking CIDR ranges directly to work locations, it provides enhanced scalability and flexibility for enterprises with multiple locations or distributed teams.

Maintainers
~~~~~~~~~~~

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

This module builds upon concepts of CIDR-based validation explored in `PR #168 <https://github.com/OCA/hr-attendance/pull/168>`_ by `sonhd91 <https://github.com/sonhd91>`_. Credit goes to the contributors of that PR for their foundational work.
This module is maintained by the OCA.

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-kongkea| image:: https://github.com/kongkea.png?size=40px
:target: https://github.com/kongkea
:alt: kongkea

Current maintainer:

|maintainer-kongkea|

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/16.0/hr_attendance_ip_check>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

Maintainers
~~~~~~~~~~~
Expand All @@ -219,6 +177,6 @@ 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.

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion hr_attendance_location_ip_check/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import models

46 changes: 19 additions & 27 deletions hr_attendance_location_ip_check/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
{
'name': "HR Attendance Location IP Check",
'version': '16.0.1.0.0',
'category': 'Human Resources/Attendances',
'summary': "Validate attendance check-in/out using work location's IP ranges (CIDR).",
'author': 'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/hr-attendance',
'license': 'AGPL-3',
'depends': [
'hr_attendance',
'hr',
"name": "HR Attendance Location IP Check",
"version": "16.0.1.0.0",
"category": "Human Resources/Attendances",
"summary": "IP check for attendance check-in/out linked to work location CIDR ranges.",
"author": "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-attendance",
"license": "AGPL-3",
"depends": ["hr_attendance", "hr"],
"data": [
"security/ir.model.access.csv",
"security/security.xml",
"views/hr_work_location_views.xml",
"views/hr_employee_views.xml",
"views/res_config_settings_views.xml",
],
'data': [
'security/ir.model.access.csv',
'security/security.xml',
'views/hr_work_location_views.xml',
'views/hr_employee_views.xml',
'views/res_config_settings_views.xml',
],
'demo': [],
'installable': True,
'application': False,
'auto_install': False,
'development_status': 'Beta',
"demo": [],
"installable": True,
"application": False,
"auto_install": False,
"development_status": "Beta",
}





Loading

0 comments on commit d90ad1b

Please sign in to comment.