fix: Remove custom queries for customer
This commit is contained in:
@@ -395,10 +395,6 @@ frappe.ui.form.on("Payment Entry", {
|
|||||||
return {
|
return {
|
||||||
query: "erpnext.controllers.queries.employee_query",
|
query: "erpnext.controllers.queries.employee_query",
|
||||||
};
|
};
|
||||||
} else if (frm.doc.party_type == "Customer") {
|
|
||||||
return {
|
|
||||||
query: "erpnext.controllers.queries.customer_query",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -54,34 +54,9 @@ class BuyingSettings(Document):
|
|||||||
hide_name_field=False,
|
hide_name_field=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
set_search_fields("Supplier", "supplier_name", self.get("supp_master_name") == "Naming Series")
|
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
self.check_maintain_same_rate()
|
self.check_maintain_same_rate()
|
||||||
|
|
||||||
def check_maintain_same_rate(self):
|
def check_maintain_same_rate(self):
|
||||||
if self.maintain_same_rate:
|
if self.maintain_same_rate:
|
||||||
self.set_landed_cost_based_on_purchase_invoice_rate = 0
|
self.set_landed_cost_based_on_purchase_invoice_rate = 0
|
||||||
|
|
||||||
|
|
||||||
def set_search_fields(doctype, fieldname, naming_series):
|
|
||||||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
|
||||||
|
|
||||||
searchfields = frappe.get_meta(doctype).get_search_fields()
|
|
||||||
|
|
||||||
if naming_series:
|
|
||||||
if fieldname not in searchfields:
|
|
||||||
searchfields.append(fieldname)
|
|
||||||
else:
|
|
||||||
if fieldname in searchfields:
|
|
||||||
searchfields.remove(fieldname)
|
|
||||||
|
|
||||||
make_property_setter(
|
|
||||||
doctype,
|
|
||||||
"",
|
|
||||||
"search_fields",
|
|
||||||
", ".join(searchfields),
|
|
||||||
"Data",
|
|
||||||
for_doctype=True,
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -85,46 +85,6 @@ def lead_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
||||||
)
|
)
|
||||||
|
|
||||||
# searches for customer
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
|
||||||
def customer_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
|
|
||||||
doctype = "Customer"
|
|
||||||
conditions = []
|
|
||||||
cust_master_name = frappe.defaults.get_user_default("cust_master_name")
|
|
||||||
|
|
||||||
fields = ["name"]
|
|
||||||
if cust_master_name != "Customer Name":
|
|
||||||
fields.append("customer_name")
|
|
||||||
|
|
||||||
fields = get_fields(doctype, fields)
|
|
||||||
searchfields = frappe.get_meta(doctype).get_search_fields()
|
|
||||||
searchfields = " or ".join(field + " like %(txt)s" for field in searchfields)
|
|
||||||
|
|
||||||
return frappe.db.sql(
|
|
||||||
"""select {fields} from `tabCustomer`
|
|
||||||
where docstatus < 2
|
|
||||||
and ({scond}) and disabled=0
|
|
||||||
{fcond} {mcond}
|
|
||||||
order by
|
|
||||||
(case when locate(%(_txt)s, name) > 0 then locate(%(_txt)s, name) else 99999 end),
|
|
||||||
(case when locate(%(_txt)s, customer_name) > 0 then locate(%(_txt)s, customer_name) else 99999 end),
|
|
||||||
idx desc,
|
|
||||||
name, customer_name
|
|
||||||
limit %(page_len)s offset %(start)s""".format(
|
|
||||||
**{
|
|
||||||
"fields": ", ".join(fields),
|
|
||||||
"scond": searchfields,
|
|
||||||
"mcond": get_match_cond(doctype),
|
|
||||||
"fcond": get_filters_cond(doctype, filters, conditions).replace("%", "%%"),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
|
||||||
as_dict=as_dict,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
|
|||||||
@@ -31,12 +31,6 @@ class TestQueries(unittest.TestCase):
|
|||||||
self.assertGreaterEqual(len(query(txt="_Test Lead")), 4)
|
self.assertGreaterEqual(len(query(txt="_Test Lead")), 4)
|
||||||
self.assertEqual(len(query(txt="_Test Lead 4")), 1)
|
self.assertEqual(len(query(txt="_Test Lead 4")), 1)
|
||||||
|
|
||||||
def test_customer_query(self):
|
|
||||||
query = add_default_params(queries.customer_query, "Customer")
|
|
||||||
|
|
||||||
self.assertGreaterEqual(len(query(txt="_Test Customer")), 7)
|
|
||||||
self.assertGreaterEqual(len(query(txt="_Test Customer USD")), 1)
|
|
||||||
|
|
||||||
def test_item_query(self):
|
def test_item_query(self):
|
||||||
query = add_default_params(queries.item_query, "Item")
|
query = add_default_params(queries.item_query, "Item")
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
onload() {
|
onload() {
|
||||||
this.frm.set_query("customer", function (doc, cdt, cdn) {
|
|
||||||
return { query: "erpnext.controllers.queries.customer_query" };
|
|
||||||
});
|
|
||||||
|
|
||||||
this.frm.set_query("lead_owner", function (doc, cdt, cdn) {
|
this.frm.set_query("lead_owner", function (doc, cdt, cdn) {
|
||||||
return { query: "frappe.core.doctype.user.user.user_query" };
|
return { query: "frappe.core.doctype.user.user.user_query" };
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -282,9 +282,6 @@ has_website_permission = {
|
|||||||
|
|
||||||
before_tests = "erpnext.setup.utils.before_tests"
|
before_tests = "erpnext.setup.utils.before_tests"
|
||||||
|
|
||||||
standard_queries = {
|
|
||||||
"Customer": "erpnext.controllers.queries.customer_query",
|
|
||||||
}
|
|
||||||
|
|
||||||
period_closing_doctypes = [
|
period_closing_doctypes = [
|
||||||
"Sales Invoice",
|
"Sales Invoice",
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ frappe.ui.form.on("Project", {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
frm.set_query("customer", "erpnext.controllers.queries.customer_query");
|
|
||||||
|
|
||||||
frm.set_query("user", "users", function () {
|
frm.set_query("user", "users", function () {
|
||||||
return {
|
return {
|
||||||
query: "erpnext.projects.doctype.project.project.get_users_for_project",
|
query: "erpnext.projects.doctype.project.project.get_users_for_project",
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ $.extend(erpnext.queries, {
|
|||||||
return { query: "erpnext.controllers.queries.lead_query" };
|
return { query: "erpnext.controllers.queries.lead_query" };
|
||||||
},
|
},
|
||||||
|
|
||||||
customer: function () {
|
|
||||||
return { query: "erpnext.controllers.queries.customer_query" };
|
|
||||||
},
|
|
||||||
|
|
||||||
item: function (filters) {
|
item: function (filters) {
|
||||||
var args = { query: "erpnext.controllers.queries.item_query" };
|
var args = { query: "erpnext.controllers.queries.item_query" };
|
||||||
if (filters) args["filters"] = filters;
|
if (filters) args["filters"] = filters;
|
||||||
|
|||||||
@@ -583,7 +583,7 @@
|
|||||||
"link_fieldname": "party"
|
"link_fieldname": "party"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2023-12-28 13:15:36.298369",
|
"modified": "2024-03-16 19:41:47.971815",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Customer",
|
"name": "Customer",
|
||||||
@@ -661,7 +661,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
"search_fields": "customer_name,customer_group,territory, mobile_no,primary_address",
|
"search_fields": "customer_group,territory, mobile_no,primary_address",
|
||||||
"show_name_in_global_search": 1,
|
"show_name_in_global_search": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
|
|||||||
@@ -370,37 +370,6 @@ class TestCustomer(FrappeTestCase):
|
|||||||
due_date = get_due_date("2017-01-22", "Customer", "_Test Customer")
|
due_date = get_due_date("2017-01-22", "Customer", "_Test Customer")
|
||||||
self.assertEqual(due_date, "2017-01-22")
|
self.assertEqual(due_date, "2017-01-22")
|
||||||
|
|
||||||
def test_serach_fields_for_customer(self):
|
|
||||||
from erpnext.controllers.queries import customer_query
|
|
||||||
|
|
||||||
frappe.db.set_single_value("Selling Settings", "cust_master_name", "Naming Series")
|
|
||||||
|
|
||||||
make_property_setter(
|
|
||||||
"Customer", None, "search_fields", "customer_group", "Data", for_doctype="Doctype"
|
|
||||||
)
|
|
||||||
|
|
||||||
data = customer_query(
|
|
||||||
"Customer", "_Test Customer", "", 0, 20, filters={"name": "_Test Customer"}, as_dict=True
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(data[0].name, "_Test Customer")
|
|
||||||
self.assertEqual(data[0].customer_group, "_Test Customer Group")
|
|
||||||
self.assertTrue("territory" not in data[0])
|
|
||||||
|
|
||||||
make_property_setter(
|
|
||||||
"Customer", None, "search_fields", "customer_group, territory", "Data", for_doctype="Doctype"
|
|
||||||
)
|
|
||||||
data = customer_query(
|
|
||||||
"Customer", "_Test Customer", "", 0, 20, filters={"name": "_Test Customer"}, as_dict=True
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(data[0].name, "_Test Customer")
|
|
||||||
self.assertEqual(data[0].customer_group, "_Test Customer Group")
|
|
||||||
self.assertEqual(data[0].territory, "_Test Territory")
|
|
||||||
self.assertTrue("territory" in data[0])
|
|
||||||
|
|
||||||
frappe.db.set_single_value("Selling Settings", "cust_master_name", "Customer Name")
|
|
||||||
|
|
||||||
def test_parse_full_name(self):
|
def test_parse_full_name(self):
|
||||||
first, middle, last = parse_full_name("John")
|
first, middle, last = parse_full_name("John")
|
||||||
self.assertEqual(first, "John")
|
self.assertEqual(first, "John")
|
||||||
|
|||||||
@@ -295,10 +295,10 @@ erpnext.PointOfSale.ItemCart = class {
|
|||||||
<div class="customer-field"></div>
|
<div class="customer-field"></div>
|
||||||
`);
|
`);
|
||||||
const me = this;
|
const me = this;
|
||||||
const query = { query: "erpnext.controllers.queries.customer_query" };
|
|
||||||
const allowed_customer_group = this.allowed_customer_groups || [];
|
const allowed_customer_group = this.allowed_customer_groups || [];
|
||||||
|
let filters = {};
|
||||||
if (allowed_customer_group.length) {
|
if (allowed_customer_group.length) {
|
||||||
query.filters = {
|
filters = {
|
||||||
customer_group: ["in", allowed_customer_group],
|
customer_group: ["in", allowed_customer_group],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,11 @@ erpnext.PointOfSale.ItemCart = class {
|
|||||||
fieldtype: "Link",
|
fieldtype: "Link",
|
||||||
options: "Customer",
|
options: "Customer",
|
||||||
placeholder: __("Search by customer name, phone, email."),
|
placeholder: __("Search by customer name, phone, email."),
|
||||||
get_query: () => query,
|
get_query: function () {
|
||||||
|
return {
|
||||||
|
filters: filters,
|
||||||
|
};
|
||||||
|
},
|
||||||
onchange: function () {
|
onchange: function () {
|
||||||
if (this.value) {
|
if (this.value) {
|
||||||
const frm = me.events.get_frm();
|
const frm = me.events.get_frm();
|
||||||
|
|||||||
@@ -406,10 +406,6 @@ $.extend(erpnext.item, {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
frm.fields_dict.customer_items.grid.get_field("customer_name").get_query = function (doc, cdt, cdn) {
|
|
||||||
return { query: "erpnext.controllers.queries.customer_query" };
|
|
||||||
};
|
|
||||||
|
|
||||||
frm.fields_dict["item_defaults"].grid.get_field("default_warehouse").get_query = function (
|
frm.fields_dict["item_defaults"].grid.get_field("default_warehouse").get_query = function (
|
||||||
doc,
|
doc,
|
||||||
cdt,
|
cdt,
|
||||||
|
|||||||
Reference in New Issue
Block a user