mirror of
https://github.com/bringout/oca-ocb-pos.git
synced 2026-04-23 19:42:00 +02:00
19.0 vanilla
This commit is contained in:
parent
6e54c1af6c
commit
3ca647e428
1087 changed files with 132065 additions and 108499 deletions
|
|
@ -0,0 +1,9 @@
|
|||
import { Chrome } from "@point_of_sale/app/pos_app";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(Chrome.prototype, {
|
||||
get showCashMoveButton() {
|
||||
const { cashier } = this.pos;
|
||||
return super.showCashMoveButton && (!cashier || cashier._role == "manager");
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { CashierName } from "@point_of_sale/app/components/navbar/cashier_name/cashier_name";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { useCashierSelector } from "@pos_hr/app/utils/select_cashier_mixin";
|
||||
|
||||
patch(CashierName.prototype, {
|
||||
setup() {
|
||||
super.setup(...arguments);
|
||||
if (this.pos.config.module_pos_hr) {
|
||||
this.cashierSelector = useCashierSelector();
|
||||
}
|
||||
},
|
||||
//@Override
|
||||
get avatar() {
|
||||
if (this.pos.config.module_pos_hr) {
|
||||
const cashier = this.pos.getCashier();
|
||||
if (!(cashier && cashier.id)) {
|
||||
return "";
|
||||
}
|
||||
return `/web/image/hr.employee.public/${cashier.id}/avatar_128`;
|
||||
}
|
||||
return super.avatar;
|
||||
},
|
||||
//@Override
|
||||
get cssClass() {
|
||||
if (this.pos.config.module_pos_hr) {
|
||||
return { oe_status: true };
|
||||
}
|
||||
return super.cssClass;
|
||||
},
|
||||
async selectCashier(pin = false, login = false, list = false) {
|
||||
return await this.cashierSelector(...arguments);
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-name="pos_hr.CashierName" t-inherit="point_of_sale.CashierName" t-inherit-mode="extension">
|
||||
<xpath expr="//button" position="attributes">
|
||||
<attribute name="t-on-click">() => this.selectCashier(false, true, true)</attribute>
|
||||
</xpath>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { Navbar } from "@point_of_sale/app/components/navbar/navbar";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(Navbar.prototype, {
|
||||
get showCreateProductButton() {
|
||||
if (!this.pos.config.module_pos_hr || this.pos.employeeIsAdmin) {
|
||||
return super.showCreateProductButton;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
get showBackend() {
|
||||
const cashier = this.pos.getCashierUserId();
|
||||
return !this.pos.config.module_pos_hr || (cashier && cashier.id === this.pos.user?.id);
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-name="pos_hr.Navbar" t-inherit="point_of_sale.Navbar" t-inherit-mode="extension">
|
||||
<xpath expr="//DropdownItem[contains(text(), 'Backend')]" position="attributes">
|
||||
<attribute name="t-if">showBackend</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//DropdownItem[contains(text(), 'Close Register')]" position="attributes">
|
||||
<attribute name="t-if">
|
||||
!pos.config.module_pos_hr or pos.employeeIsAdmin or pos.getCashierUserId() === pos.session.user_id?.id
|
||||
</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//CashierName" position="after">
|
||||
<button t-if="pos.config.module_pos_hr and !ui.isSmall" class="lock-screen btn btn-light btn-lg" title="Lock" t-on-click="() => this.pos.showLoginScreen()">
|
||||
<i class="fa fa-fw fa-unlock"/>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//Dropdown//div[hasclass('pos-burger-menu-items')]" position="inside">
|
||||
<DropdownItem t-if="pos.config.module_pos_hr and ui.isSmall" onSelected="() => this.pos.showLoginScreen()">
|
||||
Lock
|
||||
</DropdownItem>
|
||||
</xpath>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { CashMovePopup } from "@point_of_sale/app/components/popups/cash_move_popup/cash_move_popup";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(CashMovePopup.prototype, {
|
||||
_prepareTryCashInOutPayload() {
|
||||
const result = super._prepareTryCashInOutPayload(...arguments);
|
||||
if (this.pos.config.module_pos_hr) {
|
||||
const employee_id = this.pos.getCashier().id;
|
||||
result[result.length - 1] = { ...result[result.length - 1], employee_id };
|
||||
}
|
||||
return result;
|
||||
},
|
||||
get partnerId() {
|
||||
return this.pos.config.module_pos_hr
|
||||
? this.pos.cashier.work_contact_id?.id
|
||||
: super.partnerId;
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import { Component } from "@odoo/owl";
|
||||
import { Dialog } from "@web/core/dialog/dialog";
|
||||
import { usePos } from "@point_of_sale/app/hooks/pos_hook";
|
||||
export class CashierSelectionPopup extends Component {
|
||||
static template = "pos_hr.CashierSelectionPopup";
|
||||
static components = { Dialog };
|
||||
static props = {
|
||||
close: Function,
|
||||
getPayload: Function,
|
||||
currentCashier: { type: Object, optional: true },
|
||||
employees: { type: Array },
|
||||
};
|
||||
|
||||
setup() {
|
||||
this.pos = usePos();
|
||||
}
|
||||
|
||||
async lock() {
|
||||
await this.pos.showLoginScreen();
|
||||
}
|
||||
selectEmployee(employee) {
|
||||
this.props.getPayload(employee);
|
||||
this.props.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-name="pos_hr.CashierSelectionPopup">
|
||||
<Dialog title.translate="Select Cashier" footer="false" size="'md'" bodyClass="'d-flex flex-column gap-2'">
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center btn btn-outline-secondary active p-2 p-sm-3 border-transparent cursor-default text-start"
|
||||
t-on-click="() => this.props.close()" t-if="props.currentCashier">
|
||||
<t t-set="cashier" t-value="props.currentCashier"/>
|
||||
<div class="d-flex align-items-center ">
|
||||
<div class="ratio ratio-1x1 me-2 me-sm-3" style="width: 40px">
|
||||
<img class="rounded-3" t-attf-src="/web/image/hr.employee.public/{{cashier.id}}/avatar_128"/>
|
||||
</div>
|
||||
<div class="d-flex flex-column">
|
||||
<span class="fs-4 fw-bold current-cashier-name" t-out="cashier.name"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center ms-1">
|
||||
<button class="btn-cashier-lock btn btn-lg btn-secondary" title="Lock" t-on-click.stop="() => this.lock()">
|
||||
<i class="fa fa-fw fa-lock"/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button t-foreach="props.employees" t-as="employee" t-key="employee.id"
|
||||
class="selection-item d-flex align-items-center justify-content-between btn btn-outline-secondary p-2 p-sm-3 text-start"
|
||||
t-on-click="() => this.selectEmployee(employee)">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="ratio ratio-1x1 me-2 me-sm-3" style="width: 40px">
|
||||
<img class="rounded-3" t-attf-src="/web/image/hr.employee.public/{{employee.id}}/avatar_128"/>
|
||||
</div>
|
||||
<div class="d-flex flex-column">
|
||||
<span class="fs-4 fw-bold" t-out="employee.name"/>
|
||||
</div>
|
||||
</div>
|
||||
<i class="oi oi-chevron-right"/>
|
||||
</button>
|
||||
|
||||
</Dialog>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import { ClosePosPopup } from "@point_of_sale/app/components/popups/closing_popup/closing_popup";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(ClosePosPopup.prototype, {
|
||||
hasUserAuthority() {
|
||||
if (!this.pos.config.module_pos_hr) {
|
||||
return super.hasUserAuthority();
|
||||
}
|
||||
const cashier = this.pos.cashier;
|
||||
return (
|
||||
(cashier._role == "manager" && cashier._user_role == "admin") ||
|
||||
this.allowedDifference()
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="pos_hr.ClosePosPopup" t-inherit="point_of_sale.ClosePosPopup" t-inherit-mode="extension">
|
||||
<xpath expr="//div[hasclass('payment-methods-overview')]" position="attributes">
|
||||
<attribute name="t-if">!pos.config.module_pos_hr</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('payment-methods-overview')]" position="after">
|
||||
<t t-if="pos.config.module_pos_hr">
|
||||
<div t-if="pos.config.cash_control and pos.config.module_pos_hr" class="w-100 mb-3">
|
||||
<t t-set="diff" t-value="getDifference(props.default_cash_details.id)" />
|
||||
<t t-set="counted" t-value="state.payments[props.default_cash_details.id]?.counted || '0'" />
|
||||
<div class="d-flex align-items-center justify-content-between fs-3">
|
||||
<span t-esc="props.default_cash_details.name" />
|
||||
<span t-esc="env.utils.formatCurrency(props.default_cash_details.amount)" />
|
||||
</div>
|
||||
<div class="d-flex align-items-center justify-content-between text-muted border-start ps-2">
|
||||
<span>Opening</span>
|
||||
<span t-esc="env.utils.formatCurrency(props.default_cash_details.opening)" />
|
||||
</div>
|
||||
<t t-set="amountByEmployee" t-value="props.default_cash_details.amount_per_employee" />
|
||||
<PaymentMethodBreakdown title.translate="Payments" total_amount="props.default_cash_details.payment_amount" transactions="props.default_cash_details.amount_per_employee"/>
|
||||
<PaymentMethodBreakdown title.translate="Cash in/out" total_amount="getMovesTotalAmount()" transactions="props.default_cash_details.moves_per_employee"/>
|
||||
<div class="d-flex align-items-center justify-content-between text-muted border-start ps-2">
|
||||
<span>Counted</span>
|
||||
<span t-esc="env.utils.formatCurrency(env.utils.parseValidFloat(counted))" />
|
||||
</div>
|
||||
<div class="d-flex align-items-center justify-content-between text-muted border-start ps-2" t-att-class="{'text-danger fw-bold': diff}">
|
||||
<span>Difference</span>
|
||||
<span class="cash-difference" t-esc="env.utils.formatCurrency(diff)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-100 mb-3" t-foreach="props.non_cash_payment_methods" t-as="pm" t-key="pm.id">
|
||||
<t t-set="_showDiff" t-value="pm.type === 'bank' and pm.number !== 0" />
|
||||
<t t-set="diff" t-value="_showDiff ? getDifference(pm.id) : 0" />
|
||||
<t t-set="counted" t-value="_showDiff ? env.utils.parseValidFloat(state.payments[pm.id].counted) : 0" />
|
||||
<div class="d-flex align-items-center justify-content-between fs-3">
|
||||
<span t-esc="pm.name" />
|
||||
<span t-esc="env.utils.formatCurrency(pm.amount)" />
|
||||
</div>
|
||||
<PaymentMethodBreakdown title.translate="Payments" total_amount="pm.amount" transactions="pm.amount_per_employee"/>
|
||||
<div class="d-flex align-items-center justify-content-between text-muted border-start ps-2" t-att-class="{'text-danger fw-bold': diff}">
|
||||
<span>Difference</span>
|
||||
<span t-esc="env.utils.formatCurrency(diff)" />
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import { ProductInfoPopup } from "@point_of_sale/app/components/popups/product_info_popup/product_info_popup";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(ProductInfoPopup.prototype, {
|
||||
get allowProductEdition() {
|
||||
return !this.pos.config.module_pos_hr || this.pos.employeeIsAdmin;
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import { DataServiceOptions } from "@point_of_sale/app/models/data_service_options";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(DataServiceOptions.prototype, {
|
||||
get uniqueModels() {
|
||||
return [...super.uniqueModels, "hr.employee"];
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { PosOrder } from "@point_of_sale/app/models/pos_order";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(PosOrder.prototype, {
|
||||
// @Override
|
||||
getCashierName() {
|
||||
return this.employee_id?.name?.split(" ").at(0) || super.getCashierName(...arguments);
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
import { useCashierSelector } from "@pos_hr/app/utils/select_cashier_mixin";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { LoginScreen } from "@point_of_sale/app/screens/login_screen/login_screen";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { useAutofocus } from "@web/core/utils/hooks";
|
||||
import { onWillUnmount, useExternalListener, useState } from "@odoo/owl";
|
||||
|
||||
patch(LoginScreen.prototype, {
|
||||
setup() {
|
||||
super.setup(...arguments);
|
||||
|
||||
this.state = useState({
|
||||
pin: "",
|
||||
});
|
||||
|
||||
if (this.pos.config.module_pos_hr) {
|
||||
this.cashierSelector = useCashierSelector({
|
||||
onScan: (employee) => employee && this.selectOneCashier(employee),
|
||||
exclusive: true,
|
||||
});
|
||||
|
||||
useAutofocus();
|
||||
useExternalListener(window, "keypress", async (ev) => {
|
||||
if (this.pos.login && ev.key === "Enter" && this.state.pin) {
|
||||
await this.selectCashier(this.state.pin, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onWillUnmount(() => {
|
||||
this.state.pin = "";
|
||||
this.pos.login = false;
|
||||
});
|
||||
},
|
||||
async selectCashier(pin = false, login = false, list = false) {
|
||||
return await this.cashierSelector(pin, login, list);
|
||||
},
|
||||
openRegister() {
|
||||
if (this.pos.config.module_pos_hr) {
|
||||
this.pos.login = true;
|
||||
} else {
|
||||
super.openRegister();
|
||||
}
|
||||
},
|
||||
async clickBack() {
|
||||
if (!this.pos.config.module_pos_hr) {
|
||||
super.clickBack();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.pos.login) {
|
||||
this.state.pin = "";
|
||||
this.pos.login = false;
|
||||
} else {
|
||||
const employee = await this.selectCashier();
|
||||
if (employee && employee.user_id?.id === this.pos.user.id) {
|
||||
super.clickBack();
|
||||
return;
|
||||
} else if (employee) {
|
||||
this.pos.notification.add(
|
||||
_t(
|
||||
"Only the cashier linked to the logged-in user (%s) can proceed to the Backend.",
|
||||
this.pos.user.name
|
||||
),
|
||||
{ type: "danger" }
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
get backBtnName() {
|
||||
return this.pos.login && this.pos.config.module_pos_hr ? _t("Discard") : super.backBtnName;
|
||||
},
|
||||
maskedInput(ev) {
|
||||
ev.preventDefault();
|
||||
const input = ev.target;
|
||||
const pin = this.state.pin || "";
|
||||
const maskedLen = input.value.length;
|
||||
this.state.pin = maskedLen < pin.length ? pin.slice(0, maskedLen) : pin + (ev.data || "");
|
||||
|
||||
input.value = "•".repeat(this.state.pin.length);
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="pos_hr.LoginScreen" t-inherit="point_of_sale.LoginScreen" t-inherit-mode="extension">
|
||||
<xpath expr="//div[hasclass('screen-login')]" position="attributes">
|
||||
<attribute name="t-if">!this.pos.config.module_pos_hr || !this.pos.login</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('screen-login')]" position="after">
|
||||
<div t-if="this.pos.config.module_pos_hr and this.pos.login" class="screen-login flex-grow-1 d-flex align-items-center justify-content-center">
|
||||
<div class="d-flex bg-white p-3 gap-2 rounded">
|
||||
<input
|
||||
t-ref="autofocus"
|
||||
type="text"
|
||||
t-on-input="maskedInput"
|
||||
class="form-control form-control-lg rounded flex-grow-1"
|
||||
placeholder="Enter your PIN" />
|
||||
<button class="select-cashier btn btn-secondary px-4" t-on-click="() => this.selectCashier(false, true)">
|
||||
<i class="fa fa-users" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button class="btn btn-secondary mobile-scanner px-4" t-if="this.pos.config.module_pos_hr">
|
||||
<i class="fa fa-barcode" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//button[hasclass('open-register-btn')]/span" position="replace">
|
||||
<span t-if="this.pos.session.state !== 'opened'" class="d-flex flex-grow-1 align-items-center">Open Register</span>
|
||||
<span t-else="" class="d-flex flex-grow-1 align-items-center">Unlock Register</span>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { OrderSummary } from "@point_of_sale/app/screens/product_screen/order_summary/order_summary";
|
||||
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(OrderSummary.prototype, {
|
||||
async setLinePrice(line, price) {
|
||||
if (this.pos.cashierHasPriceControlRights()) {
|
||||
await super.setLinePrice(line, price);
|
||||
return;
|
||||
}
|
||||
|
||||
this.dialog.add(AlertDialog, {
|
||||
title: _t("Access Denied"),
|
||||
body: _t("You are not allowed to change the price of a product."),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="pos_event.TicketScreen" t-inherit="point_of_sale.TicketScreen" t-inherit-mode="extension">
|
||||
<xpath expr="//button[hasclass('edit-order-payment')]" position="attributes">
|
||||
<attribute name="t-if">!this.pos.config.module_pos_hr || this.pos.employeeIsAdmin</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('ticket-screen')]//div[hasclass('subpads d-flex flex-column')]" position="attributes">
|
||||
<attribute name="t-if">!this.pos.config.module_pos_hr or this.pos.cashier._role !== 'minimal'</attribute>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
import { patch } from "@web/core/utils/patch";
|
||||
import { PosStore } from "@point_of_sale/app/services/pos_store";
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
|
||||
patch(PosStore.prototype, {
|
||||
async setup() {
|
||||
this.employeeBuffer = [];
|
||||
await super.setup(...arguments);
|
||||
if (this.config.module_pos_hr) {
|
||||
this.login = Boolean(odoo.from_backend) && !this.config.module_pos_hr;
|
||||
if (!this.hasLoggedIn) {
|
||||
this.navigate("LoginScreen");
|
||||
}
|
||||
}
|
||||
browser.addEventListener("online", () => {
|
||||
this.employeeBuffer.forEach((employee) =>
|
||||
this.data.write("pos.session", [this.config.current_session_id.id], {
|
||||
employee_id: employee.id,
|
||||
})
|
||||
);
|
||||
this.employeeBuffer = [];
|
||||
});
|
||||
},
|
||||
get employeeIsAdmin() {
|
||||
const cashier = this.getCashier();
|
||||
return cashier._role === "manager";
|
||||
},
|
||||
checkPreviousLoggedCashier() {
|
||||
if (this.config.module_pos_hr) {
|
||||
const savedCashier = this._getConnectedCashier();
|
||||
if (savedCashier) {
|
||||
this.setCashier(savedCashier);
|
||||
} else {
|
||||
this.resetCashier();
|
||||
}
|
||||
} else {
|
||||
super.checkPreviousLoggedCashier(...arguments);
|
||||
}
|
||||
},
|
||||
async afterProcessServerData() {
|
||||
await super.afterProcessServerData(...arguments);
|
||||
if (this.config.module_pos_hr) {
|
||||
const saved_cashier = this._getConnectedCashier();
|
||||
this.hasLoggedIn = saved_cashier ? true : false;
|
||||
}
|
||||
},
|
||||
createNewOrder() {
|
||||
const order = super.createNewOrder(...arguments);
|
||||
|
||||
if (this.config.module_pos_hr) {
|
||||
order.employee_id = this.getCashier();
|
||||
}
|
||||
|
||||
return order;
|
||||
},
|
||||
setCashier(employee) {
|
||||
super.setCashier(employee);
|
||||
|
||||
if (this.config.module_pos_hr) {
|
||||
if (!this.data.network.offline) {
|
||||
this.data.write("pos.session", [this.config.current_session_id.id], {
|
||||
employee_id: employee.id,
|
||||
});
|
||||
} else {
|
||||
this.employeeBuffer.push(employee);
|
||||
}
|
||||
const o = this.getOrder();
|
||||
if (o && !o.getOrderlines().length) {
|
||||
// Order without lines can be considered to be un-owned by any employee.
|
||||
// We set the cashier on that order to the currently set employee.
|
||||
o.employee_id = employee;
|
||||
}
|
||||
if (!this.cashierHasPriceControlRights() && this.numpadMode === "price") {
|
||||
this.numpadMode = "quantity";
|
||||
}
|
||||
}
|
||||
},
|
||||
addLineToCurrentOrder(vals, opt = {}, configure = true) {
|
||||
vals.employee_id = false;
|
||||
|
||||
if (this.config.module_pos_hr) {
|
||||
const cashier = this.getCashier();
|
||||
|
||||
if (cashier && cashier.model.name === "hr.employee") {
|
||||
const order = this.getOrder();
|
||||
order.employee_id = this.getCashier();
|
||||
}
|
||||
}
|
||||
|
||||
return super.addLineToCurrentOrder(vals, opt, configure);
|
||||
},
|
||||
/**{name: null, id: null, barcode: null, user_id:null, pin:null}
|
||||
* If pos_hr is activated, return {name: string, id: int, barcode: string, pin: string, user_id: int}
|
||||
* @returns {null|*}
|
||||
*/
|
||||
getCashier() {
|
||||
if (this.config.module_pos_hr) {
|
||||
return this.cashier;
|
||||
}
|
||||
return super.getCashier(...arguments);
|
||||
},
|
||||
getCashierUserId() {
|
||||
if (this.config.module_pos_hr) {
|
||||
return this.cashier.user_id ? this.cashier.user_id : null;
|
||||
}
|
||||
return super.getCashierUserId(...arguments);
|
||||
},
|
||||
async logEmployeeMessage(action, message) {
|
||||
if (!this.config.module_pos_hr) {
|
||||
super.logEmployeeMessage(...arguments);
|
||||
return;
|
||||
}
|
||||
await this.data.call("pos.session", "log_partner_message", [
|
||||
this.session.id,
|
||||
this.cashier.work_contact_id?.id,
|
||||
action,
|
||||
message,
|
||||
]);
|
||||
},
|
||||
_getConnectedCashier() {
|
||||
if (!this.config.module_pos_hr) {
|
||||
return super._getConnectedCashier(...arguments);
|
||||
}
|
||||
const cashier_id = Number(sessionStorage.getItem(`connected_cashier_${this.config.id}`));
|
||||
if (cashier_id && this.models["hr.employee"].get(cashier_id)) {
|
||||
return this.models["hr.employee"].get(cashier_id);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
shouldShowOpeningControl() {
|
||||
if (this.config.module_pos_hr) {
|
||||
return super.shouldShowOpeningControl(...arguments) && this.hasLoggedIn;
|
||||
}
|
||||
return super.shouldShowOpeningControl(...arguments);
|
||||
},
|
||||
async allowProductCreation() {
|
||||
if (this.config.module_pos_hr) {
|
||||
return this.employeeIsAdmin && (await super.allowProductCreation());
|
||||
}
|
||||
return await super.allowProductCreation();
|
||||
},
|
||||
canEditPayment(order) {
|
||||
return super.canEditPayment(order) && (!this.config.module_pos_hr || this.employeeIsAdmin);
|
||||
},
|
||||
async handleUrlParams() {
|
||||
if (this.config.module_pos_hr && !this.cashier) {
|
||||
if (this.router.state.current !== "LoginScreen") {
|
||||
this.router.navigate("LoginScreen", {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
return await super.handleUrlParams(...arguments);
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import OrderPaymentValidation from "@point_of_sale/app/utils/order_payment_validation";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(OrderPaymentValidation.prototype, {
|
||||
async validateOrder(isForceValidate) {
|
||||
if (this.pos.config.module_pos_hr) {
|
||||
this.order.employee_id = this.pos.getCashier();
|
||||
}
|
||||
|
||||
await super.validateOrder(...arguments);
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/* global Sha1 */
|
||||
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
|
||||
import { NumberPopup } from "@point_of_sale/app/components/popups/number_popup/number_popup";
|
||||
import { useBarcodeReader } from "@point_of_sale/app/hooks/barcode_reader_hook";
|
||||
import { usePos } from "@point_of_sale/app/hooks/pos_hook";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { makeAwaitable, ask } from "@point_of_sale/app/utils/make_awaitable_dialog";
|
||||
import { CashierSelectionPopup } from "@pos_hr/app/components/popups/cashier_selection_popup/cashier_selection_popup";
|
||||
|
||||
export function useCashierSelector({ exclusive, onScan } = { onScan: () => {}, exclusive: false }) {
|
||||
const pos = usePos();
|
||||
const dialog = useService("dialog");
|
||||
const notification = useService("notification");
|
||||
useBarcodeReader(
|
||||
{
|
||||
async cashier(code) {
|
||||
const employee = pos.models["hr.employee"].find(
|
||||
(emp) => emp._barcode === Sha1.hash(code.code)
|
||||
);
|
||||
if (
|
||||
employee &&
|
||||
employee !== pos.getCashier() &&
|
||||
(!employee._pin || (await checkPin(employee)))
|
||||
) {
|
||||
onScan && onScan(employee);
|
||||
}
|
||||
return employee;
|
||||
},
|
||||
},
|
||||
exclusive
|
||||
);
|
||||
|
||||
async function checkPin(employee, pin = false) {
|
||||
let inputPin = pin;
|
||||
if (!pin) {
|
||||
inputPin = await makeAwaitable(dialog, NumberPopup, {
|
||||
formatDisplayedValue: (x) => x.replace(/./g, "•"),
|
||||
title: _t("Password?"),
|
||||
});
|
||||
} else {
|
||||
if (employee._pin !== Sha1.hash(inputPin)) {
|
||||
inputPin = await makeAwaitable(dialog, NumberPopup, {
|
||||
formatDisplayedValue: (x) => x.replace(/./g, "•"),
|
||||
title: _t("Password?"),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!inputPin || employee._pin !== Sha1.hash(inputPin)) {
|
||||
notification.add(_t("PIN not found"), {
|
||||
type: "warning",
|
||||
title: _t(`Wrong PIN`),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a cashier, the returning value will either be an object or nothing (undefined)
|
||||
*/
|
||||
return async function selectCashier(pin = false, login = false, list = false) {
|
||||
if (!pos.config.module_pos_hr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wrongPinNotification = () => {
|
||||
notification.add(_t("PIN not found"), {
|
||||
type: "warning",
|
||||
title: _t(`Wrong PIN`),
|
||||
});
|
||||
};
|
||||
|
||||
let employee = false;
|
||||
const allEmployees = pos.models["hr.employee"].filter(
|
||||
(employee) => employee.id !== pos.getCashier()?.id
|
||||
);
|
||||
const pinMatchEmployees = allEmployees.filter(
|
||||
(employee) => !pin || Sha1.hash(pin) === employee._pin
|
||||
);
|
||||
|
||||
if (!pinMatchEmployees.length && !pin) {
|
||||
await ask(dialog, {
|
||||
title: _t("No Cashiers"),
|
||||
body: _t("There is no cashier available."),
|
||||
});
|
||||
return;
|
||||
} else if (pin && !pinMatchEmployees.length) {
|
||||
wrongPinNotification();
|
||||
return;
|
||||
}
|
||||
|
||||
if (pinMatchEmployees.length > 1 || list) {
|
||||
employee = await makeAwaitable(dialog, CashierSelectionPopup, {
|
||||
currentCashier: pos.getCashier() || undefined,
|
||||
employees: allEmployees,
|
||||
});
|
||||
|
||||
if (!employee) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pin && Sha1.hash(pin) !== employee._pin) {
|
||||
wrongPinNotification();
|
||||
return;
|
||||
}
|
||||
} else if (pinMatchEmployees.length === 1) {
|
||||
employee = pinMatchEmployees[0];
|
||||
}
|
||||
|
||||
if (!pin && employee && employee._pin) {
|
||||
const result = await checkPin(employee);
|
||||
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (login && employee) {
|
||||
pos.hasLoggedIn = true;
|
||||
pos.setCashier(employee);
|
||||
}
|
||||
|
||||
const currentScreen = pos.router.state.current;
|
||||
if (currentScreen === "LoginScreen" && login && employee) {
|
||||
const selectedScreen = pos.defaultPage;
|
||||
const props = {
|
||||
...selectedScreen.params,
|
||||
orderUuid: pos.selectedOrderUuid,
|
||||
};
|
||||
if (selectedScreen.page === "FloorScreen") {
|
||||
delete props.orderUuid;
|
||||
}
|
||||
pos.navigate(selectedScreen.page, props);
|
||||
}
|
||||
|
||||
return employee;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue