Tree view to be called through button in OpenERP-7

孤者浪人 提交于 2019-12-08 00:08:19

问题


I wanted to know that how may I call the tree view(of different records) through a button . Because returning form view is easy but when I tried to do exact thing for tree view it shows a list only.

The scenario is that I have a search product form. Now when the search is generated,a domain of records is filled in the field.

I want to add a button to call the tree view showing me the records present in that domain. I added a function to button but it showed me all the record in a list , didnot even show only the records in the domain.

I have tried to call the following function through a button-click but it did not meet my needs:

def views(self,cr,uid,ids,context=None):
    for id in ids:
        deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
        my_id=int(deg_obj.my_products)
    return{
          'view_type': 'tree',
          'view_mode': 'tree',
          'res_model': 'product.product',
          'res_id':my_id,
          'context': context,
          'type': 'ir.actions.act_window',
          'readonly':True,
          }

I need some guidance on this to mark my mistake. Thanks to all


回答1:


I have fixed the issue with following changes to my python code.

def views(self,cr,uid,ids,context):
     for id in ids:
         deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
         my_id=int(deg_obj.my_products)
     ss= int(deg_obj.categ_temp2)   
     domain = [('categ_id','=',ss)]
     return {
         'type': 'ir.actions.act_window',
         'name': _('Product'),
         'res_model': 'product.product',
         'view_type': 'form',
         'view_mode': 'tree,form',
         'target': 'current',
         'domain': domain,
               }

Now its working ok. Thanks all




回答2:


try this,

def views(self,cr,uid,ids,context=None):
    view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'product', 'product_product_tree_view')
    view_id = view_ref and view_ref[1] or False

    for id in ids:
        deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
        my_id=int(deg_obj.my_products)

    #this will return product tree view and form view. 
    return {
       'type': 'ir.actions.act_window',
       'name': _('Product'),
       'res_model': 'product.product',
       'view_type': 'form',
       #'res_id': my_id, # this will open particular product,
       'view_id': view_id,
       'view_mode': 'tree',
       'target': 'current',
       'nodestroy': True,
   }


来源:https://stackoverflow.com/questions/25180529/tree-view-to-be-called-through-button-in-openerp-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!