mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
fix: minor bugs, fix patch too
This commit is contained in:
parent
01f1154a67
commit
b4bed9521f
@ -1,3 +1,4 @@
|
||||
const { getPaddedName } = require('@/utils');
|
||||
const frappe = require('frappe');
|
||||
const { getRandomString } = require('frappe/utils');
|
||||
|
||||
@ -90,6 +91,7 @@ module.exports = {
|
||||
|
||||
async getSeriesNext(prefix, doctype) {
|
||||
let series;
|
||||
|
||||
try {
|
||||
series = await frappe.getDoc('NumberSeries', prefix);
|
||||
} catch (e) {
|
||||
@ -101,14 +103,7 @@ module.exports = {
|
||||
series = await frappe.getDoc('NumberSeries', prefix);
|
||||
}
|
||||
|
||||
let next = await series.next(doctype);
|
||||
console.log(next, series.pad, series)
|
||||
const pad = series.padZeros ?? 4;
|
||||
|
||||
const l = next.toString().length;
|
||||
const z = '0'.repeat(Math.max(0, pad - l));
|
||||
|
||||
return prefix + z + next;
|
||||
return await series.next(doctype);
|
||||
},
|
||||
|
||||
async createNumberSeries(prefix, referenceType, start = 1001) {
|
||||
|
@ -33,6 +33,7 @@ module.exports = {
|
||||
fieldtype: 'Int',
|
||||
default: 1001,
|
||||
required: 1,
|
||||
minvalue: 0,
|
||||
},
|
||||
{
|
||||
fieldname: 'padZeros',
|
||||
|
@ -1,3 +1,4 @@
|
||||
const { getPaddedName } = require('@/utils');
|
||||
const frappe = require('frappe');
|
||||
const BaseDocument = require('frappe/model/document');
|
||||
|
||||
@ -7,6 +8,7 @@ module.exports = class NumberSeries extends BaseDocument {
|
||||
this.current = this.start;
|
||||
}
|
||||
}
|
||||
|
||||
async next(doctype) {
|
||||
this.validate();
|
||||
|
||||
@ -17,13 +19,19 @@ module.exports = class NumberSeries extends BaseDocument {
|
||||
|
||||
this.current++;
|
||||
await this.update();
|
||||
return this.current;
|
||||
return this.getPaddedName(this.current);
|
||||
}
|
||||
|
||||
async checkIfCurrentExists(doctype) {
|
||||
if (!doctype) {
|
||||
return true;
|
||||
}
|
||||
return await frappe.db.exists(doctype, this.name + this.current);
|
||||
|
||||
const name = this.getPaddedName(this.current);
|
||||
return await frappe.db.exists(doctype, name);
|
||||
}
|
||||
|
||||
getPaddedName(next) {
|
||||
return getPaddedName(this.name, next, this.padZeros);
|
||||
}
|
||||
};
|
||||
|
@ -6,6 +6,10 @@ async function setReferencesOnNumberSeries() {
|
||||
const map = invertMap(DEFAULT_NUMBER_SERIES);
|
||||
const rows = await frappe.db.knex('NumberSeries');
|
||||
for (const row of rows) {
|
||||
if (row.referenceType === map[row.name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
row.referenceType = map[row.name];
|
||||
}
|
||||
await frappe.db.prestigeTheTable('NumberSeries', rows);
|
||||
|
@ -547,3 +547,12 @@ export function invertMap(map) {
|
||||
|
||||
return inverted;
|
||||
}
|
||||
|
||||
export function getPaddedName(prefix, next, padZeros) {
|
||||
const padding = padZeros ?? 4;
|
||||
|
||||
const l = next.toString().length;
|
||||
const z = '0'.repeat(Math.max(0, padding - l));
|
||||
|
||||
return prefix + z + next;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user