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