[FIX] point_of_sale, pos_{loyalty,mercury}: restricting key to confirm or cancel popup
The "pressing a specific key to confirm/cancel a popup" behavior was added but the problem was that some popups only had one button which was either confirm or cancel. It was thus possible to close those popups by bypassing the default behavior (e.g. possible to "cancel" a popup which only has one button linked to an overridden confirm method and vice-versa). Also, we normalize the use of `confirm` and `cancel` methods in the popups so that when the specifics keys are pressed, the right behavior is executed. closes odoo/odoo#97069 X-original-commit: a14ade59744855a9dea8b16f23a3d61eb88678de Related: odoo/enterprise#29957 Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
@@ -245,7 +245,7 @@ odoo.define('point_of_sale.Chrome', function(require) {
|
||||
|
||||
openCashControl() {
|
||||
if (this.shouldShowCashControl()) {
|
||||
this.showPopup('CashOpeningPopup', { cancelKey: false });
|
||||
this.showPopup('CashOpeningPopup');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,17 @@ odoo.define('point_of_sale.CashOpeningPopup', function(require) {
|
||||
displayMoneyDetailsPopup: false,
|
||||
});
|
||||
}
|
||||
//@override
|
||||
async confirm() {
|
||||
this.env.pos.bank_statement.balance_start = this.state.openingCash;
|
||||
this.env.pos.pos_session.state = 'opened';
|
||||
this.rpc({
|
||||
model: 'pos.session',
|
||||
method: 'set_cashbox_pos',
|
||||
args: [this.env.pos.pos_session.id, this.state.openingCash, this.state.notes],
|
||||
});
|
||||
super.confirm();
|
||||
}
|
||||
openDetailsPopup() {
|
||||
this.state.openingCash = 0;
|
||||
this.state.notes = "";
|
||||
@@ -24,16 +35,6 @@ odoo.define('point_of_sale.CashOpeningPopup', function(require) {
|
||||
closeDetailsPopup() {
|
||||
this.state.displayMoneyDetailsPopup = false;
|
||||
}
|
||||
startSession() {
|
||||
this.env.pos.bank_statement.balance_start = this.state.openingCash;
|
||||
this.env.pos.pos_session.state = 'opened';
|
||||
this.rpc({
|
||||
model: 'pos.session',
|
||||
method: 'set_cashbox_pos',
|
||||
args: [this.env.pos.pos_session.id, this.state.openingCash, this.state.notes],
|
||||
});
|
||||
this.cancel(); // close popup
|
||||
}
|
||||
updateCashOpening({ total, moneyDetailsNotes }) {
|
||||
this.state.openingCash = total;
|
||||
if (moneyDetailsNotes) {
|
||||
@@ -49,6 +50,7 @@ odoo.define('point_of_sale.CashOpeningPopup', function(require) {
|
||||
}
|
||||
|
||||
CashOpeningPopup.template = 'CashOpeningPopup';
|
||||
CashOpeningPopup.defaultProps = { cancelKey: false };
|
||||
Registries.Component.add(CashOpeningPopup);
|
||||
|
||||
return CashOpeningPopup;
|
||||
|
||||
@@ -53,7 +53,7 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) {
|
||||
}
|
||||
Object.assign(this.state, state);
|
||||
} catch (error) {
|
||||
this.cancel();
|
||||
super.cancel();
|
||||
if (identifyError(error) instanceof ConnectionLostError) {
|
||||
this.showPopup('ErrorPopup', {
|
||||
title: this.env._t('Network Error'),
|
||||
@@ -64,6 +64,36 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) {
|
||||
}
|
||||
}
|
||||
}
|
||||
//@override
|
||||
async confirm() {
|
||||
if (!this.cashControl || !this.hasDifference()) {
|
||||
this.closeSession();
|
||||
} else if (this.hasUserAuthority()) {
|
||||
const { confirmed } = await this.showPopup('ConfirmPopup', {
|
||||
title: this.env._t('Payments Difference'),
|
||||
body: this.env._t('Do you want to accept payments difference and post a profit/loss journal entry?'),
|
||||
});
|
||||
if (confirmed) {
|
||||
this.closeSession();
|
||||
}
|
||||
} else {
|
||||
await this.showPopup('ConfirmPopup', {
|
||||
title: this.env._t('Payments Difference'),
|
||||
body: _.str.sprintf(
|
||||
this.env._t('The maximum difference allowed is %s.\n\
|
||||
Please contact your manager to accept the closing difference.'),
|
||||
this.env.pos.format_currency(this.amountAuthorizedDiff)
|
||||
),
|
||||
confirmText: this.env._t('OK'),
|
||||
})
|
||||
}
|
||||
}
|
||||
//@override
|
||||
async cancel() {
|
||||
if (this.canCancel()) {
|
||||
super.cancel();
|
||||
}
|
||||
}
|
||||
openDetailsPopup() {
|
||||
this.state.payments[this.defaultCashDetails.id].counted = 0;
|
||||
this.state.payments[this.defaultCashDetails.id].difference = -this.defaultCashDetails.amount;
|
||||
@@ -110,37 +140,9 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) {
|
||||
const absDifferences = Object.entries(this.state.payments).map(pm => Math.abs(pm[1].difference));
|
||||
return this.isManager || this.amountAuthorizedDiff == null || Math.max(...absDifferences) <= this.amountAuthorizedDiff;
|
||||
}
|
||||
async onCloseSession() {
|
||||
if (!this.cashControl || !this.hasDifference()) {
|
||||
this.closeSession();
|
||||
} else if (this.hasUserAuthority()) {
|
||||
const { confirmed } = await this.showPopup('ConfirmPopup', {
|
||||
title: this.env._t('Payments Difference'),
|
||||
body: this.env._t('Do you want to accept payments difference and post a profit/loss journal entry?'),
|
||||
});
|
||||
if (confirmed) {
|
||||
this.closeSession();
|
||||
}
|
||||
} else {
|
||||
await this.showPopup('ConfirmPopup', {
|
||||
title: this.env._t('Payments Difference'),
|
||||
body: _.str.sprintf(
|
||||
this.env._t('The maximum difference allowed is %s.\n\
|
||||
Please contact your manager to accept the closing difference.'),
|
||||
this.env.pos.format_currency(this.amountAuthorizedDiff)
|
||||
),
|
||||
confirmText: this.env._t('OK'),
|
||||
})
|
||||
}
|
||||
}
|
||||
canCancel() {
|
||||
return true;
|
||||
}
|
||||
cancelPopup() {
|
||||
if (this.canCancel()) {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
closePos() {
|
||||
this.trigger('close-pos');
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ odoo.define('point_of_sale.ControlButtonPopup', function(require) {
|
||||
ControlButtonPopup.template = 'ControlButtonPopup';
|
||||
ControlButtonPopup.defaultProps = {
|
||||
cancelText: _lt('Back'),
|
||||
controlButtons: []
|
||||
controlButtons: [],
|
||||
confirmKey: false,
|
||||
};
|
||||
|
||||
Registries.Component.add(ControlButtonPopup);
|
||||
|
||||
@@ -18,9 +18,9 @@ odoo.define('point_of_sale.ErrorPopup', function(require) {
|
||||
ErrorPopup.template = 'ErrorPopup';
|
||||
ErrorPopup.defaultProps = {
|
||||
confirmText: _lt('Ok'),
|
||||
cancelText: _lt('Cancel'),
|
||||
title: _lt('Error'),
|
||||
body: '',
|
||||
cancelKey: false,
|
||||
};
|
||||
|
||||
Registries.Component.add(ErrorPopup);
|
||||
|
||||
@@ -32,6 +32,7 @@ odoo.define('point_of_sale.ErrorTracebackPopup', function(require) {
|
||||
ErrorTracebackPopup.defaultProps = {
|
||||
confirmText: _lt('Ok'),
|
||||
cancelText: _lt('Cancel'),
|
||||
confirmKey: false,
|
||||
title: _lt('Error with Traceback'),
|
||||
body: '',
|
||||
exitButtonIsShown: false,
|
||||
|
||||
@@ -18,7 +18,7 @@ odoo.define('point_of_sale.OrderImportPopup', function(require) {
|
||||
OrderImportPopup.template = 'OrderImportPopup';
|
||||
OrderImportPopup.defaultProps = {
|
||||
confirmText: _lt('Ok'),
|
||||
cancelText: _lt('Cancel'),
|
||||
cancelKey: false,
|
||||
body: '',
|
||||
};
|
||||
|
||||
|
||||
@@ -71,5 +71,6 @@ odoo.define('point_of_sale.ProductInfoPopup', function(require) {
|
||||
}
|
||||
|
||||
ProductInfoPopup.template = 'ProductInfoPopup';
|
||||
ProductInfoPopup.defaultProps= { confirmKey: false };
|
||||
Registries.Component.add(ProductInfoPopup);
|
||||
});
|
||||
|
||||
@@ -46,11 +46,11 @@ odoo.define('point_of_sale.SelectionPopup', function (require) {
|
||||
}
|
||||
SelectionPopup.template = 'SelectionPopup';
|
||||
SelectionPopup.defaultProps = {
|
||||
confirmText: _lt('Confirm'),
|
||||
cancelText: _lt('Cancel'),
|
||||
title: _lt('Select'),
|
||||
body: '',
|
||||
list: [],
|
||||
confirmKey: false,
|
||||
};
|
||||
|
||||
Registries.Component.add(SelectionPopup);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<textarea placeholder="Add an opening note..." class="opening-cash-notes" t-model="state.notes"/>
|
||||
</main>
|
||||
<footer class="footer">
|
||||
<div class="button" t-on-click="startSession">Open session</div>
|
||||
<div class="button" t-on-click="confirm">Open session</div>
|
||||
</footer>
|
||||
</div>
|
||||
<MoneyDetailsPopup
|
||||
|
||||
@@ -79,9 +79,9 @@
|
||||
</div>
|
||||
</main>
|
||||
<footer class="footer">
|
||||
<div class="button highlight" t-on-click="onCloseSession">Close Session</div>
|
||||
<div class="button highlight" t-on-click="confirm">Close Session</div>
|
||||
<div class="button" t-on-click="closePos" title="Visit the Backend but keep session open">Backend</div>
|
||||
<div class="button" t-att-class="{'disabled': !canCancel()}" t-on-click="cancelPopup">Discard</div>
|
||||
<div class="button" t-att-class="{'disabled': !canCancel()}" t-on-click="cancel">Discard</div>
|
||||
<!-- Download Sale Details -->
|
||||
<div class="small button icon"
|
||||
t-on-click="downloadSalesReport"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</header>
|
||||
<main class="body traceback"><t t-esc="props.body"/></main>
|
||||
<footer class="footer">
|
||||
<div class="button cancel" t-on-click="cancel">
|
||||
<div class="button confirm" t-on-click="confirm">
|
||||
Ok
|
||||
</div>
|
||||
<div class="button dont-show-again" t-on-click="dontShowAgain">
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</t>
|
||||
</ul>
|
||||
<footer class="footer">
|
||||
<div class="button cancel" t-on-click="cancel">
|
||||
<div class="button cancel" t-on-click="confirm">
|
||||
<t t-esc="props.confirmText" />
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@@ -34,8 +34,11 @@ export class GiftCardPopup extends AbstractAwaitablePopup {
|
||||
}, true);
|
||||
}
|
||||
|
||||
clickConfirm() {
|
||||
this.confirmFunctions[this.state.context]();
|
||||
//@override
|
||||
async confirm() {
|
||||
if (!this.state.showMenu) {
|
||||
this.confirmFunctions[this.state.context]();
|
||||
}
|
||||
}
|
||||
|
||||
get code() {
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
<div t-if="!state.showMenu" class="button cancel gift-card-footer-button" t-on-click="switchToMenu">
|
||||
Back
|
||||
</div>
|
||||
<div t-if="!state.showMenu" class="button confirm gift-card-footer-button" t-on-click="clickConfirm">
|
||||
<div t-if="!state.showMenu" class="button confirm gift-card-footer-button" t-on-click="confirm">
|
||||
Confirm
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@@ -28,9 +28,9 @@ odoo.define('pos_mercury.PaymentTransactionPopup', function(require) {
|
||||
PaymentTransactionPopup.template = 'PaymentTransactionPopup';
|
||||
PaymentTransactionPopup.defaultProps = {
|
||||
confirmText: _lt('Ok'),
|
||||
cancelText: _lt('Cancel'),
|
||||
title: _lt('Online Payment'),
|
||||
body: '',
|
||||
cancelKey: false,
|
||||
};
|
||||
|
||||
Registries.Component.add(PaymentTransactionPopup);
|
||||
|
||||
Reference in New Issue
Block a user