Skip to content

Commit

Permalink
refactor!: remove abbreviation renaming (#27766)
Browse files Browse the repository at this point in the history
Co-authored-by: Ankush Menat <ankush@iwebnotes.com>
  • Loading branch information
nextchamp-saqib and ankush authored Oct 7, 2021
1 parent 772d475 commit 64c1347
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 82 deletions.
41 changes: 0 additions & 41 deletions erpnext/setup/doctype/company/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,6 @@ frappe.ui.form.on("Company", {
});
},

change_abbreviation(frm) {
var dialog = new frappe.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() {
var args = dialog.get_values();
if (!args) return;
frappe.show_alert(__("Update in progress. It might take a while."));
return frappe.call({
method: "erpnext.setup.doctype.company.company.enqueue_replace_abbr",
args: {
"company": frm.doc.name,
"old": frm.doc.abbr,
"new": args.new_abbr
},
callback: function(r) {
if (r.exc) {
frappe.msgprint(__("There were errors."));
return;
} else {
frm.set_value("abbr", args.new_abbr);
}
dialog.hide();
frm.refresh();
},
btn: this
});
});
dialog.show();
},

company_name: function(frm) {
if(frm.doc.__islocal) {
// add missing " " arg in split method
Expand Down Expand Up @@ -164,10 +127,6 @@ frappe.ui.form.on("Company", {
}, __('Manage'));
}
}

frm.add_custom_button(__('Change Abbreviation'), () => {
frm.trigger('change_abbreviation');
}, __('Manage'));
}

erpnext.company.set_chart_of_accounts_options(frm.doc);
Expand Down
8 changes: 5 additions & 3 deletions erpnext/setup/doctype/company/company.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"label": "Abbr",
"oldfieldname": "abbr",
"oldfieldtype": "Data",
"reqd": 1
"reqd": 1,
"set_only_once": 1
},
{
"bold": 1,
Expand Down Expand Up @@ -747,10 +748,11 @@
"image_field": "company_logo",
"is_tree": 1,
"links": [],
"modified": "2021-07-12 11:27:06.353860",
"modified": "2021-10-04 12:09:25.833133",
"modified_by": "Administrator",
"module": "Setup",
"name": "Company",
"naming_rule": "By fieldname",
"nsm_parent_field": "parent_company",
"owner": "Administrator",
"permissions": [
Expand Down Expand Up @@ -808,4 +810,4 @@
"sort_field": "modified",
"sort_order": "ASC",
"track_changes": 1
}
}
38 changes: 0 additions & 38 deletions erpnext/setup/doctype/company/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,44 +399,6 @@ def on_trash(self):
if not frappe.db.get_value('GL Entry', {'company': self.name}):
frappe.db.sql("delete from `tabProcess Deferred Accounting` where company=%s", self.name)

@frappe.whitelist()
def enqueue_replace_abbr(company, old, new):
kwargs = dict(queue="long", company=company, old=old, new=new)
frappe.enqueue('erpnext.setup.doctype.company.company.replace_abbr', **kwargs)


@frappe.whitelist()
def replace_abbr(company, old, new):
new = new.strip()
if not new:
frappe.throw(_("Abbr can not be blank or space"))

frappe.only_for("System Manager")

def _rename_record(doc):
parts = doc[0].rsplit(" - ", 1)
if len(parts) == 1 or parts[1].lower() == old.lower():
frappe.rename_doc(dt, doc[0], parts[0] + " - " + new, force=True)

def _rename_records(dt):
# rename is expensive so let's be economical with memory usage
doc = (d for d in frappe.db.sql("select name from `tab%s` where company=%s" % (dt, '%s'), company))
for d in doc:
_rename_record(d)
try:
frappe.db.auto_commit_on_many_writes = 1
for dt in ["Warehouse", "Account", "Cost Center", "Department",
"Sales Taxes and Charges Template", "Purchase Taxes and Charges Template"]:
_rename_records(dt)
frappe.db.commit()
frappe.db.set_value("Company", company, "abbr", new)

except Exception:
frappe.log_error(title=_('Abbreviation Rename Error'))
finally:
frappe.db.auto_commit_on_many_writes = 0


def get_name_with_abbr(name, company):
company_abbr = frappe.get_cached_value('Company', company, "abbr")
parts = name.split(" - ")
Expand Down

0 comments on commit 64c1347

Please sign in to comment.