From 42343bbc2cd300241d95b87f70a116902eb1e4d3 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 5 May 2017 17:23:17 +0530 Subject: [PATCH] Selling price validation against last purchase rate / valuation rate (#8702) --- erpnext/controllers/selling_controller.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 1cd705b8c4..10b3607df9 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -170,7 +170,7 @@ class SellingController(StockController): def validate_selling_price(self): def throw_message(item_name, rate, ref_rate_field): - frappe.throw(_("""Selling price for item {0} is lower than its {1}. Selling price should be atleast {2}""") + frappe.throw(_("""Selling rate for item {0} is lower than its {1}. Selling rate should be atleast {2}""") .format(item_name, ref_rate_field, rate)) if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"): @@ -178,18 +178,19 @@ class SellingController(StockController): for it in self.get("items"): last_purchase_rate, is_stock_item = frappe.db.get_value("Item", it.item_code, ["last_purchase_rate", "is_stock_item"]) - - if flt(it.base_rate) < flt(last_purchase_rate): - throw_message(it.item_name, last_purchase_rate, "last purchase rate") + last_purchase_rate_in_sales_uom = last_purchase_rate / (it.conversion_factor or 1) + if flt(it.base_rate) < flt(last_purchase_rate_in_sales_uom): + throw_message(it.item_name, last_purchase_rate_in_sales_uom, "last purchase rate") last_valuation_rate = frappe.db.sql(""" SELECT valuation_rate FROM `tabStock Ledger Entry` WHERE item_code = %s AND warehouse = %s AND valuation_rate > 0 ORDER BY posting_date DESC, posting_time DESC, name DESC LIMIT 1 """, (it.item_code, it.warehouse)) - - if is_stock_item and flt(it.base_rate) < flt(last_valuation_rate): - throw_message(it.name, last_valuation_rate, "valuation rate") + if last_valuation_rate: + last_valuation_rate_in_sales_uom = last_valuation_rate[0][0] / (it.conversion_factor or 1) + if is_stock_item and flt(it.base_rate) < flt(last_valuation_rate_in_sales_uom): + throw_message(it.name, last_valuation_rate_in_sales_uom, "valuation rate") def get_item_list(self):