From cfb899451f5a074a0ba9f8801abf5ba7e56e012f Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 5 Aug 2019 10:14:05 +0530 Subject: [PATCH] fix: Make conversion rate optional for non itemized items (#18541) --- erpnext/buying/utils.py | 14 ++++++++------ erpnext/controllers/buying_controller.py | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/erpnext/buying/utils.py b/erpnext/buying/utils.py index 981ee5dcef..8c0a1e56f7 100644 --- a/erpnext/buying/utils.py +++ b/erpnext/buying/utils.py @@ -30,7 +30,9 @@ def update_last_purchase_rate(doc, is_submit): # for it to be considered for latest purchase rate if flt(d.conversion_factor): last_purchase_rate = flt(d.base_rate) / flt(d.conversion_factor) - else: + # Check if item code is present + # Conversion factor should not be mandatory for non itemized items + elif d.item_code: frappe.throw(_("UOM Conversion factor is required in row {0}").format(d.idx)) # update last purchsae rate @@ -84,13 +86,13 @@ def get_linked_material_requests(items): items = json.loads(items) mr_list = [] for item in items: - material_request = frappe.db.sql("""SELECT distinct mr.name AS mr_name, - (mr_item.qty - mr_item.ordered_qty) AS qty, + material_request = frappe.db.sql("""SELECT distinct mr.name AS mr_name, + (mr_item.qty - mr_item.ordered_qty) AS qty, mr_item.item_code AS item_code, - mr_item.name AS mr_item + mr_item.name AS mr_item FROM `tabMaterial Request` mr, `tabMaterial Request Item` mr_item WHERE mr.name = mr_item.parent - AND mr_item.item_code = %(item)s + AND mr_item.item_code = %(item)s AND mr.material_request_type = 'Purchase' AND mr.per_ordered < 99.99 AND mr.docstatus = 1 @@ -98,6 +100,6 @@ def get_linked_material_requests(items): ORDER BY mr_item.item_code ASC""",{"item": item}, as_dict=1) if material_request: mr_list.append(material_request) - + return mr_list diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 0b4d38ce5c..588f74dbc9 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -395,7 +395,9 @@ class BuyingController(StockController): def set_qty_as_per_stock_uom(self): for d in self.get("items"): if d.meta.get_field("stock_qty"): - if not d.conversion_factor: + # Check if item code is present + # Conversion factor should not be mandatory for non itemized items + if not d.conversion_factor and d.item_code: frappe.throw(_("Row {0}: Conversion Factor is mandatory").format(d.idx)) d.stock_qty = flt(d.qty) * flt(d.conversion_factor)