feat(fusion_clock): NFC tap endpoint (happy path)
Add /fusion_clock/kiosk/nfc/tap JSON-RPC endpoint that toggles attendance via _attendance_action_change, writing x_fclk_clock_source='nfc_kiosk' and location on clock-in, applying break deduction/penalty checks on clock-out. Add 2 HttpCase tests (clock-in + clock-out with 6s debounce sleep). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -151,3 +151,71 @@ class TestEnrollEndpoint(HttpCase):
|
||||
'enroll_password': '1234',
|
||||
})
|
||||
self.assertEqual(result.get('error'), 'invalid_uid')
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install', 'fusion_clock')
|
||||
class TestTapEndpointHappyPath(HttpCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.ICP = cls.env['ir.config_parameter'].sudo()
|
||||
cls.ICP.set_param('fusion_clock.enable_nfc_kiosk', 'True')
|
||||
cls.ICP.set_param('fusion_clock.nfc_photo_required', 'False')
|
||||
cls.location = cls.env['fusion.clock.location'].create({
|
||||
'name': 'Tap Plant',
|
||||
'latitude': 43.65,
|
||||
'longitude': -79.38,
|
||||
'radius': 100,
|
||||
})
|
||||
cls.env.company.x_fclk_nfc_kiosk_location_id = cls.location.id
|
||||
cls.kiosk_user = cls.env['res.users'].create({
|
||||
'name': 'Tap Kiosk User',
|
||||
'login': 'nfc-kiosk-tap',
|
||||
'password': 'kioskpass123',
|
||||
'group_ids': [(4, cls.env.ref('fusion_clock.group_fusion_clock_manager').id)],
|
||||
})
|
||||
cls.alice = cls.env['hr.employee'].create({
|
||||
'name': 'Alice T',
|
||||
'x_fclk_enable_clock': True,
|
||||
'x_fclk_nfc_card_uid': '04:A2:B5:62:C1:90',
|
||||
})
|
||||
|
||||
def _tap(self, card_uid='04:A2:B5:62:C1:90', photo_b64=''):
|
||||
self.authenticate('nfc-kiosk-tap', 'kioskpass123')
|
||||
response = self.url_open(
|
||||
'/fusion_clock/kiosk/nfc/tap',
|
||||
data=json.dumps({
|
||||
'jsonrpc': '2.0',
|
||||
'method': 'call',
|
||||
'params': {'card_uid': card_uid, 'photo_b64': photo_b64},
|
||||
}),
|
||||
headers={'Content-Type': 'application/json'},
|
||||
)
|
||||
return response.json().get('result', {})
|
||||
|
||||
def test_first_tap_clocks_in(self):
|
||||
result = self._tap()
|
||||
self.assertTrue(result.get('success'))
|
||||
self.assertEqual(result.get('action'), 'clock_in')
|
||||
self.assertEqual(result.get('employee_name'), 'Alice T')
|
||||
attendance = self.env['hr.attendance'].search([
|
||||
('employee_id', '=', self.alice.id),
|
||||
], order='check_in desc', limit=1)
|
||||
self.assertTrue(attendance)
|
||||
self.assertEqual(attendance.x_fclk_clock_source, 'nfc_kiosk')
|
||||
self.assertEqual(attendance.x_fclk_location_id, self.location)
|
||||
self.assertFalse(attendance.check_out)
|
||||
|
||||
def test_second_tap_clocks_out(self):
|
||||
self._tap()
|
||||
# Wait for debounce window (5s) to elapse
|
||||
import time
|
||||
time.sleep(6)
|
||||
result = self._tap()
|
||||
self.assertTrue(result.get('success'))
|
||||
self.assertEqual(result.get('action'), 'clock_out')
|
||||
attendance = self.env['hr.attendance'].search([
|
||||
('employee_id', '=', self.alice.id),
|
||||
], order='check_in desc', limit=1)
|
||||
self.assertTrue(attendance.check_out)
|
||||
|
||||
Reference in New Issue
Block a user