Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: black & prettier #1

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exclude: 'node_modules|.git'
default_stages: [commit]
default_stages: [pre-commit]
fail_fast: false


Expand Down
2 changes: 1 addition & 1 deletion payments/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# page_js = {"page" : "public/js/file.js"}

# include js in doctype views
doctype_js = {"Web Form" : "public/js/web_form.js"}
doctype_js = {"Web Form": "public/js/web_form.js"}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
# doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}
Expand Down
2 changes: 1 addition & 1 deletion payments/overrides/payment_webform.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_payment_gateway_url(self, doc):

if amount is None or Decimal(amount) <= 0:
return frappe.utils.get_url(self.success_url or self.route)

# Set Payer Name
payer_name = frappe.utils.get_fullname(frappe.session.user)
if self.payer_name_based_on_field:
Expand Down
148 changes: 81 additions & 67 deletions payments/public/js/web_form.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,90 @@
frappe.ui.form.on("Web Form", {
set_fields(frm) {
let doc = frm.doc;
set_fields(frm) {
let doc = frm.doc;

let update_options = (options) => {
[frm.fields_dict.web_form_fields.grid, frm.fields_dict.list_columns.grid].forEach(
(obj) => {
obj.update_docfield_property("fieldname", "options", options);
}
);
};
let update_options = (options) => {
[
frm.fields_dict.web_form_fields.grid,
frm.fields_dict.list_columns.grid,
].forEach((obj) => {
obj.update_docfield_property("fieldname", "options", options);
});
};

if (!doc.doc_type) {
update_options([]);
frm.set_df_property("amount_field", "options", []);
frm.set_df_property("payer_name_field", "options", []);
frm.set_df_property("payer_email_field", "options", []);
return;
}
if (!doc.doc_type) {
update_options([]);
frm.set_df_property("amount_field", "options", []);
frm.set_df_property("payer_name_field", "options", []);
frm.set_df_property("payer_email_field", "options", []);
return;
}

update_options([`Fetching fields from ${doc.doc_type}...`]);
update_options([`Fetching fields from ${doc.doc_type}...`]);

get_fields_for_doctype(doc.doc_type).then((fields) => {
let as_select_option = (df) => ({
label: df.label,
value: df.fieldname,
});
update_options(fields.map(as_select_option));
new Promise((resolve) =>
frappe.model.with_doctype(doc.doc_type, resolve)
).then(() => {
const fields = frappe.meta.get_docfields(doc.doc_type).filter((df) => {
return (
(frappe.model.is_value_type(df.fieldtype) &&
!["lft", "rgt"].includes(df.fieldname)) ||
["Table", "Table Multiselect"].includes(df.fieldtype) ||
frappe.model.layout_fields.includes(df.fieldtype)
);
});

// Amount Field Options
let currency_fields = fields
.filter((df) => ["Currency", "Float"].includes(df.fieldtype))
.map(as_select_option);
if (!currency_fields.length) {
currency_fields = [
{
label: `No currency fields in ${doc.doc_type}`,
value: "",
disabled: true,
},
];
}
frm.set_df_property("amount_field", "options", currency_fields);
let as_select_option = (df) => ({
label: df.label,
value: df.fieldname,
});

// Payer Name Field Options
let payer_name_fields = fields
.filter((df) => ["Data", "Link"].includes(df.fieldtype))
.map(as_select_option);
if (!payer_name_fields.length) {
payer_name_fields = [
{
label: `No data or link fields in ${doc.doc_type}`,
value: "",
disabled: true,
},
];
}
frm.set_df_property("payer_name_field", "options", payer_name_fields);
// Update main field options
update_options(fields.map(as_select_option));

// Payer Email Field Options
let payer_email_fields = fields
.filter((df) => ["Email"].includes(df.options))
.map(as_select_option);
if (!payer_email_fields.length) {
payer_email_fields = [
{
label: `No email fields in ${doc.doc_type}`,
value: "",
disabled: true,
},
];
}
frm.set_df_property("payer_email_field", "options", payer_email_fields);
});
}
// Amount Field Options
let currency_fields = fields
.filter((df) => ["Currency", "Float"].includes(df.fieldtype))
.map(as_select_option);
if (!currency_fields.length) {
currency_fields = [
{
label: `No currency fields in ${doc.doc_type}`,
value: "",
disabled: true,
},
];
}
frm.set_df_property("amount_field", "options", currency_fields);

// Payer Name Field Options
let payer_name_fields = fields
.filter((df) => ["Data", "Link"].includes(df.fieldtype))
.map(as_select_option);
if (!payer_name_fields.length) {
payer_name_fields = [
{
label: `No data or link fields in ${doc.doc_type}`,
value: "",
disabled: true,
},
];
}
frm.set_df_property("payer_name_field", "options", payer_name_fields);

// Payer Email Field Options
let payer_email_fields = fields
.filter((df) => ["Email"].includes(df.options))
.map(as_select_option);
if (!payer_email_fields.length) {
payer_email_fields = [
{
label: `No email fields in ${doc.doc_type}`,
value: "",
disabled: true,
},
];
}
frm.set_df_property("payer_email_field", "options", payer_email_fields);
});
},
});
2 changes: 1 addition & 1 deletion payments/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def delete_custom_fields():
"payment_gateway",
"payments_cb",
"payments_sb",
"payments_tab"
"payments_tab",
)

for fieldname in fieldnames:
Expand Down
Loading