From e3bdea2197624047e62aa27712783053c45ee822 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 27 Nov 2024 01:15:16 +0100 Subject: [PATCH] fix: ticketSale keyup.enter --- src/pages/Ticket/Card/TicketSale.vue | 50 ++++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/pages/Ticket/Card/TicketSale.vue b/src/pages/Ticket/Card/TicketSale.vue index 08cdcb9df..95ef3118e 100644 --- a/src/pages/Ticket/Card/TicketSale.vue +++ b/src/pages/Ticket/Card/TicketSale.vue @@ -181,17 +181,34 @@ const resetChanges = async () => { arrayData.fetch({ append: false }); tableRef.value.reload(); }; +const rowToUpdate = ref(null); +const changeQuantity = async (sale) => { + canProceed.value = await isSalePrepared(sale); + if (!canProceed.value) return; + if ( + !sale.itemFk || + sale.quantity == null || + edit.value?.oldQuantity === sale.quantity + ) + return; + if (!sale.id) return addSale(sale); -const updateQuantity = async (sale) => { - const params = { quantity: sale.quantity }; try { - await axios.post(`Sales/${sale.id}/updateQuantity`, params); + if (!rowToUpdate.value) return; + rowToUpdate.value = null; + await updateQuantity(sale); } catch (e) { - sale.quantity = tableRef.value.CrudModelRef.originalData.find( + const { quantity } = tableRef.value.CrudModelRef.originalData.find( (s) => s.id === sale.id - ).quantity; + ); + sale.quantity = quantity; throw e; } +}; + +const updateQuantity = async ({ quantity, id }) => { + const params = { quantity: quantity }; + await axios.post(`Sales/${id}/updateQuantity`, params); notify('globals.dataSaved', 'positive'); }; @@ -219,19 +236,6 @@ const addSale = async (sale) => { window.location.reload(); }; -const changeQuantity = async (sale) => { - canProceed.value = await isSalePrepared(sale); - if (!canProceed.value) return; - if ( - !sale.itemFk || - sale.quantity == null || - edit.value?.oldQuantity === sale.quantity - ) - return; - if (!sale.id) return addSale(sale); - await updateQuantity(sale); -}; - const updateConcept = async (sale) => { canProceed.value = await isSalePrepared(sale); if (!canProceed.value) return; @@ -768,16 +772,12 @@ watch(