[FIX]: restrict the journal list in search view and list view of Journal Items
authorMantavya Gajjar <mga@tinyerp.com>
Fri, 13 Aug 2010 13:47:30 +0000 (19:17 +0530)
committerMantavya Gajjar <mga@tinyerp.com>
Fri, 13 Aug 2010 13:47:30 +0000 (19:17 +0530)
bzr revid: mga@tinyerp.com-20100813134730-8113k9lix2ebrncw

addons/account/account.py
addons/account/account_move_line.py

index b39ed2a..4c75436 100644 (file)
@@ -716,7 +716,7 @@ class account_journal(osv.osv):
         result = self.write(cr, uid, [journal.id], res)
             
         return result
-        
+    
     def create(self, cr, uid, vals, context={}):
         journal_id = super(account_journal, self).create(cr, uid, vals, context)
         self.create_sequence(cr, uid, [journal_id], context)
@@ -736,10 +736,15 @@ class account_journal(osv.osv):
         if not args:
             args = []
         ids = []
+
+        if context.get('journal_type', False):
+            args += [('type','=',context.get('journal_type'))]
+        
         if name:
             ids = self.search(cr, user, [('code','ilike',name)]+ args, limit=limit, context=context)
         if not ids:
             ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context)
+
         return self.name_get(cr, user, ids, context=context)
 
     def onchange_type(self, cr, uid, ids, type, currency):
index effcdf9..eae81a3 100644 (file)
@@ -842,11 +842,18 @@ class account_move_line(osv.osv):
         }
 
     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):
+        journal_pool = self.pool.get('account.journal')
+        
         result = super(osv.osv, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
         if view_type != 'tree':
             #Remove the toolbar from the form view
             if view_type == 'form':
                 result['toolbar']['action'] = []
+
+            #Restrict the list of journal view in search view
+            if view_type == 'search':
+                journal_list = journal_pool.name_search(cr, uid, '', [], context=context)
+                result['fields']['journal_id']['selection'] = journal_list
             return result
 
         fld = []
@@ -854,7 +861,7 @@ class account_move_line(osv.osv):
         flds = []
         title = "Accounting Entries" #self.view_header_get(cr, uid, view_id, view_type, context)
         xml = '''<?xml version="1.0"?>\n<tree string="%s" editable="top" refresh="5" on_write="on_create_write">\n\t''' % (title)
-        journal_pool = self.pool.get('account.journal')
+        
 
         ids = journal_pool.search(cr, uid, [])
         journals = journal_pool.browse(cr, uid, ids)