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

fix: MR Default Supplier search query #40273

Merged
merged 1 commit into from
Mar 10, 2024
Merged
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
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
Loading