Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5336 Lượt xem

Hello developer's, need a support!!!

I create a qweb-action in my form view and it's working fine, Now I want to hide this print button conditionally depending on my model data state like we do for usual buttons. Can I do that?

I want to hide my "Cash register" action when the state is in "Processing"

Thanks in Advance.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

HI Tarikol Islam,

You can do it using the fields_view_get method, But it will hide the action when the method will load. So when you change the records, it will not work.

On my suggestion, please add the cash register action button and add it in the header of the form. assign it the report action. then you can add attrs to hide it.

Hope it will help you.

Ảnh đại diện
Huỷ bỏ
Tác giả

Sure Thanks for the reply, but it has to be, what asked by the PM. I had also asked for the button event for generating a report.

Câu trả lời hay nhất

Hi,

To conditionally hide a QWeb action button using the `get_views` method, you can override the method and include your logic to filter the views based on the model's state. Here's a concise example:


from odoo import models

class YourModel(models.Model):

    _inherit = 'your.model'


    def get_views(self, views, options=None):

        result = super(YourModel, self).get_views(views, options=options)

        # Add conditional logic based on the model's state

        if self.state != 'desired_state':

            # Modify the result to hide the button

            result = [view for view in result if view[0] != 'form']

        return result


In this example:

- Replace `'desired_state'` with the condition you want to check.

- Adjust the filtering logic as needed to hide or show the views accordingly.


Hope it helps

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Maybe I'm a little bit late but for those who still are struggeling with this there are two options:

  1. Manage in the ir.actions.report model under security the visibility by groups (standard and easy)
  2. Patch the component "ActionMenus" and override the function "get printItems()".
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 22
1949
1
thg 6 25
1252
3
thg 7 25
3018
1
thg 5 25
1167
1
thg 5 25
1441