feat: add an argument pass mechanism to bulk transactions

This commit is contained in:
David Arnold 2024-01-23 17:42:56 +01:00
parent 4832175341
commit ffd38362d5
No known key found for this signature in database
GPG Key ID: AB15A6AF1101390D
2 changed files with 13 additions and 4 deletions

View File

@ -1,7 +1,7 @@
frappe.provide("erpnext.bulk_transaction_processing");
$.extend(erpnext.bulk_transaction_processing, {
create: function(listview, from_doctype, to_doctype) {
create: function(listview, from_doctype, to_doctype, args) {
let checked_items = listview.get_checked_items();
const doc_name = [];
checked_items.forEach((Item)=> {
@ -15,7 +15,7 @@ $.extend(erpnext.bulk_transaction_processing, {
if (doc_name.length == 0) {
frappe.call({
method: "erpnext.utilities.bulk_transaction.transaction_processing",
args: {data: checked_items, from_doctype: from_doctype, to_doctype: to_doctype}
args: {data: checked_items, from_doctype: from_doctype, to_doctype: to_doctype, args: args}
}).then(()=> {
});

View File

@ -7,12 +7,15 @@ from frappe.utils import get_link_to_form, today
@frappe.whitelist()
def transaction_processing(data, from_doctype, to_doctype):
def transaction_processing(data, from_doctype, to_doctype, args=None):
if isinstance(data, str):
deserialized_data = json.loads(data)
else:
deserialized_data = data
if isinstance(args, str):
args = frappe._dict(json.loads(args))
length_of_data = len(deserialized_data)
frappe.msgprint(
@ -23,6 +26,7 @@ def transaction_processing(data, from_doctype, to_doctype):
deserialized_data=deserialized_data,
from_doctype=from_doctype,
to_doctype=to_doctype,
args=args,
)
@ -71,8 +75,13 @@ def update_log(log_name, status, retried, err=None):
frappe.db.set_value("Bulk Transaction Log Detail", log_name, "error_description", err)
def job(deserialized_data, from_doctype, to_doctype):
def job(deserialized_data, from_doctype, to_doctype, args):
fail_count = 0
if args:
# currently: flag-based transport to `task`
frappe.flags.args = args
for d in deserialized_data:
try:
doc_name = d.get("name")