mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +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 frappe = require('frappe');
|
||||||
const { getRandomString } = require('frappe/utils');
|
const { getRandomString } = require('frappe/utils');
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ module.exports = {
|
|||||||
|
|
||||||
async getSeriesNext(prefix, doctype) {
|
async getSeriesNext(prefix, doctype) {
|
||||||
let series;
|
let series;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
series = await frappe.getDoc('NumberSeries', prefix);
|
series = await frappe.getDoc('NumberSeries', prefix);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -101,14 +103,7 @@ module.exports = {
|
|||||||
series = await frappe.getDoc('NumberSeries', prefix);
|
series = await frappe.getDoc('NumberSeries', prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
let next = await series.next(doctype);
|
return 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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async createNumberSeries(prefix, referenceType, start = 1001) {
|
async createNumberSeries(prefix, referenceType, start = 1001) {
|
||||||
|
@ -33,6 +33,7 @@ module.exports = {
|
|||||||
fieldtype: 'Int',
|
fieldtype: 'Int',
|
||||||
default: 1001,
|
default: 1001,
|
||||||
required: 1,
|
required: 1,
|
||||||
|
minvalue: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldname: 'padZeros',
|
fieldname: 'padZeros',
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
const { getPaddedName } = require('@/utils');
|
||||||
const frappe = require('frappe');
|
const frappe = require('frappe');
|
||||||
const BaseDocument = require('frappe/model/document');
|
const BaseDocument = require('frappe/model/document');
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ module.exports = class NumberSeries extends BaseDocument {
|
|||||||
this.current = this.start;
|
this.current = this.start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async next(doctype) {
|
async next(doctype) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
@ -17,13 +19,19 @@ module.exports = class NumberSeries extends BaseDocument {
|
|||||||
|
|
||||||
this.current++;
|
this.current++;
|
||||||
await this.update();
|
await this.update();
|
||||||
return this.current;
|
return this.getPaddedName(this.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkIfCurrentExists(doctype) {
|
async checkIfCurrentExists(doctype) {
|
||||||
if (!doctype) {
|
if (!doctype) {
|
||||||
return true;
|
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 map = invertMap(DEFAULT_NUMBER_SERIES);
|
||||||
const rows = await frappe.db.knex('NumberSeries');
|
const rows = await frappe.db.knex('NumberSeries');
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
|
if (row.referenceType === map[row.name]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
row.referenceType = map[row.name];
|
row.referenceType = map[row.name];
|
||||||
}
|
}
|
||||||
await frappe.db.prestigeTheTable('NumberSeries', rows);
|
await frappe.db.prestigeTheTable('NumberSeries', rows);
|
||||||
|
@ -547,3 +547,12 @@ export function invertMap(map) {
|
|||||||
|
|
||||||
return inverted;
|
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