Get standard/historical valuation rate where missing: some minor fixes

This commit is contained in:
Nabin Hait 2017-02-07 01:23:26 +05:30
parent ea8fab52c6
commit 0a6aaf4257
7 changed files with 32 additions and 26 deletions

View File

@ -1316,7 +1316,7 @@
"unique": 0
},
{
"allow_on_submit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
@ -1816,7 +1816,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-02-06 17:05:03.737297",
"modified": "2017-02-07 01:21:03.737800",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",

View File

@ -1382,7 +1382,7 @@
"unique": 0
},
{
"allow_on_submit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
@ -1910,7 +1910,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-02-06 17:01:16.812686",
"modified": "2017-02-07 01:21:47.142162",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",

View File

@ -59,8 +59,9 @@ class StockController(AccountsController):
# try to pick valuation rate from previous sle or Item master and update in SLE
# Otherwise, throw an exception
if not sle.stock_value_difference and sle.voucher_type != "Stock Reconciliation" \
if not sle.stock_value_difference and self.doctype != "Stock Reconciliation" \
and not item_row.get("is_sample_item"):
sle = self.update_stock_ledger_entries(sle)
gl_list.append(self.get_gl_dict({
@ -95,7 +96,7 @@ class StockController(AccountsController):
def update_stock_ledger_entries(self, sle):
sle.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse,
sle.voucher_type, sle.voucher_no)
self.doctype, self.name)
sle.stock_value = flt(sle.qty_after_transaction) * flt(sle.valuation_rate)
sle.stock_value_difference = flt(sle.actual_qty) * flt(sle.valuation_rate)
@ -162,9 +163,9 @@ class StockController(AccountsController):
stock_ledger = {}
stock_ledger_entries = frappe.db.sql("""
select
name, warehouse, stock_value_difference, valuation_rate
name, warehouse, stock_value_difference, valuation_rate,
voucher_detail_no, item_code, posting_date, posting_time,
actual_qty, qty_after_transaction, voucher_type, voucher_no
actual_qty, qty_after_transaction
from
`tabStock Ledger Entry`
where
@ -173,7 +174,6 @@ class StockController(AccountsController):
for sle in stock_ledger_entries:
stock_ledger.setdefault(sle.voucher_detail_no, []).append(sle)
return stock_ledger
def make_adjustment_entry(self, expected_gle, voucher_obj):

View File

@ -1477,7 +1477,7 @@
"width": "120px"
},
{
"allow_on_submit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
@ -1719,7 +1719,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-02-06 17:00:24.354000",
"modified": "2017-02-07 01:22:03.047137",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note Item",

View File

@ -1575,7 +1575,7 @@
"unique": 0
},
{
"allow_on_submit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
@ -1913,7 +1913,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-02-06 17:04:23.305884",
"modified": "2017-02-07 01:21:36.348032",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt Item",

View File

@ -1004,7 +1004,7 @@
"unique": 0
},
{
"allow_on_submit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
@ -1183,7 +1183,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-02-06 17:08:06.841514",
"modified": "2017-02-07 01:21:14.367586",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Entry Detail",

View File

@ -261,10 +261,7 @@ class update_entries_after(object):
# Get valuation rate from previous SLE or Item master, if item is not a sample item
if not self.valuation_rate and sle.voucher_detail_no:
ref_item_dt = sle.voucher_type + " Detail" if sle.voucher_type == "Stock Entry" else " Item"
is_sample_item = frappe.db.get_value(ref_item_dt, sle.voucher_detail_no, "is_sample_item")
is_sample_item = self.check_if_sample_item(sle.voucher_type, sle.voucher_detail_no)
if not is_sample_item:
self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse,
sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
@ -292,8 +289,13 @@ class update_entries_after(object):
while qty_to_pop:
if not self.stock_queue:
# Get valuation rate from last sle if exists or from valuation rate field in item master
is_sample_item = self.check_if_sample_item(sle.voucher_type, sle.voucher_detail_no)
if not is_sample_item:
_rate = get_valuation_rate(sle.item_code, sle.warehouse,
sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
else:
_rate = 0
self.stock_queue.append([0, _rate])
index = None
@ -340,6 +342,10 @@ class update_entries_after(object):
if not self.stock_queue:
self.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.valuation_rate])
def check_if_sample_item(self, voucher_type, voucher_detail_no):
ref_item_dt = voucher_type + (" Detail" if voucher_type == "Stock Entry" else " Item")
return frappe.db.get_value(ref_item_dt, voucher_detail_no, "is_sample_item")
def get_sle_before_datetime(self):
"""get previous stock ledger entry before current time-bucket"""
return get_stock_ledger_entries(self.args, "<", "desc", "limit 1", for_update=False)
@ -438,6 +444,6 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, allow_zer
if not allow_zero_rate and not valuation_rate \
and cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")):
frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries. If the item is transacting as a sample item in {1} {2}, please mention that in the {1} Item table. Otherwise, please create an incoming stock transaction for the item or mention valuation rate in the Item record, and then try submiting this entry").format(item_code, voucher_type, voucher_no))
frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries for {1} {2}. If the item is transacting as a sample item in the {1}, please mention that in the {1} Item table. Otherwise, please create an incoming stock transaction for the item or mention valuation rate in the Item record, and then try submiting/cancelling this entry").format(item_code, voucher_type, voucher_no))
return valuation_rate