2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00

fix: number series skipping issue

This commit is contained in:
18alantom 2022-02-07 15:48:37 +05:30
parent 838ae87642
commit dd5d87442e
2 changed files with 18 additions and 4 deletions

View File

@ -13,7 +13,7 @@ module.exports = {
if (doc.meta.settings) {
const numberSeries = (await doc.getSettings()).numberSeries;
if (numberSeries) {
doc.name = await this.getSeriesNext(numberSeries);
doc.name = await this.getSeriesNext(numberSeries, doc.doctype);
}
}
}
@ -58,7 +58,7 @@ module.exports = {
return lastInserted && lastInserted.length ? lastInserted[0] : null;
},
async getSeriesNext(prefix) {
async getSeriesNext(prefix, doctype) {
let series;
try {
series = await frappe.getDoc('NumberSeries', prefix);
@ -69,7 +69,7 @@ module.exports = {
await this.createNumberSeries(prefix);
series = await frappe.getDoc('NumberSeries', prefix);
}
let next = await series.next();
let next = await series.next(doctype);
return prefix + next;
},

View File

@ -1,3 +1,4 @@
const frappe = require('frappe');
const BaseDocument = require('frappe/model/document');
module.exports = class NumberSeries extends BaseDocument {
@ -6,10 +7,23 @@ module.exports = class NumberSeries extends BaseDocument {
this.current = 0;
}
}
async next() {
async next(doctype) {
this.validate();
const exists = await this.checkIfCurrentExists(doctype);
if (!exists) {
return this.current;
}
this.current++;
await this.update();
return this.current;
}
async checkIfCurrentExists(doctype) {
if (!doctype) {
return true;
}
return await frappe.db.exists(doctype, this.name + this.current);
}
};