Merge pull request #28977 from frappe/fix-copy-fields

fix: duplicate/copy doc
This commit is contained in:
Md Hussain Nagaria 2025-01-01 16:00:04 +05:30 committed by GitHub
commit a77787822c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 16 deletions

View file

@ -593,6 +593,7 @@
"fieldname": "api_key",
"fieldtype": "Data",
"label": "API Key",
"no_copy": 1,
"permlevel": 1,
"read_only": 1,
"unique": 1
@ -887,7 +888,7 @@
"link_fieldname": "user"
}
],
"modified": "2024-09-27 11:41:13.336662",
"modified": "2024-12-31 19:35:17.052698",
"modified_by": "Administrator",
"module": "Core",
"name": "User",

View file

@ -283,23 +283,23 @@ $.extend(frappe.model, {
},
copy_doc: function (doc, from_amend, parent_doc, parentfield) {
var no_copy_list = ["name", "amended_from", "amendment_date", "cancel_reason"];
var newdoc = frappe.model.get_new_doc(doc.doctype, parent_doc, parentfield);
let no_copy_list = ["name", "amended_from", "amendment_date", "cancel_reason"];
let newdoc = frappe.model.get_new_doc(doc.doctype, parent_doc, parentfield);
for (var key in doc) {
// dont copy name and blank fields
var df = frappe.meta.get_docfield(doc.doctype, key);
for (let key in doc) {
// don't copy name and blank fields
let df = frappe.meta.get_docfield(doc.doctype, key);
if (
df &&
key.substr(0, 2) != "__" &&
!no_copy_list.includes(key) &&
!(df && !from_amend && cint(df.no_copy) == 1)
) {
var value = doc[key] || [];
const is_internal_field = key.substring(0, 2) === "__";
const is_blocked_field = no_copy_list.includes(key);
const is_no_copy = !from_amend && df && cint(df.no_copy) == 1;
const is_password = df && df.fieldtype === "Password";
if (df && !is_internal_field && !is_blocked_field && !is_no_copy && !is_password) {
let value = doc[key] || [];
if (frappe.model.table_fields.includes(df.fieldtype)) {
for (var i = 0, j = value.length; i < j; i++) {
var d = value[i];
for (let i = 0, j = value.length; i < j; i++) {
let d = value[i];
frappe.model.copy_doc(d, from_amend, newdoc, df.fieldname);
}
} else {
@ -308,7 +308,7 @@ $.extend(frappe.model, {
}
}
var user = frappe.session.user;
let user = frappe.session.user;
newdoc.__islocal = 1;
newdoc.docstatus = 0;