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