[FIX] account: change decimal precision to avoid erasing tax and base values when...
[odoo/odoo.git] / addons / account / tests / test_search.py
1 from openerp.tests.common import TransactionCase
2
3 class TestSearch(TransactionCase):
4     """Tests for search on name_search (account.account)
5
6     The name search on account.account is quite complexe, make sure
7     we have all the correct results
8     """
9
10     def setUp(self):
11         super(TestSearch, self).setUp()
12         cr, uid = self.cr, self.uid
13         self.account_model = self.registry('account.account')
14         self.account_type_model = self.registry('account.account.type')
15         ac_ids = self.account_type_model.search(cr, uid, [], limit=1)
16         self.atax = (int(self.account_model.create(cr, uid, dict(
17             name="Tax Received",
18             code="121",
19             user_type=ac_ids[0],
20         ))), "121 Tax Received")
21
22         self.apurchase = (int(self.account_model.create(cr, uid, dict(
23             name="Purchased Stocks",
24             code="1101",
25             user_type=ac_ids[0],
26         ))), "1101 Purchased Stocks")
27
28         self.asale = (int(self.account_model.create(cr, uid, dict(
29             name="Product Sales",
30             code="200",
31             user_type=ac_ids[0],
32         ))), "200 Product Sales")
33
34         self.all_ids = [self.atax[0], self.apurchase[0], self.asale[0]]
35
36     def test_name_search(self):
37         cr, uid = self.cr, self.uid
38         atax_ids = self.account_model.name_search(cr, uid, name="Tax", operator='ilike', args=[('id', 'in', self.all_ids)])
39         self.assertEqual(set([self.atax[0]]), set([a[0] for a in atax_ids]), "name_search 'ilike Tax' should have returned Tax Received account only")
40
41         atax_ids = self.account_model.name_search(cr, uid, name="Tax", operator='not ilike', args=[('id', 'in', self.all_ids)])
42         self.assertEqual(set([self.apurchase[0], self.asale[0]]), set([a[0] for a in atax_ids]), "name_search 'not ilike Tax' should have returned all but Tax Received account")
43
44         apur_ids = self.account_model.name_search(cr, uid, name='1101', operator='ilike', args=[('id', 'in', self.all_ids)])
45         self.assertEqual(set([self.apurchase[0]]), set([a[0] for a in apur_ids]), "name_search 'ilike 1101' should have returned Purchased Stocks account only")
46
47         apur_ids = self.account_model.name_search(cr, uid, name='1101', operator='not ilike', args=[('id', 'in', self.all_ids)])
48         self.assertEqual(set([self.atax[0], self.asale[0]]), set([a[0] for a in apur_ids]), "name_search 'not ilike 1101' should have returned all but Purchased Stocks account")
49
50         asale_ids = self.account_model.name_search(cr, uid, name='200 Sales', operator='ilike', args=[('id', 'in', self.all_ids)])
51         self.assertEqual(set([self.asale[0]]), set([a[0] for a in asale_ids]), "name_search 'ilike 200 Sales' should have returned Product Sales account only")
52
53         asale_ids = self.account_model.name_search(cr, uid, name='200 Sales', operator='not ilike', args=[('id', 'in', self.all_ids)])
54         self.assertEqual(set([self.atax[0], self.apurchase[0]]), set([a[0] for a in asale_ids]), "name_search 'not ilike 200 Sales' should have returned all but Product Sales account")
55
56         asale_ids = self.account_model.name_search(cr, uid, name='Product Sales', operator='ilike', args=[('id', 'in', self.all_ids)])
57         self.assertEqual(set([self.asale[0]]), set([a[0] for a in asale_ids]), "name_search 'ilike Product Sales' should have returned Product Sales account only")
58
59         asale_ids = self.account_model.name_search(cr, uid, name='Product Sales', operator='not ilike', args=[('id', 'in', self.all_ids)])
60         self.assertEqual(set([self.atax[0], self.apurchase[0]]), set([a[0] for a in asale_ids]), "name_search 'not ilike Product Sales' should have returned all but Product Sales account")