Skip to Content
Menú
This question has been flagged
3 Respostes
5378 Vistes

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
Descartar
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
Descartar
Autor

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
Descartar
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
Descartar
Related Posts Respostes Vistes Activitat
1
d’ag. 22
1965
1
de juny 25
1344
3
de jul. 25
3050
1
de maig 25
1201
1
de maig 25
1473