mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
fix: number series skipping issue
This commit is contained in:
parent
838ae87642
commit
dd5d87442e
@ -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;
|
||||
},
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user