blob: d02d6f5c42dc561bf032b6560b414f99b4b1b820 [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
25from webnotes.model.doc import Document
26from webnotes.model.code import get_obj
27from webnotes.utils import cstr, flt
28from webnotes.model.doclist import getlist
29sql = webnotes.conn.sql
30
31from sandbox.testdata.masters import *
32from sandbox.testdata.sle_data import sle, bin
33from sandbox.testdata.stock_reco import *
34#----------------------------------------------------------
35
36
37class TestStockEntry(unittest.TestCase):
38 def assertDoc(self, lst):
39 """assert all values"""
40 for d in lst:
41 cl, vl = [], []
42 for k in d.keys():
43 if k!='doctype':
44 cl.append('%s=%s' % (k, '%s'))
45 vl.append(d[k])
46
47 self.assertTrue(sql("select name from `tab%s` where %s limit 1" % (d['doctype'], ' and '.join(cl)), vl))
48
49 #===========================================================================
50 def setUp(self):
51 print "====================================="
52 webnotes.conn.begin()
53 create_master_records()
54 print 'Master Data Created'
55
56 for d in sle:
57 d.save(1)
58 print "Existing SLE created"
59
60 bin.save(1)
61
62 sreco.save(1)
63 print "Stock Reco saved"
64
65 #===========================================================================
66 def test_diff_in_both(self):
67 reco = get_obj('Stock Reconciliation', sreco.name)
68 reco.doc.docstatus = 1
69 reco.doc.save()
70 reco.validate()
71 reco.on_submit()
72 print "Stock Reco submitted"
73
74 print "Checking stock ledger entry........."
75 self.assertDoc(self.get_expected_sle('diff_in_both'))
76
77 #===========================================================================
78 def tearDown(self):
79 webnotes.conn.rollback()
80
81 # Expected Result Set
82 #===================================================================================================
83 def get_expected_sle(self, action):
84 expected_sle = {
85 'diff_in_both': [{
86 'doctype': 'Stock Ledger Entry',
87 'item_code':'it',
88 'warehouse':'wh1',
89 'voucher_type': 'Stock Reconciliation',
90 'voucher_no': sreco.name,
91 'actual_qty': 15,
92 'bin_aqat': 20,
93 'valuation_rate': 150,
94 #'stock_value': 3000,
95 'is_cancelled': 'No'
96 },{
97 'doctype': 'Stock Ledger Entry',
98 'posting_date': '2011-09-10',
99 'posting_time': '15:00',
100 'item_code': 'it',
101 'warehouse': 'wh1',
102 'actual_qty': 20,
103 'incoming_rate': 200,
104 'bin_aqat': 40,
105 'valuation_rate': 175,
106 #'stock_value': 4500,
107 'is_cancelled': 'No'
108 }
109 ]
110 }
111 return expected_sle[action]