chore: rename __temporary_name & check temp_doc_name

* renamed file_relink_temp_docname to __temporary_name
* added check for temp_doc_name in relink_files in case someone
    calls the function it directly
This commit is contained in:
Maharshi Patel 2023-10-13 10:20:03 +05:30
parent e888e49cc2
commit d9a8b7ee78
2 changed files with 6 additions and 3 deletions

View file

@ -359,6 +359,8 @@ def attach_files_to_document(doc: "Document", event) -> None:
def relink_files(doc, fieldname, temp_doc_name):
if not temp_doc_name:
return
from frappe.utils.data import add_to_date, now_datetime
"""
@ -391,12 +393,12 @@ def relink_files(doc, fieldname, temp_doc_name):
def relink_mismatched_files(doc: "Document") -> None:
if not doc.get("file_relink_temp_docname", None):
if not doc.get("__temporary_name", None):
return
attach_fields = doc.meta.get("fields", {"fieldtype": ["in", ["Attach", "Attach Image"]]})
for df in attach_fields:
if doc.get(df.fieldname):
relink_files(doc, df.fieldname, doc.file_relink_temp_docname)
relink_files(doc, df.fieldname, doc.__temporary_name)
def decode_file_content(content: bytes) -> bytes:

View file

@ -20,7 +20,8 @@ def savedocs(doc, action):
if doc.doctype not in ["DocType", "File"] and doc.name.startswith(
"new-" + doc.doctype.lower().replace(" ", "-")
):
doc.file_relink_temp_docname = doc.name
# required to relink missing attachments if they exist.
doc.__temporary_name = doc.name
set_local_name(doc)
# action