Skip to content
Snippets Groups Projects
Commit 19b45d6a authored by roen-odoo's avatar roen-odoo
Browse files

[FIX] point_of_sale: double_click_validate


partial backport of : #89063

opw-2813512

closes odoo/odoo#91469

Signed-off-by: default avatarJoseph Caburnay (jcb) <jcb@odoo.com>
parent 31e15a30
Branches
Tags
No related merge requests found
......@@ -6,6 +6,7 @@ odoo.define('point_of_sale.ClientListScreen', function(require) {
const Registries = require('point_of_sale.Registries');
const { useListener } = require('web.custom_hooks');
const { isRpcError } = require('point_of_sale.utils');
const { useAsyncLockedMethod } = require('point_of_sale.custom_hooks');
/**
* Render this screen using `showTempScreen` to select client.
......@@ -25,9 +26,10 @@ odoo.define('point_of_sale.ClientListScreen', function(require) {
class ClientListScreen extends PosComponent {
constructor() {
super(...arguments);
this.lockedSaveChanges = useAsyncLockedMethod(this.saveChanges);
useListener('click-save', () => this.env.bus.trigger('save-customer'));
useListener('click-edit', () => this.editClient());
useListener('save-changes', this.saveChanges);
useListener('save-changes', this.lockedSaveChanges);
// We are not using useState here because the object
// passed to useState converts the object and its contents
......
......@@ -3,7 +3,7 @@ odoo.define('point_of_sale.PaymentScreen', function (require) {
const { parse } = require('web.field_utils');
const PosComponent = require('point_of_sale.PosComponent');
const { useErrorHandlers } = require('point_of_sale.custom_hooks');
const { useErrorHandlers, useAsyncLockedMethod } = require('point_of_sale.custom_hooks');
const NumberBuffer = require('point_of_sale.NumberBuffer');
const { useListener } = require('web.custom_hooks');
const Registries = require('point_of_sale.Registries');
......@@ -20,6 +20,7 @@ odoo.define('point_of_sale.PaymentScreen', function (require) {
useListener('send-payment-cancel', this._sendPaymentCancel);
useListener('send-payment-reverse', this._sendPaymentReverse);
useListener('send-force-done', this._sendForceDone);
this.lockedValidateOrder = useAsyncLockedMethod(this.validateOrder);
NumberBuffer.use({
// The numberBuffer listens to this event to update its state.
// Basically means 'update the buffer when this event is triggered'
......@@ -306,7 +307,7 @@ odoo.define('point_of_sale.PaymentScreen', function (require) {
' ' +
this.env._t('? Clicking "Confirm" will validate the payment.'),
}).then(({ confirmed }) => {
if (confirmed) this.validateOrder(true);
if (confirmed) this.lockedValidateOrder(true);
});
return false;
}
......
......@@ -145,5 +145,21 @@ odoo.define('point_of_sale.custom_hooks', function (require) {
});
}
return { useErrorHandlers, useAutoFocusToLast, onChangeOrder, useBarcodeReader };
function useAsyncLockedMethod(method) {
const component = Component.current;
let called = false;
return async (...args) => {
if (called) {
return;
}
try {
called = true;
await method.call(component, ...args);
} finally {
called = false;
}
};
}
return { useErrorHandlers, useAutoFocusToLast, onChangeOrder, useBarcodeReader, useAsyncLockedMethod };
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment