Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): ticket: bulk insert #1148

Merged
merged 4 commits into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions helpdesk/extends/data_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import frappe

from frappe.handler import upload_file
from frappe.model.document import Document


@frappe.whitelist()
def bulk_insert(
target_doctype: str, import_type: str = "Insert New Records"
) -> Document:
"""
Upload a file and initiate an import against a DocType. File can be of any
type supported by data import tool. File should be in a form with key `file`.

Caveats
- `doctype` can not be used as argument, since it is already used by `upload_file`
- `file` is not an explicit argument, but is required by `upload_file`

:param target_doctype: DocType against which import should be performed
:param import_type: An import type supported by data import tool
:return: Newly created `Data Import` document
"""
file = upload_file()
data_import_doc = frappe.get_doc(
{
"doctype": "Data Import",
"reference_doctype": target_doctype,
"import_type": import_type,
"import_file": file.file_url,
}
)

data_import_doc.save()
data_import_doc.start_import()

return data_import_doc