mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
feat: update name setting
This commit is contained in:
parent
2de72153e4
commit
78955b9d52
@ -28,11 +28,23 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Current, per doc number series
|
||||
if (doc.numberSeries) {
|
||||
doc.name = await this.getSeriesNext(doc.numberSeries, doc.doctype);
|
||||
return;
|
||||
}
|
||||
|
||||
// if(doc.meta)
|
||||
|
||||
// Legacy, using doc settings for number series
|
||||
if (doc.meta.settings) {
|
||||
const numberSeries = (await doc.getSettings()).numberSeries;
|
||||
if (numberSeries) {
|
||||
doc.name = await this.getSeriesNext(numberSeries, doc.doctype);
|
||||
if (!numberSeries) {
|
||||
return;
|
||||
}
|
||||
|
||||
doc.name = await this.getSeriesNext(numberSeries, doc.doctype);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,27 +96,34 @@ module.exports = {
|
||||
if (!e.statusCode || e.statusCode !== 404) {
|
||||
throw e;
|
||||
}
|
||||
await this.createNumberSeries(prefix);
|
||||
|
||||
await this.createNumberSeries(prefix, doctype);
|
||||
series = await frappe.getDoc('NumberSeries', prefix);
|
||||
}
|
||||
|
||||
let next = await series.next(doctype);
|
||||
return prefix + next;
|
||||
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, setting, start = 1001) {
|
||||
if (!(await frappe.db.exists('NumberSeries', prefix))) {
|
||||
async createNumberSeries(prefix, referenceType, start = 1001) {
|
||||
const exists = await frappe.db.exists('NumberSeries', prefix);
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
const series = frappe.newDoc({
|
||||
doctype: 'NumberSeries',
|
||||
name: prefix,
|
||||
current: start,
|
||||
start,
|
||||
referenceType,
|
||||
});
|
||||
await series.insert();
|
||||
|
||||
if (setting) {
|
||||
const settingDoc = await frappe.getSingle(setting);
|
||||
settingDoc.numberSeries = series.name;
|
||||
await settingDoc.update();
|
||||
}
|
||||
}
|
||||
await series.insert();
|
||||
},
|
||||
};
|
||||
|
@ -3,8 +3,8 @@ const BaseDocument = require('frappe/model/document');
|
||||
|
||||
module.exports = class NumberSeries extends BaseDocument {
|
||||
validate() {
|
||||
if (this.current === null || this.current === undefined) {
|
||||
this.current = 0;
|
||||
if (!this.current) {
|
||||
this.current = this.start;
|
||||
}
|
||||
}
|
||||
async next(doctype) {
|
||||
|
@ -20,15 +20,15 @@ export default async function postStart() {
|
||||
frappe.metaCache = {};
|
||||
|
||||
// init naming series if missing
|
||||
await naming.createNumberSeries('SINV-', 'SalesInvoiceSettings');
|
||||
await naming.createNumberSeries('PINV-', 'PurchaseInvoiceSettings');
|
||||
await naming.createNumberSeries('PAY-', 'PaymentSettings');
|
||||
await naming.createNumberSeries('JV-', 'JournalEntrySettings');
|
||||
await naming.createNumberSeries('QTN-', 'QuotationSettings');
|
||||
await naming.createNumberSeries('SO-', 'SalesOrderSettings');
|
||||
await naming.createNumberSeries('OF-', 'FulfillmentSettings');
|
||||
await naming.createNumberSeries('PO-', 'PurchaseOrderSettings');
|
||||
await naming.createNumberSeries('PREC-', 'PurchaseReceiptSettings');
|
||||
await naming.createNumberSeries('SINV-', 'SalesInvoice');
|
||||
await naming.createNumberSeries('PINV-', 'PurchaseInvoice');
|
||||
await naming.createNumberSeries('PAY-', 'Payment');
|
||||
await naming.createNumberSeries('JV-', 'JournalEntry');
|
||||
// await naming.createNumberSeries('QTN-', 'QuotationSettings');
|
||||
// await naming.createNumberSeries('SO-', 'SalesOrderSettings');
|
||||
// await naming.createNumberSeries('OF-', 'FulfillmentSettings');
|
||||
// await naming.createNumberSeries('PO-', 'PurchaseOrderSettings');
|
||||
// await naming.createNumberSeries('PREC-', 'PurchaseReceiptSettings');
|
||||
|
||||
// fetch singles
|
||||
// so that they are available synchronously
|
||||
|
Loading…
Reference in New Issue
Block a user