[fix] [minor] perpetual inventory: account for each warehouse

This commit is contained in:
Nabin Hait
2013-09-17 15:15:16 +05:30
parent 5cd1d54347
commit 142007a226
15 changed files with 88 additions and 75 deletions

View File

@@ -305,10 +305,11 @@ class DocType(BuyingController):
def get_rate(self,arg):
return get_obj('Purchase Common').get_rate(arg,self)
def get_gl_entries_for_stock(self):
def get_gl_entries_for_stock(self, warehouse_account=None):
against_stock_account = self.get_company_default("stock_received_but_not_billed")
gl_entries = super(DocType, self).get_gl_entries_for_stock(against_stock_account, None)
gl_entries = super(DocType, self).get_gl_entries_for_stock(warehouse_account,
against_stock_account)
return gl_entries

View File

@@ -8,10 +8,12 @@ from __future__ import unicode_literals
import webnotes, unittest
from webnotes.utils import flt
from stock.doctype.stock_ledger_entry.stock_ledger_entry import *
from stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
class TestStockEntry(unittest.TestCase):
def tearDown(self):
webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
set_perpetual_inventory(0)
if hasattr(self, "old_default_company"):
webnotes.conn.set_default("company", self.old_default_company)
@@ -81,14 +83,14 @@ class TestStockEntry(unittest.TestCase):
def test_material_receipt_gl_entry(self):
self._clear_stock_account_balance()
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
set_perpetual_inventory()
mr = webnotes.bean(copy=test_records[0])
mr.insert()
mr.submit()
stock_in_hand_account = webnotes.conn.get_value("Warehouse", mr.doclist[1].t_warehouse,
"account")
stock_in_hand_account = webnotes.conn.get_value("Account", {"account_type": "Warehouse",
"master_name": mr.doclist[1].t_warehouse})
self.check_stock_ledger_entries("Stock Entry", mr.doc.name,
[["_Test Item", "_Test Warehouse - _TC", 50.0]])
@@ -111,7 +113,7 @@ class TestStockEntry(unittest.TestCase):
def test_material_issue_gl_entry(self):
self._clear_stock_account_balance()
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
set_perpetual_inventory()
self._insert_material_receipt()
@@ -122,8 +124,9 @@ class TestStockEntry(unittest.TestCase):
self.check_stock_ledger_entries("Stock Entry", mi.doc.name,
[["_Test Item", "_Test Warehouse - _TC", -40.0]])
stock_in_hand_account = webnotes.conn.get_value("Warehouse", mi.doclist[1].s_warehouse,
"account")
stock_in_hand_account = webnotes.conn.get_value("Account", {"account_type": "Warehouse",
"master_name": mi.doclist[1].s_warehouse})
self.check_gl_entries("Stock Entry", mi.doc.name,
sorted([
[stock_in_hand_account, 0.0, 4000.0],
@@ -146,7 +149,7 @@ class TestStockEntry(unittest.TestCase):
def test_material_transfer_gl_entry(self):
self._clear_stock_account_balance()
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
set_perpetual_inventory()
self._insert_material_receipt()
@@ -157,10 +160,12 @@ class TestStockEntry(unittest.TestCase):
self.check_stock_ledger_entries("Stock Entry", mtn.doc.name,
[["_Test Item", "_Test Warehouse - _TC", -45.0], ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]])
stock_in_hand_account = webnotes.conn.get_value("Warehouse", mtn.doclist[1].s_warehouse,
"account")
fixed_asset_account = webnotes.conn.get_value("Warehouse", mtn.doclist[1].t_warehouse,
"account")
stock_in_hand_account = webnotes.conn.get_value("Account", {"account_type": "Warehouse",
"master_name": mtn.doclist[1].s_warehouse})
fixed_asset_account = webnotes.conn.get_value("Account", {"account_type": "Warehouse",
"master_name": mtn.doclist[1].t_warehouse})
self.check_gl_entries("Stock Entry", mtn.doc.name,
sorted([
@@ -180,7 +185,7 @@ class TestStockEntry(unittest.TestCase):
def test_repack_no_change_in_valuation(self):
self._clear_stock_account_balance()
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
set_perpetual_inventory()
self._insert_material_receipt()
@@ -197,11 +202,11 @@ class TestStockEntry(unittest.TestCase):
order by account desc""", repack.doc.name, as_dict=1)
self.assertFalse(gl_entries)
webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
set_perpetual_inventory(0)
def test_repack_with_change_in_valuation(self):
self._clear_stock_account_balance()
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
set_perpetual_inventory()
self._insert_material_receipt()
@@ -210,8 +215,8 @@ class TestStockEntry(unittest.TestCase):
repack.insert()
repack.submit()
stock_in_hand_account = webnotes.conn.get_value("Warehouse",
repack.doclist[2].t_warehouse, "account")
stock_in_hand_account = webnotes.conn.get_value("Account", {"account_type": "Warehouse",
"master_name": repack.doclist[2].t_warehouse})
self.check_gl_entries("Stock Entry", repack.doc.name,
sorted([
@@ -219,7 +224,7 @@ class TestStockEntry(unittest.TestCase):
["Stock Adjustment - _TC", 0.0, 1000.0],
])
)
webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
set_perpetual_inventory(0)
def check_stock_ledger_entries(self, voucher_type, voucher_no, expected_sle):
expected_sle.sort(key=lambda x: x[0])

View File

@@ -88,7 +88,10 @@ class DocType(DocListController):
if not webnotes.conn.sql("""select name from `tabBatch`
where item='%s' and name ='%s' and docstatus != 2""" % (self.doc.item_code, self.doc.batch_no)):
webnotes.throw("'%s' is not a valid Batch Number for Item '%s'" % (self.doc.batch_no, self.doc.item_code))
if not self.doc.stock_uom:
self.doc.stock_uom = item_det.stock_uom
def get_item_details(self):
return webnotes.conn.sql("""select name, has_batch_no, docstatus,
is_stock_item, has_serial_no, serial_no_series
@@ -97,11 +100,6 @@ class DocType(DocListController):
def validate_serial_no(self):
item_det = self.get_item_details()
if not self.doc.stock_uom:
self.doc.stock_uom = item_det.stock_uom
self.validate_serial_no(item_det)
if item_det.has_serial_no=="No":
if self.doc.serial_no:

View File

@@ -295,12 +295,12 @@ class DocType(StockController):
webnotes.conn.set(self.doc, "stock_value_difference", json.dumps(stock_value_difference))
def get_gl_entries_for_stock(self):
def get_gl_entries_for_stock(self, warehouse_account=None):
if not self.doc.cost_center:
msgprint(_("Please enter Cost Center"), raise_exception=1)
return super(DocType, self).get_gl_entries_for_stock(self.doc.expense_account,
self.doc.cost_center)
return super(DocType, self).get_gl_entries_for_stock(warehouse_account,
self.doc.expense_account, self.doc.cost_center)
def validate_expense_account(self):