From 6e9756b8bbad5825133252343cf54567fee44b0f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 22 Jan 2013 16:49:55 +0530 Subject: [PATCH] valuation rate mandatory for opening stock reco --- .../stock_reconciliation/stock_reconciliation.py | 15 ++++++++++----- .../test_stock_reconciliation.py | 1 - 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.py b/stock/doctype/stock_reconciliation/stock_reconciliation.py index 9017843c66..32fcf89151 100644 --- a/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -141,11 +141,18 @@ class DocType(DocListController): "posting_time": self.doc.posting_time }) + # check valuation rate mandatory + if row.qty != "" and not row.valuation_rate and \ + flt(previous_sle.get("qty_after_transaction")) <= 0: + webnotes.msgprint(_("As existing qty for item: ") + row.item_code + + _(" is less than equals to zero in the system, \ + valuation rate is mandatory for this item"), raise_exception=1) + change_in_qty = row.qty != "" and \ (flt(row.qty) - flt(previous_sle.get("qty_after_transaction"))) - + change_in_rate = row.valuation_rate != "" and \ - (flt(row.valuation_rate) != flt(previous_sle.get("valuation_rate"))) + (flt(row.valuation_rate) - flt(previous_sle.get("valuation_rate"))) if get_valuation_method(row.item_code) == "Moving Average": self.sle_for_moving_avg(row, previous_sle, change_in_qty, change_in_rate) @@ -162,7 +169,6 @@ class DocType(DocListController): else: if valuation_rate == "": valuation_rate = previous_valuation_rate - return (qty * valuation_rate - previous_qty * previous_valuation_rate) \ / flt(qty - previous_qty) @@ -175,7 +181,7 @@ class DocType(DocListController): self.insert_entries({"actual_qty": change_in_qty, "incoming_rate": incoming_rate}, row) - elif change_in_rate and flt(previous_sle.get("qty_after_transaction")) >= 0: + elif change_in_rate and flt(previous_sle.get("qty_after_transaction")) > 0: # if no change in qty, but change in rate # and positive actual stock before this reconciliation incoming_rate = _get_incoming_rate( @@ -241,7 +247,6 @@ class DocType(DocListController): "is_cancelled": "No", } args.update(opts) - # create stock ledger entry sle_wrapper = webnotes.model_wrapper([args]) sle_wrapper.ignore_permissions = 1 diff --git a/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index b3501cef56..7030c1b492 100644 --- a/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -21,7 +21,6 @@ import webnotes from webnotes.tests import insert_test_data from webnotes.utils import flt import json -from pprint import pprint company = webnotes.conn.get_default("company")