Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion webshop/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
webshop.patches.clear_cache_for_item_group_route
webshop.patches.split_payment_gateway_account_setting
22 changes: 22 additions & 0 deletions webshop/patches/split_payment_gateway_account_setting.py
Original file line number Diff line number Diff line change
@@ -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,
)
11 changes: 1 addition & 10 deletions webshop/templates/pages/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ frappe.ready(() => {

if (!loyalty_points) return;

const callback = async (r) => {
const callback = (r) => {
if (!r) return;

var message = "";
Expand All @@ -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("&");
Expand Down
11 changes: 11 additions & 0 deletions webshop/webshop/doctype/webshop_settings/test_webshop_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
9 changes: 7 additions & 2 deletions webshop/webshop/doctype/webshop_settings/webshop_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 14 additions & 5 deletions webshop/webshop/doctype/webshop_settings/webshop_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions webshop/webshop/shopping_cart/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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)

Expand Down
Loading