mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 05:29:18 +00:00
Merge pull request #45609 from rohitwaghchaure/fixed-support-30336
fix: reposting issue with s3 backup
This commit is contained in:
@@ -406,23 +406,13 @@ def create_json_gz_file(data, doc, file_name=None) -> str:
|
|||||||
compressed_content = gzip.compress(encoded_content)
|
compressed_content = gzip.compress(encoded_content)
|
||||||
|
|
||||||
if not file_name:
|
if not file_name:
|
||||||
json_filename = f"{scrub(doc.doctype)}-{scrub(doc.name)}.json.gz"
|
return create_file(doc, compressed_content)
|
||||||
_file = frappe.get_doc(
|
|
||||||
{
|
|
||||||
"doctype": "File",
|
|
||||||
"file_name": json_filename,
|
|
||||||
"attached_to_doctype": doc.doctype,
|
|
||||||
"attached_to_name": doc.name,
|
|
||||||
"attached_to_field": "reposting_data_file",
|
|
||||||
"content": compressed_content,
|
|
||||||
"is_private": 1,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
_file.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
return _file.file_url
|
|
||||||
else:
|
else:
|
||||||
file_doc = frappe.get_doc("File", file_name)
|
file_doc = frappe.get_doc("File", file_name)
|
||||||
|
if "/frappe_s3_attachment." in file_doc.file_url:
|
||||||
|
file_doc.delete()
|
||||||
|
return create_file(doc, compressed_content)
|
||||||
|
|
||||||
path = file_doc.get_full_path()
|
path = file_doc.get_full_path()
|
||||||
|
|
||||||
with open(path, "wb") as f:
|
with open(path, "wb") as f:
|
||||||
@@ -431,6 +421,24 @@ def create_json_gz_file(data, doc, file_name=None) -> str:
|
|||||||
return doc.reposting_data_file
|
return doc.reposting_data_file
|
||||||
|
|
||||||
|
|
||||||
|
def create_file(doc, compressed_content):
|
||||||
|
json_filename = f"{scrub(doc.doctype)}-{scrub(doc.name)}.json.gz"
|
||||||
|
_file = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "File",
|
||||||
|
"file_name": json_filename,
|
||||||
|
"attached_to_doctype": doc.doctype,
|
||||||
|
"attached_to_name": doc.name,
|
||||||
|
"attached_to_field": "reposting_data_file",
|
||||||
|
"content": compressed_content,
|
||||||
|
"is_private": 1,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_file.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
return _file.file_url
|
||||||
|
|
||||||
|
|
||||||
def get_items_to_be_repost(voucher_type=None, voucher_no=None, doc=None, reposting_data=None):
|
def get_items_to_be_repost(voucher_type=None, voucher_no=None, doc=None, reposting_data=None):
|
||||||
if not reposting_data and doc and doc.reposting_data_file:
|
if not reposting_data and doc and doc.reposting_data_file:
|
||||||
reposting_data = get_reposting_data(doc.reposting_data_file)
|
reposting_data = get_reposting_data(doc.reposting_data_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user