تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2080 أدوات العرض

Hello, 

I am creating a maintenance module where I use products as the maintenance actions. 

eg: product: revise engine


But  I don't want these products to show up any where else then in my maintenance module. 

I know I can add domain filters to the other views-actions to filter out these products, but this is a lot of work. And adding them to every one2many field. This is almost impossible. 

Is there a way to hide the products in all the views exept for the views where I want them to? 

I was thinking about record rules, but it doesn't look like the rules have any knowledge about the view that is shown.

Please let me know your ideas!

Thanks, 


الصورة الرمزية
إهمال

you can set the check boxes can be sold and can be purchased so it won't appear in most views.  or archive the product.  

أفضل إجابة

Hello Dries,

You can do this by simply overriding the method search_read in the inherited model product.product. Just follow the code written below:


class Product(models.Model):    
​_inherit = 'product.product'
​@api.model
​def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None, **read_kwargs):
​if self.env.context('field_name', False):
domain += [('field_name', '=', True)] # or the domain you want to add.
​else:
domain += [('field_name', '=', False)] # or the domain you want to add to restrict everywhere.
​return super().search_read(domain, fields, offset, limit, order)


In your product view action:


    My Product    ir.actions.act_window    product.product    tree,form    {'field_name': True}            

Ready to recruit more efficiently?

Let's create a job position.


As every tree and form view is calling the search_read method, you just need to play with the domain name here.


Thanks & Regards, 

 

Brain Station 23 Ltd. 

Mobile: (+880) 1404055226 

Email: sales@brainstation-23.com 

Web: https://brainstation-23.com/ 

Address: (Building-1) 8th Floor, 2 Bir Uttam AK Khandakar Road, Mohakhali C/A, Dhaka 1212, Bangladesh 


الصورة الرمزية
إهمال
الكاتب

Great, thank you, this definitely looks like a good way to do this.
Thank you,

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
سبتمبر 23
2253
1
أبريل 24
2598
1
يناير 24
2095
1
نوفمبر 23
2153
4
نوفمبر 23
2931