From dad938c6cab80af16aea5ac44a642c0748ef5829 Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Sat, 7 Nov 2026 18:39:13 +0530 Subject: [PATCH 1/2] refactor: pick payment gateway and account in webshop settings --- webshop/templates/pages/order.js | 11 +---------- .../webshop_settings/test_webshop_settings.py | 11 +++++++++++ .../webshop_settings/webshop_settings.js | 9 +++++++-- .../webshop_settings/webshop_settings.json | 19 ++++++++++++++----- .../webshop_settings/webshop_settings.py | 2 +- webshop/webshop/shopping_cart/cart.py | 16 ++++++++-------- 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/webshop/templates/pages/order.js b/webshop/templates/pages/order.js index 96608f8516..ce4137c4a5 100644 --- a/webshop/templates/pages/order.js +++ b/webshop/templates/pages/order.js @@ -14,7 +14,7 @@ frappe.ready(() => { if (!loyalty_points) return; - const callback = async (r) => { + const callback = (r) => { if (!r) return; var message = ""; @@ -41,15 +41,6 @@ frappe.ready(() => { loyalty_points, }; - const payment_gateway_account = await frappe.db.get_single_value( - "Webshop Settings", - "payment_gateway_account" - ); - - if (payment_gateway_account) { - args_obj.payment_gateway_account = payment_gateway_account; - } - const args_str = Object.entries(args_obj) .map((e) => e[0] + "=" + e[1]) .join("&"); diff --git a/webshop/webshop/doctype/webshop_settings/test_webshop_settings.py b/webshop/webshop/doctype/webshop_settings/test_webshop_settings.py index 90c0dafd93..afb23eaeaf 100644 --- a/webshop/webshop/doctype/webshop_settings/test_webshop_settings.py +++ b/webshop/webshop/doctype/webshop_settings/test_webshop_settings.py @@ -39,6 +39,17 @@ def test_invalid_filter_fields(self): self.assertRaises(frappe.ValidationError, settings.save) + def test_checkout_needs_payment_gateway_and_account(self): + settings = frappe.get_doc("Webshop Settings") + + settings.update({"enable_checkout": 1, "payment_gateway": "_Test Gateway", "payment_account": None}) + settings.validate_checkout() + self.assertFalse(settings.enable_checkout) + + settings.update({"enable_checkout": 1, "payment_account": "_Test Account"}) + settings.validate_checkout() + self.assertTrue(settings.enable_checkout) + def setup_webshop_settings(values_dict): "Accepts a dict of values that updates Webshop Settings." diff --git a/webshop/webshop/doctype/webshop_settings/webshop_settings.js b/webshop/webshop/doctype/webshop_settings/webshop_settings.js index e071f7b3e2..229c8c9446 100644 --- a/webshop/webshop/doctype/webshop_settings/webshop_settings.js +++ b/webshop/webshop/doctype/webshop_settings/webshop_settings.js @@ -8,14 +8,19 @@ frappe.ui.form.on("Webshop Settings", { frm.refresh_field("quotation_series"); } - frm.set_query("payment_gateway_account", function () { + frm.set_query("payment_account", function () { return { + query: "erpnext.accounts.doctype.payment_request.payment_request.get_payment_account", filters: { - payment_channel: ["in", ["Email", "Phone"]], + payment_gateway: frm.doc.payment_gateway, + company: frm.doc.company, }, }; }); }, + payment_gateway: function (frm) { + frm.set_value("payment_account", null); + }, refresh: function (frm) { if (frm.doc.enabled) { frm.get_field("store_page_docs") diff --git a/webshop/webshop/doctype/webshop_settings/webshop_settings.json b/webshop/webshop/doctype/webshop_settings/webshop_settings.json index a3341456a4..cfc26bc8f2 100644 --- a/webshop/webshop/doctype/webshop_settings/webshop_settings.json +++ b/webshop/webshop/doctype/webshop_settings/webshop_settings.json @@ -38,7 +38,8 @@ "show_price_in_quotation", "column_break_27", "save_quotations_as_draft", - "payment_gateway_account", + "payment_gateway", + "payment_account", "payment_success_url", "add_ons_section", "enable_wishlist", @@ -254,11 +255,19 @@ }, { "depends_on": "enable_checkout", - "fieldname": "payment_gateway_account", + "fieldname": "payment_gateway", "fieldtype": "Link", - "label": "Payment Gateway Account", + "label": "Payment Gateway", "mandatory_depends_on": "enable_checkout", - "options": "Payment Gateway Account" + "options": "Payment Gateway" + }, + { + "depends_on": "enable_checkout", + "fieldname": "payment_account", + "fieldtype": "Link", + "label": "Payment Account", + "mandatory_depends_on": "enable_checkout", + "options": "Account" }, { "collapsible": 1, @@ -387,7 +396,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2026-09-15 05:28:20.808725", + "modified": "2026-11-06 18:00:00.000000", "modified_by": "Administrator", "module": "Webshop", "name": "Webshop Settings", diff --git a/webshop/webshop/doctype/webshop_settings/webshop_settings.py b/webshop/webshop/doctype/webshop_settings/webshop_settings.py index 881db3f289..603e11c7b5 100644 --- a/webshop/webshop/doctype/webshop_settings/webshop_settings.py +++ b/webshop/webshop/doctype/webshop_settings/webshop_settings.py @@ -76,7 +76,7 @@ def validate_attribute_filters(self): self.hide_variants = 0 def validate_checkout(self): - if self.enable_checkout and not self.payment_gateway_account: + if self.enable_checkout and not (self.payment_gateway and self.payment_account): self.enable_checkout = 0 def validate_search_index_fields(self): diff --git a/webshop/webshop/shopping_cart/cart.py b/webshop/webshop/shopping_cart/cart.py index 9bde7119cc..a0a069fbed 100644 --- a/webshop/webshop/shopping_cart/cart.py +++ b/webshop/webshop/shopping_cart/cart.py @@ -606,20 +606,20 @@ def get_party(user=None): def get_debtors_account(cart_settings): - if not cart_settings.payment_gateway_account: - frappe.throw(_("Payment Gateway Account not set"), _("Mandatory")) + if not cart_settings.payment_account: + frappe.throw(_("Payment Account not set"), _("Mandatory")) - payment_gateway_account_currency = frappe.get_doc( - "Payment Gateway Account", cart_settings.payment_gateway_account - ).currency + payment_account_currency = frappe.get_cached_value( + "Account", cart_settings.payment_account, "account_currency" + ) - account_name = _("Debtors ({0})").format(payment_gateway_account_currency) + account_name = _("Debtors ({0})").format(payment_account_currency) debtors_account_name = get_account_name( "Receivable", "Asset", is_group=0, - account_currency=payment_gateway_account_currency, + account_currency=payment_account_currency, company=cart_settings.company, ) @@ -634,7 +634,7 @@ def get_debtors_account(cart_settings): root_type="Asset", is_group=1, company=cart_settings.company ), "account_name": account_name, - "currency": payment_gateway_account_currency, + "currency": payment_account_currency, } ).insert(ignore_permissions=True) From 6949e474cadf974e39d895df8aa0dbb9ae71d73a Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Sat, 7 Nov 2026 18:39:14 +0530 Subject: [PATCH 2/2] feat: move the webshop settings gateway account to gateway and account --- webshop/patches.txt | 3 ++- .../split_payment_gateway_account_setting.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 webshop/patches/split_payment_gateway_account_setting.py diff --git a/webshop/patches.txt b/webshop/patches.txt index 5c7abf22a9..e9770ae0f6 100644 --- a/webshop/patches.txt +++ b/webshop/patches.txt @@ -4,4 +4,5 @@ webshop.patches.add_homepage_field #09-05-2024 webshop.patches.enable_allow_to_guest_view_for_item_group -webshop.patches.clear_cache_for_item_group_route \ No newline at end of file +webshop.patches.clear_cache_for_item_group_route +webshop.patches.split_payment_gateway_account_setting \ No newline at end of file diff --git a/webshop/patches/split_payment_gateway_account_setting.py b/webshop/patches/split_payment_gateway_account_setting.py new file mode 100644 index 0000000000..eeaad74dc9 --- /dev/null +++ b/webshop/patches/split_payment_gateway_account_setting.py @@ -0,0 +1,22 @@ +import frappe + + +def execute(): + # the field is gone from the doctype by now, but its value is still stored + old_account = frappe.db.get_singles_dict("Webshop Settings").get("payment_gateway_account") + if not old_account: + return + + # select everything because the parent column may not exist until the payments patch runs + row = frappe.db.get_value("Payment Gateway Account", old_account, "*", as_dict=True) + if not row: + return + + frappe.db.set_single_value( + "Webshop Settings", + { + "payment_gateway": row.get("parent") or row.get("payment_gateway"), + "payment_account": row.payment_account, + }, + update_modified=False, + )