Maintain negative stock balance if balance qty is negative

This commit is contained in:
Nabin Hait
2014-10-09 19:25:03 +05:30
parent b7e5ad0a31
commit 4d74216147
8 changed files with 118 additions and 50 deletions

View File

@@ -269,7 +269,7 @@ class BuyingController(StockController):
# get raw materials rate
if self.doctype == "Purchase Receipt":
from erpnext.stock.utils import get_incoming_rate
rm.rate = get_incoming_rate({
item_rate = get_incoming_rate({
"item_code": bom_item.item_code,
"warehouse": self.supplier_warehouse,
"posting_date": self.posting_date,
@@ -277,6 +277,7 @@ class BuyingController(StockController):
"qty": -1 * required_qty,
"serial_no": rm.serial_no
})
rm.rate = item_rate or bom_item.rate
else:
rm.rate = bom_item.rate

View File

@@ -305,9 +305,15 @@ def get_valuation_rate(item_code, warehouse):
last_valuation_rate = frappe.db.sql("""select valuation_rate
from `tabStock Ledger Entry`
where item_code = %s and warehouse = %s
and ifnull(qty_after_transaction, 0) > 0
and ifnull(valuation_rate, 0) > 0
order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse))
if not last_valuation_rate:
last_valuation_rate = frappe.db.sql("""select valuation_rate
from `tabStock Ledger Entry`
where item_code = %s and ifnull(valuation_rate, 0) > 0
order by posting_date desc, posting_time desc, name desc limit 1""", item_code)
valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0
if not valuation_rate: