blob: 273c4424a18dbaab9ab9bf0cae7be3a9f01a8870 [file] [log] [blame]
Nabin Hait31665e52011-09-29 10:41:02 +05301import unittest
2
3import webnotes
4import webnotes.profile
5webnotes.user = webnotes.profile.Profile()
6
7
8from webnotes.model.doc import Document
9from webnotes.model.code import get_obj
10from webnotes.utils import cstr, flt
11sql = webnotes.conn.sql
12
13from sandbox.testdata.masters import *
14from sandbox.testdata import stock_entry
15#----------------------------------------------------------
16
17class TestStockEntry(unittest.TestCase):
18 def setUp(self):
19 print "====================================="
20 webnotes.conn.begin()
21
22 create_master_records()
23 print 'Master Data Created'
24
25 for each in stock_entry.mr:
26 each.save(1)
27
28 for t in stock_entry.mr[1:]:
29 sql("update `tabStock Entry Detail` set parent = '%s' where name = '%s'" % (stock_entry.mr[0].name, t.name))
30 print "Stock Entry Created"
31
32
33 #===========================================================================
34 def test_stock_entry_onsubmit(self):
35 print "Test Case: Stock Entry submission"
36 self.submit_stock_entry()
37
38 expected_sle = (('Stock Entry', stock_entry.mr[0].name, 10, 10, 100, 'No'),)
39 self.check_sle(expected_sle)
40
41 self.check_bin_qty(10)
42 self.check_serial_no('submit', 10)
43
44 #===========================================================================
45 def test_stock_entry_oncancel(self):
46 print "Test Case: Stock Entry Cancellation"
47 self.cancel_stock_entry()
48
49 expected_sle = (
50 ('Stock Entry', stock_entry.mr[0].name, 10, 10, 100, 'Yes'),
51 ('Stock Entry', stock_entry.mr[0].name, -10, None, None, 'Yes'),
52 )
53 self.check_sle(expected_sle)
54
55 self.check_bin_qty(0)
56 self.check_serial_no('cancel', 10)
57
58
59 #===========================================================================
60 def submit_stock_entry(self):
61 ste1 = get_obj('Stock Entry', stock_entry.mr[0].name, with_children=1)
62 ste1.validate()
63 ste1.on_submit()
64
65 ste1.doc.docstatus = 1
66 ste1.doc.save()
67
68 print "Stock Entry Submitted"
69
70
71 #===========================================================================
72 def cancel_stock_entry(self):
73 self.submit_stock_entry()
74
75 ste1 = get_obj('Stock Entry', stock_entry.mr[0].name, with_children=1)
76 ste1.on_cancel()
77
78 ste1.doc.cancel_reason = "testing"
79 ste1.doc.docstatus = 2
80 ste1.doc.save()
81
82 print "Stock Entry Cancelled"
83
84 #===========================================================================
85 def check_sle(self, expected):
86 print "Checking stock ledger entry........."
87 sle = sql("select voucher_type, voucher_no, actual_qty, bin_aqat, valuation_rate, is_cancelled from `tabStock Ledger Entry` where item_code = 'it' and warehouse = 'wh1'")
88 self.assertTrue(sle == expected)
89
90 #===========================================================================
91 def check_bin_qty(self, expected_qty):
92 print "Checking Bin qty........."
93 bin_qty = sql("select actual_qty from tabBin where item_code = 'it' and warehouse = 'wh1'")
94 self.assertTrue(bin_qty[0][0] == expected_qty)
95
96 #===========================================================================
97 def check_serial_no(self, action, cnt):
98 print "Checking serial nos........"
99 if action == 'submit':
100 status, wh, docstatus = 'In Store', 'wh1', 0
101 else:
102 status, wh, docstatus = 'Not in Use', '', 2
103
104 ser = sql("select count(name) from `tabSerial No` where item_code = 'it' and warehouse = '%s' and status = '%s' and docstatus = %s" % (wh, status, docstatus))
105
106 self.assertTrue(ser[0][0] == cnt)
107
108 #===========================================================================
109 def tearDown(self):
110 webnotes.conn.rollback()