Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
2378 Vizualizări

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?


Imagine profil
Abandonează
Autor Cel mai bun răspuns

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)]}


Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
feb. 21
4115
3
mai 24
3560
0
sept. 17
3928
2
iul. 25
4110
2
dec. 24
7404