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