mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 19:19:17 +00:00
more refactoring to renaming
This commit is contained in:
@@ -212,7 +212,7 @@ class DocType(TransactionBase):
|
||||
if self.doc.lead_name:
|
||||
sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
|
||||
|
||||
def on_rename(self,newdn,olddn):
|
||||
def on_rename(self, new, old):
|
||||
#update customer_name if not naming series
|
||||
if get_defaults().get('cust_master_name') == 'Customer Name':
|
||||
update_fields = [
|
||||
@@ -235,13 +235,14 @@ class DocType(TransactionBase):
|
||||
('Support Ticket', 'customer'),
|
||||
('Task', 'customer')]
|
||||
for rec in update_fields:
|
||||
sql("update `tab%s` set customer_name = '%s' where %s = '%s'" %(rec[0],newdn,rec[1],olddn))
|
||||
|
||||
old_account = webnotes.conn.get_value("Account", {"master_type": "Customer",
|
||||
"master_name": olddn})
|
||||
|
||||
#update master_name in doctype account
|
||||
sql("update `tabAccount` set master_name = '%s', master_type = 'Customer' where master_name = '%s'" %(newdn,olddn))
|
||||
sql("""update `tab%s` set customer_name = %s
|
||||
where `%s` = %s""" % (rec[0], "%s" ,rec[1], "%s"), (new, old))
|
||||
|
||||
from webnotes.model.rename_doc import rename_doc
|
||||
rename_doc("Account", old_account, newdn)
|
||||
for account in webnotes.conn.sql("""select name, account_name from
|
||||
tabAccount where master_name=%s and master_type='Customer'""", old, as_dict=1):
|
||||
if account.account_name != new:
|
||||
webnotes.rename_doc("Account", account.name, new)
|
||||
|
||||
#update master_name in doctype account
|
||||
webnotes.conn.sql("""update `tabAccount` set master_name = %s,
|
||||
master_type = 'Customer' where master_name = %s""", (new,old))
|
||||
|
||||
@@ -84,9 +84,8 @@ erpnext.SalesChart = Class.extend({
|
||||
// edit
|
||||
var node_links = [];
|
||||
|
||||
if (wn.boot.profile.can_read.indexOf(this.ctype) !== -1) {
|
||||
node_links.push('<a href="#!Form/'+encodeURIComponent(this.ctype)+'/'
|
||||
+encodeURIComponent(data.value)+'">Edit</a>');
|
||||
if (wn.model.can_read(this.ctype)) {
|
||||
node_links.push('<a onclick="erpnext.sales_chart.open();">Edit</a>');
|
||||
}
|
||||
|
||||
if(data.expandable) {
|
||||
@@ -95,6 +94,14 @@ erpnext.SalesChart = Class.extend({
|
||||
node_links.push('<a onclick="erpnext.sales_chart.new_node();">Add Child</a>');
|
||||
}
|
||||
}
|
||||
|
||||
if (wn.model.can_write(this.ctype)) {
|
||||
node_links.push('<a onclick="erpnext.sales_chart.rename()">Rename</a>');
|
||||
};
|
||||
|
||||
if (wn.model.can_delete(this.ctype)) {
|
||||
node_links.push('<a onclick="erpnext.sales_chart.delete()">Delete</a>');
|
||||
};
|
||||
|
||||
link.toolbar.append(node_links.join(" | "));
|
||||
},
|
||||
@@ -107,11 +114,12 @@ erpnext.SalesChart = Class.extend({
|
||||
fields: [
|
||||
{fieldtype:'Data', fieldname: 'name_field', label:'New ' + me.ctype + ' Name', reqd:true},
|
||||
{fieldtype:'Select', fieldname:'is_group', label:'Group Node',
|
||||
options:'No\nYes', description:'Entries can made only against non-group (leaf) nodes'},
|
||||
options:'No\nYes', description: "Further nodes can be only created under 'Group' type nodes"},
|
||||
{fieldtype:'Button', fieldname:'create_new', label:'Create New' }
|
||||
]
|
||||
})
|
||||
|
||||
d.set_value("is_group", "No");
|
||||
// create
|
||||
$(d.fields_dict.create_new.input).click(function() {
|
||||
var btn = this;
|
||||
@@ -138,5 +146,22 @@ erpnext.SalesChart = Class.extend({
|
||||
},
|
||||
selected_node: function() {
|
||||
return this.tree.$w.find('.tree-link.selected');
|
||||
}
|
||||
},
|
||||
open: function() {
|
||||
var node = this.selected_node();
|
||||
wn.set_route("Form", this.ctype, node.data("label"));
|
||||
},
|
||||
rename: function() {
|
||||
var node = this.selected_node();
|
||||
wn.model.rename_doc(this.ctype, node.data('label'), function(new_name) {
|
||||
console.log(new_name)
|
||||
node.data('label', new_name).find(".tree-label").html(new_name);
|
||||
});
|
||||
},
|
||||
delete: function() {
|
||||
var node = this.selected_node();
|
||||
wn.model.delete_doc(this.ctype, node.data('label'), function() {
|
||||
node.parent().remove();
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user