Skip to content

Commit

Permalink
fix: MR Default Supplier search query (backport #40273) (#40350)
Browse files Browse the repository at this point in the history
fix: MR Default Supplier search query

(cherry picked from commit c0a1f29)

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
  • Loading branch information
mergify[bot] and s-aga-r authored Mar 11, 2024
1 parent 6b88cca commit c6fe409
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions erpnext/stock/doctype/material_request/material_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,28 @@ def get_default_supplier_query(doctype, txt, searchfield, start, page_len, filte
for d in doc.items:
item_list.append(d.item_code)

return frappe.db.sql(
"""select default_supplier
from `tabItem Default`
where parent in ({0}) and
default_supplier IS NOT NULL
""".format(
", ".join(["%s"] * len(item_list))
),
tuple(item_list),
supplier = frappe.qb.DocType("Supplier")
item_default = frappe.qb.DocType("Item Default")
query = (
frappe.qb.from_(supplier)
.left_join(item_default)
.on(supplier.name == item_default.default_supplier)
.select(item_default.default_supplier)
.where(
(item_default.parent.isin(item_list))
& (item_default.default_supplier.notnull())
& (supplier[searchfield].like(f"%{txt}%"))
)
.offset(start)
.limit(page_len)
)

meta = frappe.get_meta("Supplier")
if meta.show_title_field_in_link and meta.title_field:
query = query.select(supplier[meta.title_field])

return query.run(as_dict=False)


@frappe.whitelist()
def make_supplier_quotation(source_name, target_doc=None):
Expand Down

0 comments on commit c6fe409

Please sign in to comment.