Incoming rate for stock ledger entry should not be rounded

This commit is contained in:
Nabin Hait 2013-12-23 12:14:45 +05:30
parent 4b5ced03ec
commit 861453279d
6 changed files with 39 additions and 31 deletions

View File

@ -350,7 +350,7 @@ class DocType(BuyingController):
# item gl entries
stock_item_and_auto_accounting_for_stock = False
stock_items = self.get_stock_items()
rounding_diff = 0.0
# rounding_diff = 0.0
for item in self.doclist.get({"parentfield": "entries"}):
if auto_accounting_for_stock and item.item_code in stock_items:
if flt(item.valuation_rate):
@ -359,13 +359,12 @@ class DocType(BuyingController):
# expense will be booked in sales invoice
stock_item_and_auto_accounting_for_stock = True
valuation_amt = flt(flt(item.valuation_rate) * flt(item.qty) * \
flt(item.conversion_factor), self.precision("valuation_rate", item))
valuation_amt = item.amount + item.item_tax_amount + item.rm_supp_cost
rounding_diff += (flt(item.amount, self.precision("amount", item)) +
flt(item.item_tax_amount, self.precision("item_tax_amount", item)) +
flt(item.rm_supp_cost, self.precision("rm_supp_cost", item)) -
valuation_amt)
# rounding_diff += (flt(item.amount, self.precision("amount", item)) +
# flt(item.item_tax_amount, self.precision("item_tax_amount", item)) +
# flt(item.rm_supp_cost, self.precision("rm_supp_cost", item)) -
# valuation_amt)
gl_entries.append(
self.get_gl_dict({
@ -394,11 +393,11 @@ class DocType(BuyingController):
expenses_included_in_valuation = \
self.get_company_default("expenses_included_in_valuation")
if rounding_diff:
import operator
cost_center_with_max_value = max(valuation_tax.iteritems(),
key=operator.itemgetter(1))[0]
valuation_tax[cost_center_with_max_value] -= flt(rounding_diff)
# if rounding_diff:
# import operator
# cost_center_with_max_value = max(valuation_tax.iteritems(),
# key=operator.itemgetter(1))[0]
# valuation_tax[cost_center_with_max_value] -= flt(rounding_diff)
for cost_center, amount in valuation_tax.items():
gl_entries.append(

View File

@ -45,7 +45,7 @@ def merge_similar_entries(gl_map):
same_head.credit = flt(same_head.credit) + flt(entry.credit)
else:
merged_gl_map.append(entry)
# filter zero debit and credit entries
merged_gl_map = filter(lambda x: flt(x.debit)!=0 or flt(x.credit)!=0, merged_gl_map)
return merged_gl_map

View File

@ -108,10 +108,11 @@ class BuyingController(StockController):
item.import_amount = flt(item.import_rate * item.qty,
self.precision("import_amount", item))
item.item_tax_amount = 0.0;
self._set_in_company_currency(item, "import_amount", "amount")
self._set_in_company_currency(item, "import_ref_rate", "purchase_ref_rate")
self._set_in_company_currency(item, "import_rate", "rate")
self._set_in_company_currency(item, "import_amount", "amount")
def calculate_net_total(self):
self.doc.net_total = self.doc.net_total_import = 0.0
@ -183,14 +184,12 @@ class BuyingController(StockController):
if item.item_code and item.qty:
self.round_floats_in(item)
purchase_rate = item.rate if self.doc.doctype == "Purchase Invoice" else item.purchase_rate
# if no item code, which is sometimes the case in purchase invoice,
# then it is not possible to track valuation against it
item.valuation_rate = flt((purchase_rate +
(item.item_tax_amount + item.rm_supp_cost) / item.qty) / item.conversion_factor,
self.precision("valuation_rate", item))
qty_in_stock_uom = flt(item.qty * item.conversion_factor)
item.valuation_rate = ((item.amount + item.item_tax_amount + item.rm_supp_cost)
/ qty_in_stock_uom)
else:
item.valuation_rate = 0.0

View File

@ -58,11 +58,6 @@ class TestDeliveryNote(unittest.TestCase):
self.assertEqual(stock_value, 0)
self.assertEqual(stock_value_difference, -375)
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Delivery Note' and voucher_no=%s
order by account desc""", dn.doc.name, as_dict=1)
self.assertFalse(get_gl_entries("Delivery Note", dn.doc.name))
def test_delivery_note_gl_entry(self):
@ -111,8 +106,8 @@ class TestDeliveryNote(unittest.TestCase):
gl_entries = get_gl_entries("Delivery Note", dn.doc.name)
self.assertTrue(gl_entries)
expected_values = {
stock_in_hand_account: [0.0, 666.65],
"Cost of Goods Sold - _TC": [666.65, 0.0]
stock_in_hand_account: [0.0, 666.67],
"Cost of Goods Sold - _TC": [666.67, 0.0]
}
for i, gle in enumerate(gl_entries):
self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account))

View File

@ -15,8 +15,8 @@ def execute(filters=None):
bom_rate = get_item_bom_rate()
val_rate_map = get_valuation_rate()
precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2
precision = get_currency_precision or 2
data = []
for item in sorted(item_map):
data.append([item, item_map[item]["item_name"],
@ -30,6 +30,14 @@ def execute(filters=None):
])
return columns, data
def get_currency_precision():
company_currency = webnotes.conn.get_value("Company",
webnotes.conn.get_default("company"), "default_currency")
currency_format = webnotes.conn.get_value("Currency", company_currency, "number_format")
from webnotes.utils import get_number_format_info
return get_number_format_info(currency_format)[2]
def get_columns(filters):
"""return columns based on filters"""

View File

@ -113,7 +113,14 @@ def update_entries_after(args, verbose=1):
(qty_after_transaction * valuation_rate) or 0
else:
stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in stock_queue))
# rounding as per precision
from webnotes.model.meta import get_field_precision
meta = webnotes.get_doctype("Stock Ledger Entry")
stock_value = flt(stock_value, get_field_precision(meta.get_field("stock_value"),
webnotes._dict({"fields": sle})))
stock_value_difference = stock_value - prev_stock_value
prev_stock_value = stock_value