[perpetual accounting] fixes in testcases
diff --git a/accounts/general_ledger.py b/accounts/general_ledger.py
index 959bfbb..8cfcfd9 100644
--- a/accounts/general_ledger.py
+++ b/accounts/general_ledger.py
@@ -28,6 +28,9 @@
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
diff --git a/controllers/stock_controller.py b/controllers/stock_controller.py
index 0c95c49..4fe6077 100644
--- a/controllers/stock_controller.py
+++ b/controllers/stock_controller.py
@@ -38,7 +38,6 @@
return gl_entries
def sync_stock_account_balance(self, warehouse_list, cost_center=None, posting_date=None):
- # print "sync_stock_account_balance"
from accounts.utils import get_stock_and_account_difference
acc_diff = get_stock_and_account_difference(warehouse_list)
if not cost_center:
@@ -56,7 +55,7 @@
if posting_date:
for entries in gl_entries:
entries["posting_date"] = posting_date
- # print gl_entries
+
make_gl_entries(gl_entries)
def get_sl_entries(self, d, args):
diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py
index 9dae258..8b20e58 100644
--- a/stock/doctype/stock_entry/stock_entry.py
+++ b/stock/doctype/stock_entry/stock_entry.py
@@ -198,7 +198,7 @@
gl_entries += self.get_gl_entries_for_stock(against_expense_account,
valuation_amount, warehouse, cost_center=self.doc.cost_center)
-
+
if gl_entries:
from accounts.general_ledger import make_gl_entries
make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py
index b2b8bfc..546408a 100644
--- a/stock/doctype/stock_entry/test_stock_entry.py
+++ b/stock/doctype/stock_entry/test_stock_entry.py
@@ -82,9 +82,7 @@
self._clear_stock_account_balance()
webnotes.defaults.set_global_default("perpetual_accounting", 1)
- mr = webnotes.bean(copy=test_records[0])
- mr.insert()
- mr.submit()
+ self._insert_material_receipt()
mi = webnotes.bean(copy=test_records[1])
mi.insert()
@@ -110,6 +108,7 @@
self.assertEquals(webnotes.conn.get_value("Bin", {"warehouse": mi.doclist[1].s_warehouse,
"item_code": mi.doclist[1].item_code}, "actual_qty"), 50)
+
self.assertEquals(webnotes.conn.get_value("Bin", {"warehouse": mi.doclist[1].s_warehouse,
"item_code": mi.doclist[1].item_code}, "stock_value"), 5000)
@@ -123,12 +122,8 @@
self._clear_stock_account_balance()
webnotes.defaults.set_global_default("perpetual_accounting", 1)
- mr = webnotes.bean(copy=test_records[0])
- mr.insert()
- mr.submit()
+ self._insert_material_receipt()
-
-
mtn = webnotes.bean(copy=test_records[2])
mtn.insert()
mtn.submit()
@@ -155,32 +150,79 @@
["_Test Item", "_Test Warehouse 1 - _TC", -45.0],
["_Test Item", "_Test Warehouse - _TC", -45.0],
["_Test Item", "_Test Warehouse 1 - _TC", 45.0]]))
+
+ def test_repack_no_change_in_valuation(self):
+ self._clear_stock_account_balance()
+ webnotes.defaults.set_global_default("perpetual_accounting", 1)
+ self._insert_material_receipt()
+
+ repack = webnotes.bean(copy=test_records[3])
+ repack.insert()
+ repack.submit()
+ self.check_stock_ledger_entries("Stock Entry", repack.doc.name,
+ [["_Test Item", "_Test Warehouse - _TC", -50.0],
+ ["_Test Item Home Desktop 100", "_Test Warehouse - _TC", 1]])
+
+ gl_entries = webnotes.conn.sql("""select account, debit, credit
+ from `tabGL Entry` where voucher_type='Stock Entry' and voucher_no=%s
+ order by account desc""", repack.doc.name, as_dict=1)
+ self.assertFalse(gl_entries)
+
+ webnotes.defaults.set_global_default("perpetual_accounting", 0)
+
+ def test_repack_with_change_in_valuation(self):
+ self._clear_stock_account_balance()
+ webnotes.defaults.set_global_default("perpetual_accounting", 1)
+
+ self._insert_material_receipt()
+
+ repack = webnotes.bean(copy=test_records[3])
+ repack.doclist[2].incoming_rate = 6000
+ repack.insert()
+ repack.submit()
+
+ stock_in_hand_account = webnotes.conn.get_value("Warehouse",
+ repack.doclist[2].t_warehouse, "account")
+
+ self.check_gl_entries("Stock Entry", repack.doc.name,
+ sorted([
+ [stock_in_hand_account, 1000.0, 0.0],
+ ["Stock Adjustment - _TC", 0.0, 1000.0],
+ ])
+ )
+ webnotes.defaults.set_global_default("perpetual_accounting", 0)
def check_stock_ledger_entries(self, voucher_type, voucher_no, expected_sle):
- # check stock ledger entries
- sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` where voucher_type = %s
- and voucher_no = %s order by item_code, warehouse, actual_qty""",
- (voucher_type, voucher_no), as_dict=1)
- self.assertTrue(sle)
+ expected_sle.sort(key=lambda x: x[0])
+ # check stock ledger entries
+ sle = webnotes.conn.sql("""select item_code, warehouse, actual_qty
+ from `tabStock Ledger Entry` where voucher_type = %s
+ and voucher_no = %s order by item_code, warehouse, actual_qty""",
+ (voucher_type, voucher_no), as_list=1)
+ self.assertTrue(sle)
+ sle.sort(key=lambda x: x[0])
+
for i, sle in enumerate(sle):
- self.assertEquals(expected_sle[i][0], sle.item_code)
- self.assertEquals(expected_sle[i][1], sle.warehouse)
- self.assertEquals(expected_sle[i][2], sle.actual_qty)
+ self.assertEquals(expected_sle[i][0], sle[0])
+ self.assertEquals(expected_sle[i][1], sle[1])
+ self.assertEquals(expected_sle[i][2], sle[2])
def check_gl_entries(self, voucher_type, voucher_no, expected_gl_entries):
- # check gl entries
+ expected_gl_entries.sort(key=lambda x: x[0])
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type=%s and voucher_no=%s
- order by account asc, debit asc""", (voucher_type, voucher_no), as_dict=1)
+ order by account asc, debit asc""", (voucher_type, voucher_no), as_list=1)
self.assertTrue(gl_entries)
+ gl_entries.sort(key=lambda x: x[0])
+
for i, gle in enumerate(gl_entries):
- self.assertEquals(expected_gl_entries[i][0], gle.account)
- self.assertEquals(expected_gl_entries[i][1], gle.debit)
- self.assertEquals(expected_gl_entries[i][2], gle.credit)
+ self.assertEquals(expected_gl_entries[i][0], gle[0])
+ self.assertEquals(expected_gl_entries[i][1], gle[1])
+ self.assertEquals(expected_gl_entries[i][2], gle[2])
def _clear_stock(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
@@ -656,5 +698,41 @@
"s_warehouse": "_Test Warehouse - _TC",
"t_warehouse": "_Test Warehouse 1 - _TC",
}
- ]
+ ],
+ [
+ {
+ "company": "_Test Company",
+ "doctype": "Stock Entry",
+ "posting_date": "2013-01-25",
+ "posting_time": "17:14:24",
+ "purpose": "Manufacture/Repack",
+ "fiscal_year": "_Test Fiscal Year 2013",
+ "expense_adjustment_account": "Stock Adjustment - _TC",
+ "cost_center": "_Test Cost Center - _TC"
+ },
+ {
+ "conversion_factor": 1.0,
+ "doctype": "Stock Entry Detail",
+ "item_code": "_Test Item",
+ "parentfield": "mtn_details",
+ "incoming_rate": 100,
+ "qty": 50.0,
+ "stock_uom": "_Test UOM",
+ "transfer_qty": 50.0,
+ "uom": "_Test UOM",
+ "s_warehouse": "_Test Warehouse - _TC",
+ },
+ {
+ "conversion_factor": 1.0,
+ "doctype": "Stock Entry Detail",
+ "item_code": "_Test Item Home Desktop 100",
+ "parentfield": "mtn_details",
+ "incoming_rate": 5000,
+ "qty": 1,
+ "stock_uom": "_Test UOM",
+ "transfer_qty": 1,
+ "uom": "_Test UOM",
+ "t_warehouse": "_Test Warehouse - _TC",
+ },
+ ],
]
\ No newline at end of file
diff --git a/stock/stock_ledger.py b/stock/stock_ledger.py
index fd46402..40461dc 100644
--- a/stock/stock_ledger.py
+++ b/stock/stock_ledger.py
@@ -62,7 +62,7 @@
(qty_after_transaction * valuation_rate) or 0
else:
stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in stock_queue))
- # print sle.posting_date, sle.actual_qty, sle.incoming_rate, stock_queue, stock_value
+
# update current sle
webnotes.conn.sql("""update `tabStock Ledger Entry`
set qty_after_transaction=%s, valuation_rate=%s, stock_queue=%s,