Skip to content

Commit

Permalink
fix: Remove custom queries for customer
Browse files Browse the repository at this point in the history
(cherry picked from commit 60ba25c)
  • Loading branch information
deepeshgarg007 authored and mergify[bot] committed Mar 16, 2024
1 parent e3336c6 commit 3133505
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 128 deletions.
4 changes: 0 additions & 4 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,6 @@ frappe.ui.form.on("Payment Entry", {
return {
query: "erpnext.controllers.queries.employee_query",
};
} else if (frm.doc.party_type == "Customer") {
return {
query: "erpnext.controllers.queries.customer_query",
};
}
});

Expand Down
25 changes: 0 additions & 25 deletions erpnext/buying/doctype/buying_settings/buying_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,9 @@ def validate(self):
hide_name_field=False,
)

set_search_fields("Supplier", "supplier_name", self.get("supp_master_name") == "Naming Series")

def before_save(self):
self.check_maintain_same_rate()

def check_maintain_same_rate(self):
if self.maintain_same_rate:
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,
)
40 changes: 0 additions & 40 deletions erpnext/controllers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)

# 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.validate_and_sanitize_search_inputs
Expand Down
6 changes: 0 additions & 6 deletions erpnext/controllers/tests/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ def test_lead_query(self):
self.assertGreaterEqual(len(query(txt="_Test Lead")), 4)
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):
query = add_default_params(queries.item_query, "Item")

Expand Down
4 changes: 0 additions & 4 deletions erpnext/crm/doctype/lead/lead.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ erpnext.LeadController = class LeadController extends frappe.ui.form.Controller
}

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) {
return { query: "frappe.core.doctype.user.user.user_query" };
});
Expand Down
3 changes: 0 additions & 3 deletions erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@

before_tests = "erpnext.setup.utils.before_tests"

standard_queries = {
"Customer": "erpnext.controllers.queries.customer_query",
}

period_closing_doctypes = [
"Sales Invoice",
Expand Down
2 changes: 0 additions & 2 deletions erpnext/projects/doctype/project/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ frappe.ui.form.on("Project", {
};
};

frm.set_query("customer", "erpnext.controllers.queries.customer_query");

frm.set_query("user", "users", function () {
return {
query: "erpnext.projects.doctype.project.project.get_users_for_project",
Expand Down
4 changes: 0 additions & 4 deletions erpnext/public/js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ $.extend(erpnext.queries, {
return { query: "erpnext.controllers.queries.lead_query" };
},

customer: function () {
return { query: "erpnext.controllers.queries.customer_query" };
},

item: function (filters) {
var args = { query: "erpnext.controllers.queries.item_query" };
if (filters) args["filters"] = filters;
Expand Down
4 changes: 2 additions & 2 deletions erpnext/selling/doctype/customer/customer.json
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
"link_fieldname": "party"
}
],
"modified": "2023-12-28 13:15:36.298369",
"modified": "2024-03-16 19:41:47.971815",
"modified_by": "Administrator",
"module": "Selling",
"name": "Customer",
Expand Down Expand Up @@ -661,7 +661,7 @@
}
],
"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,
"sort_field": "modified",
"sort_order": "DESC",
Expand Down
31 changes: 0 additions & 31 deletions erpnext/selling/doctype/customer/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,37 +370,6 @@ def test_customer_payment_terms(self):
due_date = get_due_date("2017-01-22", "Customer", "_Test Customer")
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):
first, middle, last = parse_full_name("John")
self.assertEqual(first, "John")
Expand Down
10 changes: 7 additions & 3 deletions erpnext/selling/page/point_of_sale/pos_item_cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ erpnext.PointOfSale.ItemCart = class {
<div class="customer-field"></div>
`);
const me = this;
const query = { query: "erpnext.controllers.queries.customer_query" };
const allowed_customer_group = this.allowed_customer_groups || [];
let filters = {};
if (allowed_customer_group.length) {
query.filters = {
filters = {
customer_group: ["in", allowed_customer_group],
};
}
Expand All @@ -308,7 +308,11 @@ erpnext.PointOfSale.ItemCart = class {
fieldtype: "Link",
options: "Customer",
placeholder: __("Search by customer name, phone, email."),
get_query: () => query,
get_query: function () {
return {
filters: filters,
};
},
onchange: function () {
if (this.value) {
const frm = me.events.get_frm();
Expand Down
4 changes: 0 additions & 4 deletions erpnext/stock/doctype/item/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
doc,
cdt,
Expand Down

0 comments on commit 3133505

Please sign in to comment.