3

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

doniyor
  • 36,596
  • 57
  • 175
  • 260
Arsalan Sherwani
  • 889
  • 2
  • 25
  • 60

2 Answers2

3

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

Arsalan Sherwani
  • 889
  • 2
  • 25
  • 60
1

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,
   }
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
  • Thanks I tried but got errors: """ Non-db action dictionaries should provide either multiple view modes or a single view mode and an optional view id. Got view modes ['tree', 'form'] and view id 220 for action {'target': 'current', 'view_type': 'form', 'res_model': 'product.product', 'view_id': 220, 'nodestroy': True, 'view_mode': 'tree,form', 'flags': {}, 'type': 'ir.actions.act_window'} """ – Arsalan Sherwani Aug 07 '14 at 12:13
  • I get the tree view but its showing me all the records. Its not showing the records in the domain. The search products are 5 records . It should show tree view of 5 records , but its showing me all the records – Arsalan Sherwani Aug 08 '14 at 06:33
  • yes, because we comment on `res_id` or you can use the domain to restrict the all the product. – Bhavesh Odedra Aug 08 '14 at 06:57
  • then on res_id , what can I give for domain here. Because if set res_id:my_id, it is still showing me everything. – Arsalan Sherwani Aug 08 '14 at 07:01
  • like first search your desire product id and store in variable `product_ids` and than give it in `domain.` For example `'domain': ['id', 'in', product_ids]` – Bhavesh Odedra Aug 08 '14 at 08:03
  • my search is running through the query. the product field contains the domain of the products after searching. Therefore the domain contains the id of the results of search products. Searching again will cause issues I think – Arsalan Sherwani Aug 08 '14 at 09:02
  • 'name': _('Product'), NameError: global name '_' is not defined THis is the exact error. – Kannan_SJD Sep 29 '14 at 04:51
  • Might be you forget to import `from openerp.tools.translate import _` It should not give you error. And `name` provide the Name in Left, top corner of form or view, if you give value of `name` with `_` it will translate the name based on login user language. For example one user has English language than form or tree view give `Product` and second user has Spanish language than form or tree view give `producto` Hope this will help you. – Bhavesh Odedra Sep 29 '14 at 05:22
  • Thanks Odedra.. It is really clear.... I understood well... Let me try and I will get back to you... – Kannan_SJD Sep 29 '14 at 14:38
  • TypeError: this.views_src[0] is undefined I am getting this error when trying to return from a product inherited module – Kannan_SJD Sep 29 '14 at 15:39
  • Sorry I am adding it to the end of my write method in inherit method – Kannan_SJD Sep 29 '14 at 16:13
  • Write Method Return True Or False..above Code Is Work On Button Click. SO you need to make a one button and than you need to customize it according to your requirement. – Bhavesh Odedra Sep 29 '14 at 16:41
  • Can you please tell me how to return from form vew to tree view when they save anythng in product view.... I have been trying this for a very long time and I am fed up doing this... If you could help... It will be really helpful...Any workaround is appreciated.. – Kannan_SJD Sep 30 '14 at 05:49