[test] [fix] abs(valuation_rate) for moving average

This commit is contained in:
Rushabh Mehta 2015-10-15 12:28:20 +05:30
parent 9f436a7c71
commit 14a908bdec
3 changed files with 21 additions and 21 deletions

View File

@ -47,7 +47,7 @@ class StockController(AccountsController):
# from warehouse account # from warehouse account
self.check_expense_account(detail) self.check_expense_account(detail)
gl_list.append(self.get_gl_dict({ gl_list.append(self.get_gl_dict({
"account": warehouse_account[sle.warehouse]["name"], "account": warehouse_account[sle.warehouse]["name"],
"against": detail.expense_account, "against": detail.expense_account,
@ -56,7 +56,7 @@ class StockController(AccountsController):
"debit": flt(sle.stock_value_difference, 2), "debit": flt(sle.stock_value_difference, 2),
}, warehouse_account[sle.warehouse]["account_currency"])) }, warehouse_account[sle.warehouse]["account_currency"]))
# to target warehouse / expense account # to target warehouse / expense account
gl_list.append(self.get_gl_dict({ gl_list.append(self.get_gl_dict({
"account": detail.expense_account, "account": detail.expense_account,
"against": warehouse_account[sle.warehouse]["name"], "against": warehouse_account[sle.warehouse]["name"],
@ -70,7 +70,7 @@ class StockController(AccountsController):
if warehouse_with_no_account: if warehouse_with_no_account:
msgprint(_("No accounting entries for the following warehouses") + ": \n" + msgprint(_("No accounting entries for the following warehouses") + ": \n" +
"\n".join(warehouse_with_no_account)) "\n".join(warehouse_with_no_account))
return process_gl_map(gl_list) return process_gl_map(gl_list)
def get_voucher_details(self, default_expense_account, default_cost_center, sle_map): def get_voucher_details(self, default_expense_account, default_cost_center, sle_map):
@ -223,7 +223,7 @@ class StockController(AccountsController):
if against_document and item_code: if against_document and item_code:
incoming_rate = frappe.db.sql("""select abs(ifnull(stock_value_difference, 0) / actual_qty) incoming_rate = frappe.db.sql("""select abs(ifnull(stock_value_difference, 0) / actual_qty)
from `tabStock Ledger Entry` 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""", and item_code = %s and warehouse=%s limit 1""",
(self.doctype, against_document, item_code, warehouse)) (self.doctype, against_document, item_code, warehouse))
incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0 incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0
@ -257,25 +257,25 @@ class StockController(AccountsController):
if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 and flt(d.qty): if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 and flt(d.qty):
return_rate = 0 return_rate = 0
if cint(self.is_return) and self.return_against and self.docstatus==1: 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) d.warehouse, self.return_against)
# On cancellation or if return entry submission, make stock ledger entry for # On cancellation or if return entry submission, make stock ledger entry for
# target warehouse first, to update serial no values properly # 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)): or (cint(self.is_return) and self.docstatus==2)):
sl_entries.append(self.get_sl_entries(d, { sl_entries.append(self.get_sl_entries(d, {
"actual_qty": -1*flt(d.qty), "actual_qty": -1*flt(d.qty),
"incoming_rate": return_rate "incoming_rate": return_rate
})) }))
if d.target_warehouse: if d.target_warehouse:
target_warehouse_sle = self.get_sl_entries(d, { target_warehouse_sle = self.get_sl_entries(d, {
"actual_qty": flt(d.qty), "actual_qty": flt(d.qty),
"warehouse": d.target_warehouse "warehouse": d.target_warehouse
}) })
if self.docstatus == 1: if self.docstatus == 1:
if not cint(self.is_return): if not cint(self.is_return):
args = frappe._dict({ args = frappe._dict({
@ -294,14 +294,14 @@ class StockController(AccountsController):
"outgoing_rate": return_rate "outgoing_rate": return_rate
}) })
sl_entries.append(target_warehouse_sle) 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)): or (cint(self.is_return) and self.docstatus==1)):
sl_entries.append(self.get_sl_entries(d, { sl_entries.append(self.get_sl_entries(d, {
"actual_qty": -1*flt(d.qty), "actual_qty": -1*flt(d.qty),
"incoming_rate": return_rate "incoming_rate": return_rate
})) }))
self.make_sl_entries(sl_entries) self.make_sl_entries(sl_entries)
def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None, def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None,
@ -374,7 +374,7 @@ def get_voucherwise_gl_entries(future_stock_vouchers, posting_date):
def get_warehouse_account(): def get_warehouse_account():
warehouse_account = frappe._dict() warehouse_account = frappe._dict()
for d in frappe.db.sql("""select warehouse, name, account_currency from tabAccount for d in frappe.db.sql("""select warehouse, name, account_currency from tabAccount
where account_type = 'Warehouse' and ifnull(warehouse, '') != ''""", as_dict=1): where account_type = 'Warehouse' and ifnull(warehouse, '') != ''""", as_dict=1):
warehouse_account.setdefault(d.warehouse, d) warehouse_account.setdefault(d.warehouse, d)

View File

@ -352,12 +352,12 @@ class TestDeliveryNote(unittest.TestCase):
# stock value diff for source warehouse # stock value diff for source warehouse
stock_value_difference = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", 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_difference")
# stock value diff for target warehouse # stock value diff for target warehouse
stock_value_difference1 = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Delivery Note", 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") "stock_value_difference")
self.assertEquals(abs(stock_value_difference), stock_value_difference1) self.assertEquals(abs(stock_value_difference), stock_value_difference1)

View File

@ -109,7 +109,7 @@ class update_entries_after(object):
def build(self): def build(self):
# includes current entry! # includes current entry!
entries_to_fix = self.get_sle_after_datetime() entries_to_fix = self.get_sle_after_datetime()
for sle in entries_to_fix: for sle in entries_to_fix:
self.process_sle(sle) self.process_sle(sle)
@ -231,10 +231,10 @@ class update_entries_after(object):
def get_moving_average_values(self, sle): def get_moving_average_values(self, sle):
actual_qty = flt(sle.actual_qty) actual_qty = flt(sle.actual_qty)
if actual_qty > 0 or flt(sle.outgoing_rate) > 0: if actual_qty > 0 or flt(sle.outgoing_rate) > 0:
rate = flt(sle.incoming_rate) if actual_qty > 0 else flt(sle.outgoing_rate) 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 self.qty_after_transaction < 0 and not self.valuation_rate:
# if negative stock, take current valuation rate as incoming rate # if negative stock, take current valuation rate as incoming rate
self.valuation_rate = rate self.valuation_rate = rate
@ -244,11 +244,11 @@ class update_entries_after(object):
if new_stock_qty: if new_stock_qty:
self.valuation_rate = new_stock_value / flt(new_stock_qty) self.valuation_rate = new_stock_value / flt(new_stock_qty)
elif not self.valuation_rate and self.qty_after_transaction <= 0: 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) 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): def get_fifo_values(self, sle):
incoming_rate = flt(sle.incoming_rate) incoming_rate = flt(sle.incoming_rate)
@ -288,7 +288,7 @@ class update_entries_after(object):
if v[1] == outgoing_rate: if v[1] == outgoing_rate:
index = i index = i
break break
# If no entry found with outgoing rate, collapse stack # If no entry found with outgoing rate, collapse stack
if index == None: if index == None:
new_stock_value = sum((d[0]*d[1] for d in self.stock_queue)) - qty_to_pop*outgoing_rate new_stock_value = sum((d[0]*d[1] for d in self.stock_queue)) - qty_to_pop*outgoing_rate