From 7af1b5d4ec8a1a264a65aa9883a880b789656129 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 23 May 2024 19:30:42 +0530 Subject: [PATCH] refactor: use `json` directly instead of using `frappe.json` (#41609) (cherry picked from commit 3f06f1905f6c86eaa5eb4d33765a46470892f576) Signed-off-by: Akhil Narang --- .../doctype/pos_invoice_merge_log/pos_invoice_merge_log.py | 2 +- .../process_payment_reconciliation.py | 4 +++- erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py | 5 +++-- .../doctype/unreconcile_payment/unreconcile_payment.py | 4 +++- erpnext/accounts/utils.py | 2 +- erpnext/selling/doctype/customer/test_customer.py | 4 +++- erpnext/stock/doctype/warehouse/warehouse.py | 1 - 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 7501df02c3f..b8548c1f4ce 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -481,7 +481,7 @@ def create_merge_logs(invoice_by_customer, closing_entry=None): if closing_entry: closing_entry.set_status(update=True, status="Failed") if isinstance(error_message, list): - error_message = frappe.json.dumps(error_message) + error_message = json.dumps(error_message) closing_entry.db_set("error_message", error_message) raise diff --git a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py index d4d66a51c34..5048fc5e25e 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py +++ b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py @@ -1,6 +1,8 @@ # Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt +import json + import frappe from frappe import _, qb from frappe.model.document import Document @@ -504,7 +506,7 @@ def is_any_doc_running(for_filter: str | dict | None = None) -> str | None: running_doc = None if for_filter: if isinstance(for_filter, str): - for_filter = frappe.json.loads(for_filter) + for_filter = json.loads(for_filter) running_doc = frappe.db.get_value( "Process Payment Reconciliation", diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index ee8658a9414..5cffe11e995 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2,6 +2,7 @@ # License: GNU General Public License v3. See license.txt import copy +import json import frappe from frappe.model.dynamic_links import get_dynamic_link_map @@ -3720,9 +3721,9 @@ class TestSalesInvoice(FrappeTestCase): map_docs( method="erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice", - source_names=frappe.json.dumps([dn1.name, dn2.name]), + source_names=json.dumps([dn1.name, dn2.name]), target_doc=si, - args=frappe.json.dumps({"customer": dn1.customer, "merge_taxes": 1, "filtered_children": []}), + args=json.dumps({"customer": dn1.customer, "merge_taxes": 1, "filtered_children": []}), ) si.save().submit() diff --git a/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py b/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py index edbd78db611..7612294a85c 100644 --- a/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py +++ b/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py @@ -1,6 +1,8 @@ # Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt +import json + import frappe from frappe import _, qb from frappe.model.document import Document @@ -161,7 +163,7 @@ def get_linked_payments_for_doc( @frappe.whitelist() def create_unreconcile_doc_for_selection(selections=None): if selections: - selections = frappe.json.loads(selections) + selections = json.loads(selections) # assuming each row is a unique voucher for row in selections: unrecon = frappe.new_doc("Unreconcile Payment") diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index bbb8900de39..1ad24c46603 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -56,7 +56,7 @@ def get_fiscal_year( date=None, fiscal_year=None, label="Date", verbose=1, company=None, as_dict=False, boolean=False ): if isinstance(boolean, str): - boolean = frappe.json.loads(boolean) + boolean = loads(boolean) fiscal_years = get_fiscal_years( date, fiscal_year, label, verbose, company, as_dict=as_dict, boolean=boolean diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 63a44cc19fb..90051673e70 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -2,6 +2,8 @@ # License: GNU General Public License v3. See license.txt +import json + import frappe from frappe.test_runner import make_test_records from frappe.tests.utils import FrappeTestCase @@ -321,7 +323,7 @@ class TestCustomer(FrappeTestCase): frappe.ValidationError, update_child_qty_rate, so.doctype, - frappe.json.dumps([modified_item]), + json.dumps([modified_item]), so.name, ) diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 6dcd3b6f484..aa9dfd2048e 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -1,7 +1,6 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt - import frappe from frappe import _, throw from frappe.contacts.address_and_contact import load_address_and_contact