mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-18 12:39:18 +00:00
refactor: ability to process in single transaction
(cherry picked from commit a158b825d7)
This commit is contained in:
@@ -20,7 +20,8 @@
|
|||||||
"section_break_tbej",
|
"section_break_tbej",
|
||||||
"doctypes",
|
"doctypes",
|
||||||
"doctypes_to_be_ignored",
|
"doctypes_to_be_ignored",
|
||||||
"amended_from"
|
"amended_from",
|
||||||
|
"process_in_single_transaction"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -129,12 +130,18 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "section_break_qpwb",
|
"fieldname": "section_break_qpwb",
|
||||||
"fieldtype": "Section Break"
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "process_in_single_transaction",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Process in Single Transaction"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-03-19 17:47:04.490196",
|
"modified": "2024-03-20 14:58:15.086360",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Transaction Deletion Record",
|
"name": "Transaction Deletion Record",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class TransactionDeletionRecord(Document):
|
|||||||
doctypes_to_be_ignored: DF.Table[TransactionDeletionRecordItem]
|
doctypes_to_be_ignored: DF.Table[TransactionDeletionRecordItem]
|
||||||
error_log: DF.LongText | None
|
error_log: DF.LongText | None
|
||||||
initialize_doctypes_table: DF.Check
|
initialize_doctypes_table: DF.Check
|
||||||
|
process_in_single_transaction: DF.Check
|
||||||
reset_company_default_values: DF.Check
|
reset_company_default_values: DF.Check
|
||||||
status: DF.Literal["Queued", "Running", "Failed", "Completed", "Cancelled"]
|
status: DF.Literal["Queued", "Running", "Failed", "Completed", "Cancelled"]
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
@@ -139,18 +140,19 @@ class TransactionDeletionRecord(Document):
|
|||||||
# Generate Job Id to uniquely identify each task for this document
|
# Generate Job Id to uniquely identify each task for this document
|
||||||
job_id = self.generate_job_name_for_task(task)
|
job_id = self.generate_job_name_for_task(task)
|
||||||
|
|
||||||
frappe.enqueue(
|
if self.process_in_single_transaction:
|
||||||
"frappe.utils.background_jobs.run_doc_method",
|
self.execute_task(task_to_execute=task)
|
||||||
doctype=self.doctype,
|
else:
|
||||||
name=self.name,
|
frappe.enqueue(
|
||||||
doc_method="execute_task",
|
"frappe.utils.background_jobs.run_doc_method",
|
||||||
job_id=job_id,
|
doctype=self.doctype,
|
||||||
queue="long",
|
name=self.name,
|
||||||
enqueue_after_commit=True,
|
doc_method="execute_task",
|
||||||
task_to_execute=task,
|
job_id=job_id,
|
||||||
)
|
queue="long",
|
||||||
|
enqueue_after_commit=True,
|
||||||
# todo: add a non-background job based approach as well
|
task_to_execute=task,
|
||||||
|
)
|
||||||
|
|
||||||
def execute_task(self, task_to_execute: str | None = None):
|
def execute_task(self, task_to_execute: str | None = None):
|
||||||
if task_to_execute:
|
if task_to_execute:
|
||||||
|
|||||||
Reference in New Issue
Block a user