Skip to content
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
73 changes: 73 additions & 0 deletions iot_ras_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
========
IoT Base
========

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fiot-lightgray.png?logo=github
:target: https://github.com/OCA/iot/tree/11.0/iot
:alt: OCA/iot
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/iot-11-0/iot-11-0-iot
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/269/11.0
:alt: Try me on Runbot

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

This addon is a base module used for all iot modules.

**Table of contents**

.. contents::
:local:

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

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

* Creu Blanca

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

* Enric Tobella <[email protected]>

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.

This module is part of the `OCA/iot <https://github.com/OCA/iot/tree/11.0/iot>`_ 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 iot_ras_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions iot_ras_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "IoT Templates",
"version": "16.0.1.0.0",
"category": "IoT",
"author": "CreuBlanca",
"license": "AGPL-3",
"installable": True,
"summary": "IoT base module",
"depends": ["iot_template_oca", "hr_attendance_rfid"],
"data": ["data/ras_template.xml"],
"website": "https://github.com/tegin/cb-addons",
}
14 changes: 14 additions & 0 deletions iot_ras_oca/data/ras_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="ras_template" model="iot.template">
<field name="name">eficent.ras</field>
</record>
<record id="ras_template_input" model="iot.template.input">
<field name="template_id" ref="ras_template" />
<field name="name">rfid_read</field>
<field name="call_model_id" eval="False" />
<field name="call_function">iot_ras_default_action</field>
<field name="params">{}</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions iot_ras_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_employee
from . import iot_device_input
25 changes: 25 additions & 0 deletions iot_ras_oca/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 Comunitea Servicios Tecnológicos S.L.
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import logging

from odoo import _, api, models

_logger = logging.getLogger(__name__)


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

@api.model
def register_attendance(self, card_code):
res = super().register_attendance(card_code)
if "action" in res:
if res["action"] == "check_in":
res["action_msg"] = _("Checked in %s") % res["employee_name"]
elif res["action"] == "check_out":
res["action_msg"] = _("Checked out %s") % res["employee_name"]
elif res["action"] == "FALSE":
res["action_msg"] = _("Contact your admin")
return res
9 changes: 9 additions & 0 deletions iot_ras_oca/models/iot_device_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import api, models


class IotDeviceInput(models.Model):
_inherit = "iot.device.input"

@api.model
def iot_ras_default_action(self, message):
return {"action_msg": message, "action": "check_in"}
1 change: 1 addition & 0 deletions iot_ras_oca/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_ras
84 changes: 84 additions & 0 deletions iot_ras_oca/tests/test_ras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from odoo.tests.common import HttpCase


class TestRas(HttpCase):
def setUp(self):
super().setUp()
self.card_code = "e313441e"
self.employee = self.env["hr.employee"].create(
{"name": "Anita", "rfid_card_code": self.card_code}
)
self.template = self.env.ref("iot_ras_oca.ras_template")

def _get_wizard(self):
wizard = self.env["iot.device.configure"].create({})
self.assertTrue(wizard.serial)
self.assertTrue(wizard.url)
return wizard

def test_generation(self):
wizard = self._get_wizard()
device_config = self.url_open(
wizard.url, data={"template": self.template.name}
).json()
device = self.env["iot.device"].search([("name", "=", device_config["name"])])
self.assertTrue(device)
ras_input = device.input_ids
self.assertTrue(ras_input)
self.assertTrue(ras_input.serial)
self.assertTrue(ras_input.passphrase)
res = self.url_open(
"/iot/%s/action" % ras_input.serial,
data={"passphrase": ras_input.passphrase, "value": "123"},
).json()
# This should work properly because it has not been assigned to
# Checking attendance
self.assertEqual(res["status"], "ok")

ras_input.write(
{
"call_model_id": self.env.ref("hr.model_hr_employee").id,
"call_function": "register_attendance",
}
) # We are assigning it to the proper function and model

res = self.url_open(
"/iot/%s/action" % ras_input.serial,
data={"passphrase": ras_input.passphrase, "value": "123"},
).json()
# Now it must fail as the value is not correct
self.assertEqual(res["status"], "ok")
self.assertIn("error_message", res)
self.assertRegex(res["error_message"], ".*No employee found.*")
self.assertFalse(
self.env["hr.attendance"].search([("employee_id", "=", self.employee.id)])
)
res = self.url_open(
"/iot/%s/action" % ras_input.serial,
data={"passphrase": ras_input.passphrase, "value": self.card_code},
).json()
# The employee has checked in
self.assertEqual(res["status"], "ok")
self.assertEqual(res["action"], "check_in")
self.assertEqual(res["error_message"], "")
attendance = self.env["hr.attendance"].search(
[("employee_id", "=", self.employee.id)]
)
self.assertTrue(attendance)
self.assertEqual(1, len(attendance))
self.assertFalse(attendance.check_out)
res = self.url_open(
"/iot/%s/action" % ras_input.serial,
data={"passphrase": ras_input.passphrase, "value": self.card_code},
).json()
# The employee has checked out
self.assertEqual(res["status"], "ok")
self.assertEqual(res["action"], "check_out")
self.assertEqual(res["error_message"], "")
attendance = self.env["hr.attendance"].search(
[("employee_id", "=", self.employee.id)]
)
attendance.invalidate_recordset()
self.assertTrue(attendance)
self.assertEqual(1, len(attendance))
self.assertTrue(attendance.check_out)
1 change: 1 addition & 0 deletions setup/iot_ras_oca/odoo/addons/iot_ras_oca
6 changes: 6 additions & 0 deletions setup/iot_ras_oca/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)