blob: ada85b48db9f02f36dd0f054e4bfa9d52bc91e14 [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Anand Doshi486f9df2012-07-19 13:40:31 +053017from __future__ import unicode_literals
Nabin Haitfc26f642011-11-21 17:13:53 +053018import unittest
19
20import webnotes
21import webnotes.profile
22webnotes.user = webnotes.profile.Profile()
23
24
Nabin Haitfc26f642011-11-21 17:13:53 +053025from webnotes.model.code import get_obj
Nabin Haitfc26f642011-11-21 17:13:53 +053026sql = webnotes.conn.sql
27
28from sandbox.testdata.masters import *
29from sandbox.testdata.sle_data import sle, bin
30from sandbox.testdata.stock_reco import *
31#----------------------------------------------------------
32
33
34class TestStockEntry(unittest.TestCase):
35 def assertDoc(self, lst):
36 """assert all values"""
37 for d in lst:
38 cl, vl = [], []
39 for k in d.keys():
40 if k!='doctype':
41 cl.append('%s=%s' % (k, '%s'))
42 vl.append(d[k])
43
44 self.assertTrue(sql("select name from `tab%s` where %s limit 1" % (d['doctype'], ' and '.join(cl)), vl))
45
46 #===========================================================================
47 def setUp(self):
48 print "====================================="
49 webnotes.conn.begin()
50 create_master_records()
51 print 'Master Data Created'
52
53 for d in sle:
54 d.save(1)
55 print "Existing SLE created"
56
57 bin.save(1)
58
59 sreco.save(1)
60 print "Stock Reco saved"
61
62 #===========================================================================
63 def test_diff_in_both(self):
64 reco = get_obj('Stock Reconciliation', sreco.name)
65 reco.doc.docstatus = 1
66 reco.doc.save()
67 reco.validate()
68 reco.on_submit()
69 print "Stock Reco submitted"
70
71 print "Checking stock ledger entry........."
72 self.assertDoc(self.get_expected_sle('diff_in_both'))
73
74 #===========================================================================
75 def tearDown(self):
76 webnotes.conn.rollback()
77
78 # Expected Result Set
79 #===================================================================================================
80 def get_expected_sle(self, action):
81 expected_sle = {
82 'diff_in_both': [{
83 'doctype': 'Stock Ledger Entry',
84 'item_code':'it',
85 'warehouse':'wh1',
86 'voucher_type': 'Stock Reconciliation',
87 'voucher_no': sreco.name,
88 'actual_qty': 15,
89 'bin_aqat': 20,
90 'valuation_rate': 150,
91 #'stock_value': 3000,
92 'is_cancelled': 'No'
93 },{
94 'doctype': 'Stock Ledger Entry',
95 'posting_date': '2011-09-10',
96 'posting_time': '15:00',
97 'item_code': 'it',
98 'warehouse': 'wh1',
99 'actual_qty': 20,
100 'incoming_rate': 200,
101 'bin_aqat': 40,
102 'valuation_rate': 175,
103 #'stock_value': 4500,
104 'is_cancelled': 'No'
105 }
106 ]
107 }
108 return expected_sle[action]