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,7 +370,9 @@ 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:
frappe.throw(_("{0} is not the default supplier for any items.".format(supplier)))
material_requests = frappe.db.sql_list("""select distinct mr.name material_requests = frappe.db.sql_list("""select distinct mr.name
from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
where mr.name = mr_item.parent where mr.name = mr_item.parent
@ -381,8 +383,7 @@ def get_material_requests_based_on_supplier(supplier):
and mr.status != 'Stopped' and mr.status != 'Stopped'
order by mr_item.item_code ASC""" % ', '.join(['%s']*len(supplier_items)), order by mr_item.item_code ASC""" % ', '.join(['%s']*len(supplier_items)),
tuple(supplier_items)) tuple(supplier_items))
else:
material_requests = []
return material_requests, supplier_items return material_requests, supplier_items
@frappe.whitelist() @frappe.whitelist()