[feature] Replace Company Abbr
This commit is contained in:
parent
c559ecf278
commit
953d0a955f
@ -2,14 +2,53 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||||
if(doc.abbr && !doc.__islocal)
|
if(doc.abbr && !doc.__islocal) {
|
||||||
cur_frm.set_df_property("abbr", "read_only", 1)
|
cur_frm.set_df_property("abbr", "read_only", 1);
|
||||||
|
if(in_list(user_roles, "System Manager"))
|
||||||
|
cur_frm.add_custom_button("Replace Abbreviation", cur_frm.cscript.replace_abbr)
|
||||||
|
}
|
||||||
|
|
||||||
if(!doc.__islocal) {
|
if(!doc.__islocal) {
|
||||||
cur_frm.toggle_enable("default_currency", !cur_frm.doc.__transactions_exist);
|
cur_frm.toggle_enable("default_currency", !cur_frm.doc.__transactions_exist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur_frm.cscript.replace_abbr = function() {
|
||||||
|
var dialog = new wn.ui.Dialog({
|
||||||
|
title: "Replace Abbr",
|
||||||
|
fields: [
|
||||||
|
{"fieldtype": "Data", "label": "New Abbreviation", "fieldname": "new_abbr",
|
||||||
|
"reqd": 1 },
|
||||||
|
{"fieldtype": "Button", "label": "Update", "fieldname": "update"},
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.fields_dict.update.$input.click(function() {
|
||||||
|
args = dialog.get_values();
|
||||||
|
if(!args) return;
|
||||||
|
return wn.call({
|
||||||
|
method: "setup.doctype.company.company.replace_abbr",
|
||||||
|
args: {
|
||||||
|
"company": cur_frm.doc.name,
|
||||||
|
"old": cur_frm.doc.abbr,
|
||||||
|
"new": args.new_abbr
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
if(r.exc) {
|
||||||
|
msgprint(wn._("There were errors."));
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
cur_frm.set_value("abbr", args.new_abbr);
|
||||||
|
}
|
||||||
|
dialog.hide();
|
||||||
|
cur_frm.refresh();
|
||||||
|
},
|
||||||
|
btn: this
|
||||||
|
})
|
||||||
|
});
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
cur_frm.cscript.has_special_chars = function(t) {
|
cur_frm.cscript.has_special_chars = function(t) {
|
||||||
var iChars = "!@#$%^*+=-[]\\\';,/{}|\":<>?";
|
var iChars = "!@#$%^*+=-[]\\\';,/{}|\":<>?";
|
||||||
for (var i = 0; i < t.length; i++) {
|
for (var i = 0; i < t.length; i++) {
|
||||||
|
@ -5,9 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
from webnotes import _, msgprint
|
from webnotes import _, msgprint
|
||||||
|
|
||||||
from webnotes.utils import cstr, cint
|
from webnotes.utils import cstr
|
||||||
from webnotes.model.doc import Document
|
|
||||||
from webnotes.model.code import get_obj
|
|
||||||
import webnotes.defaults
|
import webnotes.defaults
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
@ -316,4 +314,19 @@ class DocType:
|
|||||||
where doctype='Global Defaults' and field='default_company'
|
where doctype='Global Defaults' and field='default_company'
|
||||||
and value=%s""", (newdn, olddn))
|
and value=%s""", (newdn, olddn))
|
||||||
|
|
||||||
webnotes.defaults.clear_default("company", value=olddn)
|
webnotes.defaults.clear_default("company", value=olddn)
|
||||||
|
|
||||||
|
@webnotes.whitelist()
|
||||||
|
def replace_abbr(company, old, new):
|
||||||
|
webnotes.conn.set_value("Company", company, "abbr", new)
|
||||||
|
|
||||||
|
def _rename_record(dt):
|
||||||
|
for d in webnotes.conn.sql("select name from `tab%s` where company=%s" % (dt, '%s'), company):
|
||||||
|
parts = d[0].split(" - ")
|
||||||
|
if parts[-1].lower() == old.lower():
|
||||||
|
name_without_abbr = " - ".join(parts[:-1])
|
||||||
|
webnotes.rename_doc(dt, d[0], name_without_abbr + " - " + new)
|
||||||
|
|
||||||
|
for dt in ["Account", "Cost Center", "Warehouse"]:
|
||||||
|
_rename_record(dt)
|
||||||
|
webnotes.conn.commit()
|
@ -4,7 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
from webnotes.utils import cint, flt, validate_email_add
|
from webnotes.utils import cint, validate_email_add
|
||||||
from webnotes import msgprint, _
|
from webnotes import msgprint, _
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
@ -115,8 +115,9 @@ class DocType:
|
|||||||
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
||||||
|
|
||||||
def on_rename(self, newdn, olddn, merge=False):
|
def on_rename(self, newdn, olddn, merge=False):
|
||||||
webnotes.conn.set_value("Account", {"account_type": "Warehouse", "master_name": olddn},
|
account = webnotes.conn.get_value("Account", {"account_type": "Warehouse",
|
||||||
"master_name", newdn)
|
"master_name": olddn})
|
||||||
|
webnotes.conn.set_value("Account", account, "master_name", newdn)
|
||||||
|
|
||||||
if merge:
|
if merge:
|
||||||
from stock.stock_ledger import update_entries_after
|
from stock.stock_ledger import update_entries_after
|
||||||
|
Loading…
x
Reference in New Issue
Block a user