2
0
mirror of https://github.com/frappe/books.git synced 2025-01-12 11:04:12 +00:00

fix: doc.setName

This commit is contained in:
Faris Ansari 2019-10-30 01:08:43 +05:30
parent 26f0a720e2
commit 88c84e805b
3 changed files with 8 additions and 3 deletions

View File

@ -214,7 +214,7 @@ module.exports = {
async getNewDoc(doctype) { async getNewDoc(doctype) {
let doc = this.newDoc({ doctype: doctype }); let doc = this.newDoc({ doctype: doctype });
doc._notInserted = true; doc._notInserted = true;
doc.name = this.getRandomString(); await doc.setName();
this.addToCache(doc); this.addToCache(doc);
return doc; return doc;
}, },

View File

@ -337,6 +337,10 @@ module.exports = class BaseDocument extends Observable {
} }
} }
async setName() {
await naming.setName(this);
}
async commit() { async commit() {
// re-run triggers // re-run triggers
this.setStandardValues(); this.setStandardValues();
@ -347,7 +351,7 @@ module.exports = class BaseDocument extends Observable {
} }
async insert() { async insert() {
await naming.setName(this); await this.setName();
await this.commit(); await this.commit();
await this.trigger('beforeInsert'); await this.trigger('beforeInsert');

View File

@ -1,4 +1,5 @@
const frappe = require('frappejs'); const frappe = require('frappejs');
const { getRandomString } = require('frappejs/utils');
module.exports = { module.exports = {
async setName(doc) { async setName(doc) {
@ -30,7 +31,7 @@ module.exports = {
// assign a random name by default // assign a random name by default
// override doc to set a name // override doc to set a name
if (!doc.name) { if (!doc.name) {
doc.name = frappe.getRandomString(); doc.name = getRandomString();
} }
}, },