mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 13:39:18 +00:00
Merge pull request #48939 from frappe/mergify/bp/version-15-hotfix/pr-48575
feat(payment gateway account): add company (backport #48575)
This commit is contained in:
@@ -8,4 +8,14 @@ frappe.ui.form.on("Payment Gateway Account", {
|
|||||||
frm.set_df_property("payment_gateway", "read_only", 1);
|
frm.set_df_property("payment_gateway", "read_only", 1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setup(frm) {
|
||||||
|
frm.set_query("payment_account", function () {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
company: frm.doc.company,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"payment_gateway",
|
"payment_gateway",
|
||||||
"payment_channel",
|
"payment_channel",
|
||||||
|
"company",
|
||||||
"is_default",
|
"is_default",
|
||||||
"column_break_4",
|
"column_break_4",
|
||||||
"payment_account",
|
"payment_account",
|
||||||
@@ -70,11 +71,21 @@
|
|||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Payment Channel",
|
"label": "Payment Channel",
|
||||||
"options": "\nEmail\nPhone"
|
"options": "\nEmail\nPhone"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-09-20 13:30:27.722852",
|
"modified": "2025-07-14 16:49:55.210352",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Gateway Account",
|
"name": "Payment Gateway Account",
|
||||||
@@ -95,4 +106,4 @@
|
|||||||
],
|
],
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC"
|
"sort_order": "DESC"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class PaymentGatewayAccount(Document):
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from frappe.types import DF
|
from frappe.types import DF
|
||||||
|
|
||||||
|
company: DF.Link
|
||||||
currency: DF.ReadOnly | None
|
currency: DF.ReadOnly | None
|
||||||
is_default: DF.Check
|
is_default: DF.Check
|
||||||
message: DF.SmallText | None
|
message: DF.SmallText | None
|
||||||
@@ -24,7 +25,8 @@ class PaymentGatewayAccount(Document):
|
|||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
def autoname(self):
|
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):
|
def validate(self):
|
||||||
self.currency = frappe.get_cached_value("Account", self.payment_account, "account_currency")
|
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):
|
def update_default_payment_gateway(self):
|
||||||
if self.is_default:
|
if self.is_default:
|
||||||
frappe.db.sql(
|
frappe.db.set_value(
|
||||||
"""update `tabPayment Gateway Account` set is_default = 0
|
"Payment Gateway Account",
|
||||||
where is_default = 1 """
|
{"is_default": 1, "name": ["!=", self.name], "company": self.company},
|
||||||
|
"is_default",
|
||||||
|
0,
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_as_default_if_not_set(self):
|
def set_as_default_if_not_set(self):
|
||||||
if not frappe.db.get_value(
|
if not frappe.db.exists(
|
||||||
"Payment Gateway Account", {"is_default": 1, "name": ("!=", self.name)}, "name"
|
"Payment Gateway Account", {"is_default": 1, "name": ("!=", self.name), "company": self.company}
|
||||||
):
|
):
|
||||||
self.is_default = 1
|
self.is_default = 1
|
||||||
|
|||||||
@@ -9,6 +9,14 @@ frappe.ui.form.on("Payment Request", {
|
|||||||
query: "erpnext.setup.doctype.party_type.party_type.get_party_type",
|
query: "erpnext.setup.doctype.party_type.party_type.get_party_type",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frm.set_query("payment_gateway_account", function () {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
company: frm.doc.company,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -539,7 +539,9 @@ def make_payment_request(**args):
|
|||||||
if args.dt not in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST:
|
if args.dt not in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST:
|
||||||
frappe.throw(_("Payment Requests cannot be created against: {0}").format(frappe.bold(args.dt)))
|
frappe.throw(_("Payment Requests cannot be created against: {0}").format(frappe.bold(args.dt)))
|
||||||
|
|
||||||
ref_doc = frappe.get_doc(args.dt, args.dn)
|
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()
|
gateway_account = get_gateway_details(args) or frappe._dict()
|
||||||
|
|
||||||
grand_total = get_amount(ref_doc, gateway_account.get("payment_account"))
|
grand_total = get_amount(ref_doc, gateway_account.get("payment_account"))
|
||||||
@@ -782,7 +784,7 @@ def get_gateway_details(args): # nosemgrep
|
|||||||
"""
|
"""
|
||||||
Return gateway and payment account of default payment gateway
|
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})
|
||||||
if gateway_account:
|
if gateway_account:
|
||||||
return get_payment_gateway_account(gateway_account)
|
return get_payment_gateway_account(gateway_account)
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ payment_method = [
|
|||||||
"payment_gateway": "_Test Gateway",
|
"payment_gateway": "_Test Gateway",
|
||||||
"payment_account": "_Test Bank - _TC",
|
"payment_account": "_Test Bank - _TC",
|
||||||
"currency": "INR",
|
"currency": "INR",
|
||||||
|
"company": "_Test Company",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Payment Gateway Account",
|
"doctype": "Payment Gateway Account",
|
||||||
"payment_gateway": "_Test Gateway",
|
"payment_gateway": "_Test Gateway",
|
||||||
"payment_account": "_Test Bank USD - _TC",
|
"payment_account": "_Test Bank USD - _TC",
|
||||||
"currency": "USD",
|
"currency": "USD",
|
||||||
|
"company": "_Test Company",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -46,7 +48,11 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
for method in payment_method:
|
for method in payment_method:
|
||||||
if not frappe.db.get_value(
|
if not frappe.db.get_value(
|
||||||
"Payment Gateway Account",
|
"Payment Gateway Account",
|
||||||
{"payment_gateway": method["payment_gateway"], "currency": method["currency"]},
|
{
|
||||||
|
"payment_gateway": method["payment_gateway"],
|
||||||
|
"currency": method["currency"],
|
||||||
|
"company": method["company"],
|
||||||
|
},
|
||||||
"name",
|
"name",
|
||||||
):
|
):
|
||||||
frappe.get_doc(method).insert(ignore_permissions=True)
|
frappe.get_doc(method).insert(ignore_permissions=True)
|
||||||
@@ -60,7 +66,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
dt="Sales Order",
|
dt="Sales Order",
|
||||||
dn=so_inr.name,
|
dn=so_inr.name,
|
||||||
recipient_id="saurabh@erpnext.com",
|
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")
|
self.assertEqual(pr.reference_doctype, "Sales Order")
|
||||||
@@ -74,7 +80,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
dt="Sales Invoice",
|
dt="Sales Invoice",
|
||||||
dn=si_usd.name,
|
dn=si_usd.name,
|
||||||
recipient_id="saurabh@erpnext.com",
|
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")
|
self.assertEqual(pr.reference_doctype, "Sales Invoice")
|
||||||
@@ -95,7 +101,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
party="_Test Supplier USD",
|
party="_Test Supplier USD",
|
||||||
recipient_id="user@example.com",
|
recipient_id="user@example.com",
|
||||||
mute_email=1,
|
mute_email=1,
|
||||||
payment_gateway_account="_Test Gateway - USD",
|
payment_gateway_account="_Test Gateway - USD - _TC",
|
||||||
submit_doc=1,
|
submit_doc=1,
|
||||||
return_doc=1,
|
return_doc=1,
|
||||||
)
|
)
|
||||||
@@ -119,7 +125,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
dn=purchase_invoice.name,
|
dn=purchase_invoice.name,
|
||||||
recipient_id="user@example.com",
|
recipient_id="user@example.com",
|
||||||
mute_email=1,
|
mute_email=1,
|
||||||
payment_gateway_account="_Test Gateway - USD",
|
payment_gateway_account="_Test Gateway - USD - _TC",
|
||||||
return_doc=1,
|
return_doc=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -138,7 +144,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
dn=purchase_invoice.name,
|
dn=purchase_invoice.name,
|
||||||
recipient_id="user@example.com",
|
recipient_id="user@example.com",
|
||||||
mute_email=1,
|
mute_email=1,
|
||||||
payment_gateway_account="_Test Gateway - USD",
|
payment_gateway_account="_Test Gateway - USD - _TC",
|
||||||
return_doc=1,
|
return_doc=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -162,7 +168,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
dn=so_inr.name,
|
dn=so_inr.name,
|
||||||
recipient_id="saurabh@erpnext.com",
|
recipient_id="saurabh@erpnext.com",
|
||||||
mute_email=1,
|
mute_email=1,
|
||||||
payment_gateway_account="_Test Gateway - INR",
|
payment_gateway_account="_Test Gateway - INR - _TC",
|
||||||
submit_doc=1,
|
submit_doc=1,
|
||||||
return_doc=1,
|
return_doc=1,
|
||||||
)
|
)
|
||||||
@@ -184,7 +190,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
dn=si_usd.name,
|
dn=si_usd.name,
|
||||||
recipient_id="saurabh@erpnext.com",
|
recipient_id="saurabh@erpnext.com",
|
||||||
mute_email=1,
|
mute_email=1,
|
||||||
payment_gateway_account="_Test Gateway - USD",
|
payment_gateway_account="_Test Gateway - USD - _TC",
|
||||||
submit_doc=1,
|
submit_doc=1,
|
||||||
return_doc=1,
|
return_doc=1,
|
||||||
)
|
)
|
||||||
@@ -228,7 +234,7 @@ class TestPaymentRequest(FrappeTestCase):
|
|||||||
dn=si_usd.name,
|
dn=si_usd.name,
|
||||||
recipient_id="saurabh@erpnext.com",
|
recipient_id="saurabh@erpnext.com",
|
||||||
mute_email=1,
|
mute_email=1,
|
||||||
payment_gateway_account="_Test Gateway - USD",
|
payment_gateway_account="_Test Gateway - USD - _TC",
|
||||||
submit_doc=1,
|
submit_doc=1,
|
||||||
return_doc=1,
|
return_doc=1,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1339,6 +1339,7 @@ def create_payment_gateway_account(gateway, payment_channel="Email"):
|
|||||||
"payment_account": bank_account.name,
|
"payment_account": bank_account.name,
|
||||||
"currency": bank_account.account_currency,
|
"currency": bank_account.account_currency,
|
||||||
"payment_channel": payment_channel,
|
"payment_channel": payment_channel,
|
||||||
|
"company": company,
|
||||||
}
|
}
|
||||||
).insert(ignore_permissions=True, ignore_if_duplicate=True)
|
).insert(ignore_permissions=True, ignore_if_duplicate=True)
|
||||||
|
|
||||||
|
|||||||
@@ -418,3 +418,4 @@ 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.remove_sales_partner_from_consolidated_sales_invoice
|
||||||
erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting #2025-07-31
|
erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting #2025-07-31
|
||||||
execute:frappe.db.set_single_value("Accounts Settings", "fetch_valuation_rate_for_internal_transaction", 1)
|
execute:frappe.db.set_single_value("Accounts Settings", "fetch_valuation_rate_for_internal_transaction", 1)
|
||||||
|
erpnext.patches.v15_0.add_company_payment_gateway_account
|
||||||
|
|||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user