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 1 commit
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
Prev Previous commit
Next Next commit
chore: make method more generic
  • Loading branch information
ssiyad committed May 4, 2023
commit 20536bee6b3ab726244ef650b369e20130f0d033
21 changes: 18 additions & 3 deletions helpdesk/api/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from frappe.contacts.doctype.contact.contact import get_contact_name
from frappe.core.doctype.data_import.data_import import start_import
from frappe.handler import upload_file
from frappe.model.document import Document
from frappe.utils import datetime
from frappe.website.utils import cleanup_page_name

Expand All @@ -21,13 +22,27 @@


@frappe.whitelist()
def bulk_insert():
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": "HD Ticket",
"import_type": "Insert New Records",
"reference_doctype": target_doctype,
"import_type": import_type,
"import_file": file.file_url,
}
)
Expand Down
Loading