diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 180ccbb3e2b..647c9faf026 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -230,6 +230,13 @@ class update_entries_after(object): # else it remains the same as that of previous entry self.valuation_rate = new_stock_value / new_stock_qty + if not self.valuation_rate and sle.voucher_detail_no: + allow_zero_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) + if not allow_zero_rate: + self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, + sle.voucher_type, sle.voucher_no, self.allow_zero_rate, + currency=erpnext.get_company_currency(sle.company)) + def get_moving_average_values(self, sle): actual_qty = flt(sle.actual_qty) new_stock_qty = flt(self.qty_after_transaction) + actual_qty diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 01a18b90a43..6f091446d9e 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -126,7 +126,7 @@ def update_bin(args, allow_negative_stock=False, via_landed_cost_voucher=False): def get_incoming_rate(args): """Get Incoming Rate based on valuation method""" from erpnext.stock.stock_ledger import get_previous_sle - + if isinstance(args, basestring): args = json.loads(args) @@ -141,6 +141,8 @@ def get_incoming_rate(args): return 0.0 previous_stock_queue = json.loads(previous_sle.get('stock_queue', '[]') or '[]') in_rate = get_fifo_rate(previous_stock_queue, args.get("qty") or 0) if previous_stock_queue else 0 + if not in_rate and not previous_stock_queue: + in_rate = previous_sle.get('valuation_rate') or 0 elif valuation_method == 'Moving Average': in_rate = previous_sle.get('valuation_rate') or 0