fix: cast values for renaming autoincrement documents
- cast `name` values to integer - cast `link_field` values to string
This commit is contained in:
parent
0ef8001102
commit
e76c33cdbc
1 changed files with 12 additions and 6 deletions
|
|
@ -11,7 +11,7 @@ from frappe.model.dynamic_links import get_dynamic_link_map
|
|||
from frappe.model.naming import validate_name
|
||||
from frappe.model.utils.user_settings import sync_user_settings, update_user_settings_data
|
||||
from frappe.query_builder import Field
|
||||
from frappe.utils.data import sbool
|
||||
from frappe.utils.data import sbool, cint, cstr
|
||||
from frappe.utils.password import rename_password
|
||||
from frappe.utils.scheduler import is_scheduler_inactive
|
||||
|
||||
|
|
@ -118,8 +118,8 @@ def update_document_title(
|
|||
|
||||
def rename_doc(
|
||||
doctype: str | None = None,
|
||||
old: str | None = None,
|
||||
new: str | None = None,
|
||||
old: str | int | None = None,
|
||||
new: str | int | None = None,
|
||||
force: bool = False,
|
||||
merge: bool = False,
|
||||
ignore_permissions: bool = False,
|
||||
|
|
@ -157,6 +157,10 @@ def rename_doc(
|
|||
merge = sbool(merge)
|
||||
meta = frappe.get_meta(doctype)
|
||||
|
||||
if meta.naming_rule == 'Autoincrement':
|
||||
old = cint(old)
|
||||
new = cint(new)
|
||||
|
||||
if validate:
|
||||
old_doc = doc or frappe.get_doc(doctype, old)
|
||||
out = old_doc.run_method("before_rename", old, new, merge) or {}
|
||||
|
|
@ -350,8 +354,8 @@ def update_autoname_field(doctype: str, new: str, meta: "Meta") -> None:
|
|||
|
||||
def validate_rename(
|
||||
doctype: str,
|
||||
old: str,
|
||||
new: str,
|
||||
old: str | int,
|
||||
new: str | int,
|
||||
meta: "Meta",
|
||||
merge: bool,
|
||||
force: bool = False,
|
||||
|
|
@ -453,7 +457,9 @@ def update_link_field_values(link_fields: list[dict], old: str, new: str, doctyp
|
|||
if parent == new and doctype == "DocType":
|
||||
parent = old
|
||||
|
||||
frappe.db.set_value(parent, {docfield: old}, docfield, new, update_modified=False)
|
||||
# when a document with autoincrement naming is renamed, the old and new values are int
|
||||
# but link field values are always stored as varchar, so casting the values to string
|
||||
frappe.db.set_value(parent, {docfield: cstr(old)}, docfield, cstr(new), update_modified=False)
|
||||
|
||||
# update cached link_fields as per new
|
||||
if doctype == "DocType" and field["parent"] == old:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue