2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

fix: don't reuse NumberSeries id

This commit is contained in:
18alantom 2022-07-07 16:58:58 +05:30 committed by Alan
parent c49eeed102
commit 4723d169f9

View File

@ -7,8 +7,16 @@ function getPaddedName(prefix: string, next: number, padZeros: number): string {
export default class NumberSeries extends Doc {
setCurrent() {
let current = this.get('current') as number | null;
/**
* Increment current if it isn't the first entry. This
* is to prevent reassignment of NumberSeries document ids.
*/
if (!current) {
current = this.get('start') as number;
} else {
current = current + 1;
}
this.current = current;
@ -16,13 +24,12 @@ export default class NumberSeries extends Doc {
async next(schemaName: string) {
this.setCurrent();
const exists = await this.checkIfCurrentExists(schemaName);
if (!exists) {
return this.getPaddedName(this.current as number);
if (exists) {
this.current = (this.current as number) + 1;
}
this.current = (this.current as number) + 1;
await this.sync();
return this.getPaddedName(this.current as number);
}