fix(InvoiceOutGlobal): refs #8264 fix invoicing
This commit is contained in:
parent
ebb4d36fda
commit
0c30a82440
|
@ -93,7 +93,6 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
},
|
||||
|
||||
async makeInvoice(formData, clientsToInvoice) {
|
||||
this.invoicing = true;
|
||||
try {
|
||||
this.printer = formData.printer;
|
||||
const params = {
|
||||
|
@ -118,10 +117,12 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
);
|
||||
throw new Error("There aren't addresses to invoice");
|
||||
}
|
||||
this.invoicing = false;
|
||||
this.status = 'invoicing';
|
||||
this.formData = formData;
|
||||
this.addressIndex = 0;
|
||||
await this.invoiceClient(this.addressIndex);
|
||||
this.errors = [];
|
||||
await this.invoiceClient();
|
||||
} catch (err) {
|
||||
this.handleError(err);
|
||||
}
|
||||
|
@ -180,10 +181,9 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
}
|
||||
},
|
||||
|
||||
async invoiceClient(index = this.addressIndex++) {
|
||||
if (this.nRequests >= this.parallelism) return;
|
||||
|
||||
const address = this.addresses[index];
|
||||
async invoiceClient() {
|
||||
if (this.invoicing || this.nRequests >= this.parallelism) return;
|
||||
const address = this.addresses[this.addressIndex];
|
||||
|
||||
if (!address || !this.status || this.status == 'stopping') {
|
||||
this.status = 'stopping';
|
||||
|
@ -191,6 +191,7 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
return;
|
||||
}
|
||||
try {
|
||||
this.invoicing = true;
|
||||
const params = {
|
||||
clientId: address.clientId,
|
||||
addressId: address.id,
|
||||
|
@ -200,26 +201,22 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
serialType: this.formData.serialType,
|
||||
};
|
||||
|
||||
this.invoicing = true;
|
||||
|
||||
const { data } = await axios.post('InvoiceOuts/invoiceClient', params);
|
||||
|
||||
if (data) this.makePdfAndNotify(data, address);
|
||||
this.isInvoicing = false;
|
||||
} catch (err) {
|
||||
if (err?.response?.status >= 400 && err?.response?.status < 500) {
|
||||
this.invoiceClientError(address, err.response?.data?.error?.message);
|
||||
return;
|
||||
} else {
|
||||
this.invoicing = false;
|
||||
notify(
|
||||
'invoiceOut.globalInvoices.errors.criticalInvoiceError',
|
||||
'negative'
|
||||
);
|
||||
throw new Error('Critical invoicing error, process stopped');
|
||||
}
|
||||
} finally {
|
||||
await this.invoiceClient();
|
||||
this.invoicing = false;
|
||||
this.addressIndex++;
|
||||
this.invoiceClient();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -234,7 +231,7 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
this.invoiceClientError(client, err.response?.data?.error?.message, true);
|
||||
} finally {
|
||||
this.nRequests--;
|
||||
await this.invoiceClient(); // Comprobar que no haya ninguna factura pendiente
|
||||
this.invoiceClient();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue