refactor: added throw if supplier is not default for any item

This commit is contained in:
Shivam Mishra 2019-07-05 13:06:53 +05:30
parent 7fd503b5ba
commit 7a7c66e95e

View File

@ -370,19 +370,20 @@ def make_purchase_order_based_on_supplier(source_name, target_doc=None):
def get_material_requests_based_on_supplier(supplier): def get_material_requests_based_on_supplier(supplier):
supplier_items = [d.parent for d in frappe.db.get_all("Item Default", supplier_items = [d.parent for d in frappe.db.get_all("Item Default",
{"default_supplier": supplier}, 'parent')] {"default_supplier": supplier}, 'parent')]
if supplier_items: if not supplier_items:
material_requests = frappe.db.sql_list("""select distinct mr.name frappe.throw(_("{0} is not the default supplier for any items.".format(supplier)))
from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
where mr.name = mr_item.parent material_requests = frappe.db.sql_list("""select distinct mr.name
and mr_item.item_code in (%s) from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
and mr.material_request_type = 'Purchase' where mr.name = mr_item.parent
and mr.per_ordered < 99.99 and mr_item.item_code in (%s)
and mr.docstatus = 1 and mr.material_request_type = 'Purchase'
and mr.status != 'Stopped' and mr.per_ordered < 99.99
order by mr_item.item_code ASC""" % ', '.join(['%s']*len(supplier_items)), and mr.docstatus = 1
tuple(supplier_items)) and mr.status != 'Stopped'
else: order by mr_item.item_code ASC""" % ', '.join(['%s']*len(supplier_items)),
material_requests = [] tuple(supplier_items))
return material_requests, supplier_items return material_requests, supplier_items
@frappe.whitelist() @frappe.whitelist()