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][MIG] thingsintouch_ras_simplified #1

Open
wants to merge 5 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
20 changes: 20 additions & 0 deletions thingsintouch_ras_simplified/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
============================================================
Simplified Template to configure new RFID Attendance Devices
============================================================

This simplified template delivers the configuration needed to define new RAS2 devices on the OCA-IoT Modules.


Credits
=======

Authors
~~~~~~~

* Creu Blanca
* thingsintouch.com

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

This module is maintained by thingsintouch.com
1 change: 1 addition & 0 deletions thingsintouch_ras_simplified/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions thingsintouch_ras_simplified/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (C) 2018 Creu Blanca
# Copyright (C) 2024 thingsintouch.com
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "RAS Simplified Configuration for IoT/OCA",
"version": "17.0.1.0.0",
"category": "IoT",
"author": "Creu Blanca , "
"thingsintouch.com",
"website": "https://github.com/thingsintouch/iot-devices",
"license": "AGPL-3",
"installable": True,
"summary": "Simplified Template and Functionality to define new RAS Devices for OCA-IoT Modules",
"depends": ["hr_attendance_rfid", "iot_template_oca"],
"data": ["data/ras_simplified_template.xml"],
}
13 changes: 13 additions & 0 deletions thingsintouch_ras_simplified/data/ras_simplified_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="ras_simplified_template" model="iot.template">
<field name="name">thingsintouch.ras_simplified</field>
</record>
<record id="ras_template_input_async" model="iot.template.input">
<field name="template_id" ref="ras_simplified_template"/>
<field name="name">async_clocking</field>
<field name="call_model_id" ref="hr.model_hr_employee"/>
<field name="call_function">register_attendance_async</field>
<field name="params">{}</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions thingsintouch_ras_simplified/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_employee
18 changes: 18 additions & 0 deletions thingsintouch_ras_simplified/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 thingsintouch.com
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, models

from datetime import datetime

import freezegun


class HrEmployee(models.Model):
_inherit = "hr.employee"

@api.model
def register_attendance_async(self, card_code, timestamp):
with freezegun.freeze_time(datetime.fromtimestamp(int(timestamp), tz=None)):
result = self.register_attendance(card_code)
return result
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions thingsintouch_ras_simplified/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_thingsintouch_ras_simplified
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import time
from odoo.tests.common import HttpCase
from odoo.tests import new_test_user

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestThingsintouchRasSimplified(HttpCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
user = new_test_user(
cls.env,
login="ras_rfid-user",
groups="hr_attendance_rfid.group_hr_attendance_rfid,base.group_user",
)
cls.rfid_card_code = "5b3f5"
cls.device_serial_number = "ABC00001"
cls.env["hr.employee"].create(
{"user_id": user.id, "rfid_card_code": cls.rfid_card_code}
)
cls.employee_model = cls.env["hr.employee"]
cls.device_modal = cls.env["iot.device"]
cls.template = cls.env.ref(
"thingsintouch_ras_simplified.ras_simplified_template"
)

def action_request(self, device_input):
url = f"/iot/{device_input.serial}/action"
data = {
"passphrase": device_input.passphrase,
"card_code": self.rfid_card_code,
"timestamp": round(time.time()),
}
return self.url_open(url, data).json()

def test_01_device_register_with_template_and_action(self):
wizard = self.env["iot.device.configure"].create(
{"serial": self.device_serial_number}
)
device_config = self.url_open(
wizard.url,
data={"template": self.template.name},
).json()
device = self.device_modal.search([("name", "=", device_config["name"])])
self.assertTrue(device)
self.assertEqual(1, len(device))
self.assertEqual(1, len(device.input_ids))
self.assertEqual(0, len(device.output_ids))
device_input = device.input_ids
# action login
res = self.action_request(device_input)
self.assertTrue("action" in res and res["action"] == "check_in")
self.assertTrue("logged" in res and res["logged"])
self.assertTrue(
"rfid_card_code" in res and res["rfid_card_code"] == self.rfid_card_code
)
# action login
res = self.action_request(device_input)
self.assertTrue("action" in res and res["action"] == "check_out")
self.assertTrue("logged" in res and res["logged"])