summaryrefslogtreecommitdiff
path: root/addons/pos_hr/static/src/js/CashierName.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/pos_hr/static/src/js/CashierName.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/pos_hr/static/src/js/CashierName.js')
-rw-r--r--addons/pos_hr/static/src/js/CashierName.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/addons/pos_hr/static/src/js/CashierName.js b/addons/pos_hr/static/src/js/CashierName.js
new file mode 100644
index 00000000..76283720
--- /dev/null
+++ b/addons/pos_hr/static/src/js/CashierName.js
@@ -0,0 +1,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;
+});