[test] [fix] abs(valuation_rate) for moving average
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 4b58b3c..2a9fa17 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -47,7 +47,7 @@
# from warehouse account
self.check_expense_account(detail)
-
+
gl_list.append(self.get_gl_dict({
"account": warehouse_account[sle.warehouse]["name"],
"against": detail.expense_account,
@@ -56,7 +56,7 @@
"debit": flt(sle.stock_value_difference, 2),
}, warehouse_account[sle.warehouse]["account_currency"]))
- # to target warehouse / expense account
+ # to target warehouse / expense account
gl_list.append(self.get_gl_dict({
"account": detail.expense_account,
"against": warehouse_account[sle.warehouse]["name"],
@@ -70,7 +70,7 @@
if warehouse_with_no_account:
msgprint(_("No accounting entries for the following warehouses") + ": \n" +
"\n".join(warehouse_with_no_account))
-
+
return process_gl_map(gl_list)
def get_voucher_details(self, default_expense_account, default_cost_center, sle_map):
@@ -223,7 +223,7 @@
if against_document and item_code:
incoming_rate = frappe.db.sql("""select abs(ifnull(stock_value_difference, 0) / actual_qty)
from `tabStock Ledger Entry`
- where voucher_type = %s and voucher_no = %s
+ where voucher_type = %s and voucher_no = %s
and item_code = %s and warehouse=%s limit 1""",
(self.doctype, against_document, item_code, warehouse))
incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0
@@ -257,25 +257,25 @@
if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 and flt(d.qty):
return_rate = 0
if cint(self.is_return) and self.return_against and self.docstatus==1:
- return_rate = self.get_incoming_rate_for_sales_return(d.item_code,
+ return_rate = self.get_incoming_rate_for_sales_return(d.item_code,
d.warehouse, self.return_against)
-
+
# On cancellation or if return entry submission, make stock ledger entry for
# target warehouse first, to update serial no values properly
- if d.warehouse and ((not cint(self.is_return) and self.docstatus==1)
+ if d.warehouse and ((not cint(self.is_return) and self.docstatus==1)
or (cint(self.is_return) and self.docstatus==2)):
sl_entries.append(self.get_sl_entries(d, {
"actual_qty": -1*flt(d.qty),
"incoming_rate": return_rate
}))
-
+
if d.target_warehouse:
target_warehouse_sle = self.get_sl_entries(d, {
"actual_qty": flt(d.qty),
"warehouse": d.target_warehouse
})
-
+
if self.docstatus == 1:
if not cint(self.is_return):
args = frappe._dict({
@@ -294,14 +294,14 @@
"outgoing_rate": return_rate
})
sl_entries.append(target_warehouse_sle)
-
- if d.warehouse and ((not cint(self.is_return) and self.docstatus==2)
+
+ if d.warehouse and ((not cint(self.is_return) and self.docstatus==2)
or (cint(self.is_return) and self.docstatus==1)):
sl_entries.append(self.get_sl_entries(d, {
"actual_qty": -1*flt(d.qty),
"incoming_rate": return_rate
}))
-
+
self.make_sl_entries(sl_entries)
def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None,
@@ -374,7 +374,7 @@
def get_warehouse_account():
warehouse_account = frappe._dict()
-
+
for d in frappe.db.sql("""select warehouse, name, account_currency from tabAccount
where account_type = 'Warehouse' and ifnull(warehouse, '') != ''""", as_dict=1):
warehouse_account.setdefault(d.warehouse, d)
diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
index cee8a4f..676724c 100644
--- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
@@ -352,12 +352,12 @@
# stock value diff for source warehouse
stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note",
- "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},
+ "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100", "warehouse": "_Test Warehouse - _TC"},
"stock_value_difference")
# stock value diff for target warehouse
stock_value_difference1 = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note",
- "voucher_no": dn.name, "item_code": "_Test Item", "warehouse": "_Test Warehouse 1 - _TC"},
+ "voucher_no": dn.name, "item_code": "_Test Item Home Desktop 100", "warehouse": "_Test Warehouse 1 - _TC"},
"stock_value_difference")
self.assertEquals(abs(stock_value_difference), stock_value_difference1)
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index c0d5cd0..ce5a0c9 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -109,7 +109,7 @@
def build(self):
# includes current entry!
entries_to_fix = self.get_sle_after_datetime()
-
+
for sle in entries_to_fix:
self.process_sle(sle)
@@ -231,10 +231,10 @@
def get_moving_average_values(self, sle):
actual_qty = flt(sle.actual_qty)
-
+
if actual_qty > 0 or flt(sle.outgoing_rate) > 0:
rate = flt(sle.incoming_rate) if actual_qty > 0 else flt(sle.outgoing_rate)
-
+
if self.qty_after_transaction < 0 and not self.valuation_rate:
# if negative stock, take current valuation rate as incoming rate
self.valuation_rate = rate
@@ -244,11 +244,11 @@
if new_stock_qty:
self.valuation_rate = new_stock_value / flt(new_stock_qty)
-
+
elif not self.valuation_rate and self.qty_after_transaction <= 0:
self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, self.allow_zero_rate)
- return abs(flt(self.valuation_rate))
+ self.valuation_rate = abs(flt(self.valuation_rate))
def get_fifo_values(self, sle):
incoming_rate = flt(sle.incoming_rate)
@@ -288,7 +288,7 @@
if v[1] == outgoing_rate:
index = i
break
-
+
# If no entry found with outgoing rate, collapse stack
if index == None:
new_stock_value = sum((d[0]*d[1] for d in self.stock_queue)) - qty_to_pop*outgoing_rate