2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +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) {
let doc = this.newDoc({ doctype: doctype });
doc._notInserted = true;
doc.name = this.getRandomString();
await doc.setName();
this.addToCache(doc);
return doc;
},

View File

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

View File

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