diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js index f15c2bdab21..ab9a50f8285 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js +++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.js @@ -8,4 +8,14 @@ frappe.ui.form.on("Payment Gateway Account", { frm.set_df_property("payment_gateway", "read_only", 1); } }, + + setup(frm) { + frm.set_query("payment_account", function () { + return { + filters: { + company: frm.doc.company, + }, + }; + }); + }, }); diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json index cc0f3d1b52b..cb258a89741 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json +++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.json @@ -7,6 +7,7 @@ "field_order": [ "payment_gateway", "payment_channel", + "company", "is_default", "column_break_4", "payment_account", @@ -71,11 +72,21 @@ "fieldtype": "Select", "label": "Payment Channel", "options": "\nEmail\nPhone\nOther" + }, + { + "fieldname": "company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "options": "Company", + "print_hide": 1, + "remember_last_selected_value": 1, + "reqd": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2024-03-29 18:53:09.836254", + "modified": "2025-07-14 16:49:55.210352", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Gateway Account", @@ -94,6 +105,7 @@ "write": 1 } ], + "row_format": "Dynamic", "sort_field": "creation", "sort_order": "DESC", "states": [] diff --git a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.py b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.py index f1bf363eca0..7c58949be8b 100644 --- a/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.py +++ b/erpnext/accounts/doctype/payment_gateway_account/payment_gateway_account.py @@ -15,6 +15,7 @@ class PaymentGatewayAccount(Document): if TYPE_CHECKING: from frappe.types import DF + company: DF.Link currency: DF.ReadOnly | None is_default: DF.Check message: DF.SmallText | None @@ -24,7 +25,8 @@ class PaymentGatewayAccount(Document): # end: auto-generated types def autoname(self): - self.name = self.payment_gateway + " - " + self.currency + abbr = frappe.db.get_value("Company", self.company, "abbr") + self.name = self.payment_gateway + " - " + self.currency + " - " + abbr def validate(self): self.currency = frappe.get_cached_value("Account", self.payment_account, "account_currency") @@ -34,13 +36,15 @@ class PaymentGatewayAccount(Document): def update_default_payment_gateway(self): if self.is_default: - frappe.db.sql( - """update `tabPayment Gateway Account` set is_default = 0 - where is_default = 1 """ + frappe.db.set_value( + "Payment Gateway Account", + {"is_default": 1, "name": ["!=", self.name], "company": self.company}, + "is_default", + 0, ) def set_as_default_if_not_set(self): - if not frappe.db.get_value( - "Payment Gateway Account", {"is_default": 1, "name": ("!=", self.name)}, "name" + if not frappe.db.exists( + "Payment Gateway Account", {"is_default": 1, "name": ("!=", self.name), "company": self.company} ): self.is_default = 1 diff --git a/erpnext/accounts/doctype/payment_request/payment_request.js b/erpnext/accounts/doctype/payment_request/payment_request.js index 44313e5c0d2..1d4c8d5280d 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.js +++ b/erpnext/accounts/doctype/payment_request/payment_request.js @@ -9,6 +9,14 @@ frappe.ui.form.on("Payment Request", { query: "erpnext.setup.doctype.party_type.party_type.get_party_type", }; }); + + frm.set_query("payment_gateway_account", function () { + return { + filters: { + company: frm.doc.company, + }, + }; + }); }, }); diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index db0992014a7..cafd2e4b721 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -534,7 +534,8 @@ def make_payment_request(**args): frappe.throw(_("Payment Requests cannot be created against: {0}").format(frappe.bold(args.dt))) ref_doc = args.ref_doc or frappe.get_doc(args.dt, args.dn) - + if not args.get("company"): + args.company = ref_doc.company gateway_account = get_gateway_details(args) or frappe._dict() grand_total = get_amount(ref_doc, gateway_account.get("payment_account")) @@ -781,7 +782,7 @@ def get_gateway_details(args): # nosemgrep """ Return gateway and payment account of default payment gateway """ - gateway_account = args.get("payment_gateway_account", {"is_default": 1}) + gateway_account = args.get("payment_gateway_account", {"is_default": 1, "company": args.company}) return get_payment_gateway_account(gateway_account) diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index a0a60a0e142..1f97b8b5784 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -34,12 +34,14 @@ payment_method = [ "payment_gateway": "_Test Gateway", "payment_account": "_Test Bank - _TC", "currency": "INR", + "company": "_Test Company", }, { "doctype": "Payment Gateway Account", "payment_gateway": "_Test Gateway", "payment_account": "_Test Bank USD - _TC", "currency": "USD", + "company": "_Test Company", }, { "doctype": "Payment Gateway Account", @@ -47,6 +49,7 @@ payment_method = [ "payment_account": "_Test Bank USD - _TC", "payment_channel": "Other", "currency": "USD", + "company": "_Test Company", }, { "doctype": "Payment Gateway Account", @@ -54,6 +57,7 @@ payment_method = [ "payment_account": "_Test Bank USD - _TC", "payment_channel": "Phone", "currency": "USD", + "company": "_Test Company", }, ] @@ -67,7 +71,11 @@ class TestPaymentRequest(IntegrationTestCase): for method in payment_method: if not frappe.db.get_value( "Payment Gateway Account", - {"payment_gateway": method["payment_gateway"], "currency": method["currency"]}, + { + "payment_gateway": method["payment_gateway"], + "currency": method["currency"], + "company": method["company"], + }, "name", ): frappe.get_doc(method).insert(ignore_permissions=True) @@ -103,7 +111,7 @@ class TestPaymentRequest(IntegrationTestCase): dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com", - payment_gateway_account="_Test Gateway - INR", + payment_gateway_account="_Test Gateway - INR - _TC", ) self.assertEqual(pr.reference_doctype, "Sales Order") @@ -117,7 +125,7 @@ class TestPaymentRequest(IntegrationTestCase): dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com", - payment_gateway_account="_Test Gateway - USD", + payment_gateway_account="_Test Gateway - USD - _TC", ) self.assertEqual(pr.reference_doctype, "Sales Invoice") @@ -130,7 +138,7 @@ class TestPaymentRequest(IntegrationTestCase): pr = make_payment_request( dt="Sales Order", dn=so.name, - payment_gateway_account="_Test Gateway Other - USD", + payment_gateway_account="_Test Gateway Other - USD - _TC", submit_doc=True, return_doc=True, ) @@ -145,7 +153,7 @@ class TestPaymentRequest(IntegrationTestCase): pr = make_payment_request( dt="Sales Order", dn=so.name, - payment_gateway_account="_Test Gateway - USD", # email channel + payment_gateway_account="_Test Gateway - USD - _TC", # email channel submit_doc=False, return_doc=True, ) @@ -163,7 +171,7 @@ class TestPaymentRequest(IntegrationTestCase): pr = make_payment_request( dt="Sales Order", dn=so.name, - payment_gateway_account="_Test Gateway Phone - USD", + payment_gateway_account="_Test Gateway Phone - USD - _TC", submit_doc=True, return_doc=True, ) @@ -180,7 +188,7 @@ class TestPaymentRequest(IntegrationTestCase): pr = make_payment_request( dt="Sales Order", dn=so.name, - payment_gateway_account="_Test Gateway - USD", # email channel + payment_gateway_account="_Test Gateway - USD - _TC", # email channel submit_doc=True, return_doc=True, ) @@ -201,7 +209,7 @@ class TestPaymentRequest(IntegrationTestCase): pr = make_payment_request( dt="Sales Order", dn=so.name, - payment_gateway_account="_Test Gateway - USD", # email channel + payment_gateway_account="_Test Gateway - USD - _TC", # email channel make_sales_invoice=True, mute_email=True, submit_doc=True, @@ -232,7 +240,7 @@ class TestPaymentRequest(IntegrationTestCase): party="_Test Supplier USD", recipient_id="user@example.com", mute_email=1, - payment_gateway_account="_Test Gateway - USD", + payment_gateway_account="_Test Gateway - USD - _TC", submit_doc=1, return_doc=1, ) @@ -257,7 +265,7 @@ class TestPaymentRequest(IntegrationTestCase): dn=purchase_invoice.name, recipient_id="user@example.com", mute_email=1, - payment_gateway_account="_Test Gateway - USD", + payment_gateway_account="_Test Gateway - USD - _TC", return_doc=1, ) @@ -276,7 +284,7 @@ class TestPaymentRequest(IntegrationTestCase): dn=purchase_invoice.name, recipient_id="user@example.com", mute_email=1, - payment_gateway_account="_Test Gateway - USD", + payment_gateway_account="_Test Gateway - USD - _TC", return_doc=1, ) @@ -300,7 +308,7 @@ class TestPaymentRequest(IntegrationTestCase): dn=so_inr.name, recipient_id="saurabh@erpnext.com", mute_email=1, - payment_gateway_account="_Test Gateway - INR", + payment_gateway_account="_Test Gateway - INR - _TC", submit_doc=1, return_doc=1, ) @@ -322,7 +330,7 @@ class TestPaymentRequest(IntegrationTestCase): dn=si_usd.name, recipient_id="saurabh@erpnext.com", mute_email=1, - payment_gateway_account="_Test Gateway - USD", + payment_gateway_account="_Test Gateway - USD - _TC", submit_doc=1, return_doc=1, ) @@ -366,7 +374,7 @@ class TestPaymentRequest(IntegrationTestCase): dn=si_usd.name, recipient_id="saurabh@erpnext.com", mute_email=1, - payment_gateway_account="_Test Gateway - USD", + payment_gateway_account="_Test Gateway - USD - _TC", submit_doc=1, return_doc=1, ) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index b29b7495391..e1366c1c365 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1361,6 +1361,7 @@ def create_payment_gateway_account(gateway, payment_channel="Email", company=Non "payment_account": bank_account.name, "currency": bank_account.account_currency, "payment_channel": payment_channel, + "company": company, } ).insert(ignore_permissions=True, ignore_if_duplicate=True) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 532c5f1b2a4..f8e82f01085 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -430,3 +430,4 @@ erpnext.patches.v15_0.rename_price_list_to_buying_price_list erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting #2025-07-31 erpnext.patches.v15_0.patch_missing_buying_price_list_in_material_request erpnext.patches.v15_0.remove_sales_partner_from_consolidated_sales_invoice +erpnext.patches.v15_0.add_company_payment_gateway_account diff --git a/erpnext/patches/v15_0/add_company_payment_gateway_account.py b/erpnext/patches/v15_0/add_company_payment_gateway_account.py new file mode 100644 index 00000000000..0c2f0c6f2d3 --- /dev/null +++ b/erpnext/patches/v15_0/add_company_payment_gateway_account.py @@ -0,0 +1,7 @@ +import frappe + + +def execute(): + for gateway_account in frappe.get_list("Payment Gateway Account", fields=["name", "payment_account"]): + company = frappe.db.get_value("Account", gateway_account.payment_account, "company") + frappe.db.set_value("Payment Gateway Account", gateway_account.name, "company", company)