Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
2424 Visualizzazioni

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
Abbandona
Autore Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
feb 21
4120
3
mag 24
3591
0
set 17
3947
2
lug 25
4179
2
dic 24
7440