From 86d24ffede6b430e7923d66f77d73244a8dc71d7 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 17 Oct 2022 13:02:03 +0200 Subject: [PATCH] refactor code --- .../invoiceOut/back/methods/invoiceOut/clientToInvoice.js | 3 +-- modules/invoiceOut/front/index/global-invoicing/index.js | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js index cb2bfece7..a0578897a 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js @@ -21,8 +21,7 @@ module.exports = Self => { { arg: 'toClientId', type: 'number', - description: 'The maximum client id', - required: false + description: 'The maximum client id' }, { arg: 'companyFk', diff --git a/modules/invoiceOut/front/index/global-invoicing/index.js b/modules/invoiceOut/front/index/global-invoicing/index.js index 4ef2ed8e0..e311f6b02 100644 --- a/modules/invoiceOut/front/index/global-invoicing/index.js +++ b/modules/invoiceOut/front/index/global-invoicing/index.js @@ -58,7 +58,7 @@ class Controller extends Dialog { if (!this.invoice.invoiceDate || !this.invoice.maxShipped) throw new Error('Invoice date and the max date should be filled'); - if (!this.invoice.fromClientId) + if (!this.invoice.fromClientId || !this.invoice.toClientId) throw new Error('Choose a valid clients range'); this.on('close', () => { @@ -71,11 +71,11 @@ class Controller extends Dialog { return this.$http.post(`InvoiceOuts/clientToInvoice`, this.invoice) .then(async res => { - const clientsAndAddresses = res.data.clientsAndAddresses; const invoice = res.data.invoice; - + const clientsAndAddresses = res.data.clientsAndAddresses; if (!clientsAndAddresses.length) return super.responseHandler(response); this.lastClientId = clientsAndAddresses[clientsAndAddresses.length - 1].clientId; + for (let clientAndAddress of clientsAndAddresses) { this.currentClientId = clientAndAddress.clientId; const params = { @@ -98,8 +98,8 @@ class Controller extends Dialog { .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) .finally(() => this.restartValues()); } catch (e) { - this.restartValues(); this.vnApp.showError(this.$t(e.message)); + this.restartValues(); return false; } }