Browse Source

Merge pull request #2349 from rohitwaghchaure/rename_autoname_field

[Fix] Rename autoname field on rename of docname
version-14
Nabin Hait 8 years ago
committed by GitHub
parent
commit
262920288e
1 changed files with 9 additions and 0 deletions
  1. +9
    -0
      frappe/model/rename_doc.py

+ 9
- 0
frappe/model/rename_doc.py View File

@@ -85,8 +85,17 @@ def rename_parent_and_child(doctype, old, new, meta):
# rename the doc # rename the doc
frappe.db.sql("update `tab%s` set name=%s where name=%s" % (frappe.db.escape(doctype), '%s', '%s'), frappe.db.sql("update `tab%s` set name=%s where name=%s" % (frappe.db.escape(doctype), '%s', '%s'),
(new, old)) (new, old))
update_autoname_field(doctype, new, meta)
update_child_docs(old, new, meta) update_child_docs(old, new, meta)


def update_autoname_field(doctype, new, meta):
# update the value of the autoname field on rename of the docname
if meta.get('autoname'):
field = meta.get('autoname').split(':')
if field and field[0] == "field":
frappe.db.sql("update `tab%s` set %s=%s where name=%s" % (frappe.db.escape(doctype), field[1], '%s', '%s'),
(new, new))

def validate_rename(doctype, new, meta, merge, force, ignore_permissions): def validate_rename(doctype, new, meta, merge, force, ignore_permissions):
# using for update so that it gets locked and someone else cannot edit it while this rename is going on! # using for update so that it gets locked and someone else cannot edit it while this rename is going on!
exists = frappe.db.sql("select name from `tab{doctype}` where name=%s for update".format(doctype=frappe.db.escape(doctype)), new) exists = frappe.db.sql("select name from `tab{doctype}` where name=%s for update".format(doctype=frappe.db.escape(doctype)), new)


Loading…
Cancel
Save