Skip to Content
Menu
This question has been flagged
3 Replies
4424 Views

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.

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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.

Best Answer

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

Avatar
Discard
Best Answer

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()".
Avatar
Discard
Related Posts Replies Views Activity
1
Aug 22
1568
4
May 25
1755
2
May 25
1864
0
Mar 25
445
1
Feb 25
5191