[feature] Replace Company Abbr
diff --git a/setup/doctype/company/company.js b/setup/doctype/company/company.js
index ca3c93b..d023f8d 100644
--- a/setup/doctype/company/company.js
+++ b/setup/doctype/company/company.js
@@ -2,14 +2,53 @@
// License: GNU General Public License v3. See license.txt
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
- if(doc.abbr && !doc.__islocal)
- cur_frm.set_df_property("abbr", "read_only", 1)
+ if(doc.abbr && !doc.__islocal) {
+ 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) {
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) {
var iChars = "!@#$%^*+=-[]\\\';,/{}|\":<>?";
for (var i = 0; i < t.length; i++) {
diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py
index 9746eb2..7da2310 100644
--- a/setup/doctype/company/company.py
+++ b/setup/doctype/company/company.py
@@ -5,9 +5,7 @@
import webnotes
from webnotes import _, msgprint
-from webnotes.utils import cstr, cint
-from webnotes.model.doc import Document
-from webnotes.model.code import get_obj
+from webnotes.utils import cstr
import webnotes.defaults
sql = webnotes.conn.sql
@@ -316,4 +314,19 @@
where doctype='Global Defaults' and field='default_company'
and value=%s""", (newdn, olddn))
- webnotes.defaults.clear_default("company", value=olddn)
\ No newline at end of file
+ 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()
\ No newline at end of file
diff --git a/stock/doctype/warehouse/warehouse.py b/stock/doctype/warehouse/warehouse.py
index 476a6f6..cfa2782 100644
--- a/stock/doctype/warehouse/warehouse.py
+++ b/stock/doctype/warehouse/warehouse.py
@@ -4,7 +4,7 @@
from __future__ import unicode_literals
import webnotes
-from webnotes.utils import cint, flt, validate_email_add
+from webnotes.utils import cint, validate_email_add
from webnotes import msgprint, _
sql = webnotes.conn.sql
@@ -115,8 +115,9 @@
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
def on_rename(self, newdn, olddn, merge=False):
- webnotes.conn.set_value("Account", {"account_type": "Warehouse", "master_name": olddn},
- "master_name", newdn)
+ account = webnotes.conn.get_value("Account", {"account_type": "Warehouse",
+ "master_name": olddn})
+ webnotes.conn.set_value("Account", account, "master_name", newdn)
if merge:
from stock.stock_ledger import update_entries_after