Skip to content

Commit

Permalink
⚡ hex option in base.config.settings
Browse files Browse the repository at this point in the history
  • Loading branch information
KolushovAlexandr committed Mar 14, 2019
1 parent ca583ca commit 45e40f7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
2 changes: 1 addition & 1 deletion base_attendance/doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-------

- **New:** Autocheckout option - closes shifts after defined time
- **New:** HEX barcode scanners support for **Kiosk Mode**
- **New:** Option to suppert HEX barcode scanners in **Kiosk Mode**
- **Fix:** Error related to incorrect attribute name

`1.0.0`
Expand Down
15 changes: 14 additions & 1 deletion base_attendance/models/res_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class BaseConfigSettings(models.TransientModel):
help='Enable or disable partner PIN identification at check in',
implied_group="base_attendance.group_hr_attendance_use_pin")
shift_autocheckout = fields.Integer('Autocheckout ', help="Maximum Shift Time in Minutes")
hex_scanner_is_used = fields.Boolean('HEX Scanner', default=False,
help='Some devices scan regular barcodes as hexadecimal. '
'This option decode those types of barcodes')

@api.multi
def set_shift_autocheckout(self):
self.env["ir.config_parameter"].set_param("base_attendance.shift_autocheckout", self.shift_autocheckout)
self.env["ir.config_parameter"].set_param("base_attendance.shift_autocheckout", self.shift_autocheckout or '0')
self.checkout_shifts()

@api.multi
Expand All @@ -37,3 +40,13 @@ def checkout_shifts(self):
cron_record.write({
'active': True,
})

@api.multi
def set_hex_scanner_is_used(self):
self.env["ir.config_parameter"].set_param("base_attendance.hex_scanner_is_used", self.hex_scanner_is_used)

@api.multi
def get_default_hex_scanner_is_used(self, fields):
hex_scanner_is_used = self.env["ir.config_parameter"].get_param("base_attendance.hex_scanner_is_used",
default=False)
return {'hex_scanner_is_used': hex_scanner_is_used}
40 changes: 28 additions & 12 deletions base_attendance/static/src/js/kiosk_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var core = require('web.core');
var Model = require('web.Model');
var Widget = require('web.Widget');
var Session = require('web.session');
var local_storage = require('web.local_storage');
var BarcodeHandlerMixin = require('barcodes.BarcodeHandlerMixin');

var QWeb = core.qweb;
Expand All @@ -27,9 +28,27 @@ var KioskMode = Widget.extend(BarcodeHandlerMixin, {
// We added a local variable for this._super in order to fix the nextLINT error
//"Expected an assignment or function call and instead saw an expression. [Error/no-unused-expressions]"
var init_super = this._super;

action.target = 'fullscreen';
var hex_scanner_is_used = action.context.hex_scanner_is_used;
if (typeof hex_scanner_is_used === 'undefined') {
hex_scanner_is_used = this.get_from_storage('hex_scanner_is_used') || false;
} else {
this.save_locally('hex_scanner_is_used', Boolean(hex_scanner_is_used));
}
this.hex_scanner_is_used = hex_scanner_is_used;

BarcodeHandlerMixin.init.apply(this, arguments);
},

save_locally: function(key, value) {
local_storage.setItem('est.' + key, JSON.stringify(value));
},

get_from_storage: function(key) {
return JSON.parse(local_storage.getItem('est.' + key));
},

start: function () {
var self = this;
self.session = Session;
Expand All @@ -49,21 +68,18 @@ var KioskMode = Widget.extend(BarcodeHandlerMixin, {
on_barcode_scanned: function(barcode) {
var self = this;
var hr_employee = new Model('res.partner');
hr_employee.call('attendance_scan', [barcode, ]).then(function (result) {
var res_barcode = barcode;
if (this.hex_scanner_is_used) {
res_barcode = parseInt(barcode, 16).toString();
if (res_barcode.length % 2) {
res_barcode = '0' + res_barcode;
}
}
hr_employee.call('attendance_scan', [res_barcode, ]).then(function (result) {
if (result.action) {
self.do_action(result.action);
} else if (result.warning) {
var unhexed_code = parseInt(barcode, 16).toString();
if (unhexed_code.length % 2) {
unhexed_code = '0' + unhexed_code;
}
hr_employee.call('attendance_scan', [unhexed_code, ]).then(function (res) {
if (res.action) {
self.do_action(res.action);
} else if (res.warning) {
self.do_warn(result.warning);
}
});
self.do_warn(result.warning);
}
});
},
Expand Down
19 changes: 15 additions & 4 deletions base_attendance/views/res_attendance_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,21 @@
<field name="view_id"></field> <!-- force empty -->
</record>

<record id="hr_attendance_action_kiosk_mode" model="ir.actions.client">
<field name="name">Attendances</field>
<field name="tag">base_attendance_kiosk_mode</field>
<field name="target">fullscreen</field>
<record model="ir.actions.server" id="hr_attendance_action_kiosk_mode">
<field name="name">Get to the Kiosk Mode</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_res_partner_attendance"/>
<field name="code">
hex_scanner_is_used = model.env["ir.config_parameter"].get_param("base_attendance.hex_scanner_is_used",default=False)
action = {
'type': 'ir.actions.client',
'tag': 'base_attendance_kiosk_mode',
'target': 'fullscreen',
'context': {
'hex_scanner_is_used': hex_scanner_is_used
},
}
</field>
</record>

<record id="hr_attendance_action_greeting_message" model="ir.actions.client">
Expand Down
1 change: 1 addition & 0 deletions base_attendance/views/res_config_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<button string="Cancel" type="object" name="cancel" class="oe_link" special="cancel"/>
</header>
<group string="Settings">
<field name="hex_scanner_is_used"/>
<field name="group_attendance_use_pin" widget="radio"/>
<field name="shift_autocheckout"/>
</group>
Expand Down

0 comments on commit 45e40f7

Please sign in to comment.