Chart of account not update if Company Abbreviation changed

erpnext.setup.doctype.company.company.replace_abbr

Queue / Worker	Job	Created
failed	
erpnext.setup.doctype.company.company.replace_abbr
Traceback (most recent call last):
  File "/home/vishal/frappe-bench-production/env/local/lib/python2.7/site-packages/rq/worker.py", line 793, in perform_job
    rv = job.perform()
  File "/home/vishal/frappe-bench-production/env/local/lib/python2.7/site-packages/rq/job.py", line 599, in perform
    self._result = self._execute()
  File "/home/vishal/frappe-bench-production/env/local/lib/python2.7/site-packages/rq/job.py", line 605, in _execute
    return self.func(*self.args, **self.kwargs)
  File "/home/vishal/frappe-bench-production/apps/frappe/frappe/utils/background_jobs.py", line 97, in execute_job
    method(**kwargs)
  File "/home/vishal/frappe-bench-production/apps/erpnext/erpnext/setup/doctype/company/company.py", line 340, in replace_abbr
    _rename_records(dt)
  File "/home/vishal/frappe-bench-production/apps/erpnext/erpnext/setup/doctype/company/company.py", line 337, in _rename_records
    _rename_record(d)
  File "/home/vishal/frappe-bench-production/apps/erpnext/erpnext/setup/doctype/company/company.py", line 331, in _rename_record
    frappe.rename_doc(dt, doc[0], parts[0] + " - " + new)
  File "/home/vishal/frappe-bench-production/apps/frappe/frappe/__init__.py", line 700, in rename_doc
    return rename_doc(*args, **kwargs)
  File "/home/vishal/frappe-bench-production/apps/frappe/frappe/model/rename_doc.py", line 39, in rename_doc
    new = validate_rename(doctype, new, meta, merge, force, ignore_permissions)
  File "/home/vishal/frappe-bench-production/apps/frappe/frappe/model/rename_doc.py", line 132, in validate_rename
    frappe.msgprint(_("{0} not allowed to be renamed").format(_(doctype)), raise_exception=1)
  File "/home/vishal/frappe-bench-production/apps/frappe/frappe/__init__.py", line 309, in msgprint
    _raise_exception()
  File "/home/vishal/frappe-bench-production/apps/frappe/frappe/__init__.py", line 284, in _raise_exception
    raise ValidationError(encode(msg))
ValidationError: Account not allowed to be renamed

master branch

1 Like

I had the same issue, please also make a GitHub issue for this.

I’m using a workaround by copying the replace_abbr function from company.py into bench console with one slight modification: adding an argument force=True in the function frappe.rename_doc(dt, doc[0], parts[0] + " - " + new, force=True)

So basically if you’re comfortable with Python and bench console you can copy the function and call it from bench console:

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")

	frappe.db.set_value("Company", company, "abbr", new)

	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)

	for dt in ["Warehouse", "Account", "Cost Center"]:
		_rename_records(dt)
		frappe.db.commit()
2 Likes