Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
2539 Tampilan

Hello,

I've inherited the sale.order to add a new boolean field make_ready, like the following

class SaleOrder(models.Model): 
_name = 'sale.order' 
_inherit = 'sale.order'
make_ready = fields.Boolean(default=False, index=True)



(I also have a new button (near the confirm) in the sale_order view to change the above boolean field)
Then, I've a new filter element in the quotation tree view to filter the quotations based on the value of the above field


 < filter string="Made ready" name="made_ready_quotations"                         domain="[('make_ready', '=', True),('state','in', ('sent','draft'))]" >

It works well.

Now, I've added a new filed to sale.config.settings to show/hide the above new aditions, like below

class SaleConfigSettings(models.TransientModel): 
_inherit = 'sale.config.settings' 
make_ready_required = fields.Boolean(default=False, string="Make ready required?")

and to get the value of this field in sale.order, I've added a new compute field like below

show_make_ready = fields.Boolean(default=False, index=True, compute='_show_make_ready')
@api.model    def _show_make_ready(self): 
return self.env['ir.values'].get_default('sale.config.settings', 'make_ready_required')

------

Now, can I show/hide the initially added search filter based on the value of this show_make_ready field?
Or, is there a better way to achive this?


Avatar
Buang
Penulis Jawaban Terbai

Thanks for the response.
I've actually got the filter working based on the value of the field added to *sale.order*  -  ie, make_ready

Now, I need to hide/show this new added filter based on a value in the sale.config.settings.

I've tried it like below

domain="[('ready_to_bill', '=', True),('state','in', ('sent','draft'))]" 

attrs="{'invisible': [('show_make_ready', '=',False)]}" /> 

Also tried adding an inner *attribute* element like the following
{'invisible':[('show_ready_to_bill', '=', False)]}


Avatar
Buang
Jawaban Terbai

Hi,

For using the compute field, we have to store it in the database first, In Odoo, the computed fields can be stored in two different ways. By setting store=True, we can create the store field. Additionally, you can use a search function by setting it on the field.


The other method to search using a computed field is to add a search function to the computing field.For more details, refer to the blog:

How to Add a Search Filter for Computed Fields in Odoo 16


Hope it helps

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Feb 21
4218
3
Mei 24
3719
0
Sep 17
4059
2
Jul 25
4551
2
Des 24
7710