blob: 7628372032fc9428920130ab4546b88f2c5d8f97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
odoo.define('pos_hr.CashierName', function (require) {
'use strict';
const CashierName = require('point_of_sale.CashierName');
const Registries = require('point_of_sale.Registries');
const useSelectEmployee = require('pos_hr.useSelectEmployee');
const { useBarcodeReader } = require('point_of_sale.custom_hooks');
const PosHrCashierName = (CashierName) =>
class extends CashierName {
constructor() {
super(...arguments);
const { selectEmployee, askPin } = useSelectEmployee();
this.askPin = askPin;
this.selectEmployee = selectEmployee;
useBarcodeReader({ cashier: this._onCashierScan });
}
mounted() {
this.env.pos.on('change:cashier', this.render, this);
}
willUnmount() {
this.env.pos.off('change:cashier', null, this);
}
async selectCashier() {
if (!this.env.pos.config.module_pos_hr) return;
const list = this.env.pos.employees
.filter((employee) => employee.id !== this.env.pos.get_cashier().id)
.map((employee) => {
return {
id: employee.id,
item: employee,
label: employee.name,
isSelected: false,
};
});
const employee = await this.selectEmployee(list);
if (employee) {
this.env.pos.set_cashier(employee);
}
}
async _onCashierScan(code) {
const employee = this.env.pos.employees.find(
(emp) => emp.barcode === Sha1.hash(code.code)
);
if (!employee || employee === this.env.pos.get_cashier()) return;
if (!employee.pin || (await this.askPin(employee))) {
this.env.pos.set_cashier(employee);
}
}
};
Registries.Component.extend(CashierName, PosHrCashierName);
return CashierName;
});
|