콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
2682 화면

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?


아바타
취소
작성자 베스트 답변

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


아바타
취소
베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
1
2월 21
4366
3
5월 24
3842
0
9월 17
4188
2
7월 25
4870
2
12월 24
7928