Skip to content

Commit

Permalink
fix: MR Default Supplier search query
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Mar 5, 2024
1 parent 6379238 commit 2877a91
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 @@ -595,17 +595,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 2877a91

Please sign in to comment.