2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 12:10:06 +00:00

feat: Rename methods

This commit is contained in:
Faris Ansari 2019-10-06 03:16:14 +05:30
parent e0c6a1a411
commit 700ee9c55c
3 changed files with 16 additions and 0 deletions

View File

@ -299,6 +299,10 @@ module.exports = class Database extends Observable {
// await frappe.db.run('delete from SingleValue where parent=?', name)
}
async rename(doctype, oldName, newName) {
// await frappe.db.run('update doctype set name = ? where name = ?', name)
}
prepareChild(parenttype, parent, child, field, idx) {
if (!child.name) {
child.name = frappe.getRandomString();

View File

@ -159,6 +159,11 @@ module.exports = class sqliteDatabase extends Database {
await frappe.db.run('delete from SingleValue where parent=?', name)
}
async rename(doctype, oldName, newName) {
await frappe.db.run(`update ${baseDoctype} set name = ? where name = ?`, [newName, oldName]);
await frappe.db.commit();
}
async setValues(doctype, name, fieldValuePair) {
const meta = frappe.getMeta(doctype);
const validFields = this.getKeys(doctype);

View File

@ -346,6 +346,13 @@ module.exports = class BaseDocument extends Observable {
this.update();
}
async rename(newName) {
await this.trigger('beforeRename');
await frappe.db.rename(this.doctype, this.name, newName);
this.name = newName;
await this.trigger('afterRename');
}
// trigger methods on the class if they match
// with the trigger name
async trigger(event, params) {