Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
4429 Vistas

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
Mejor respuesta

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.

Mejor respuesta

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
Mejor respuesta

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
Publicaciones relacionadas Respuestas Vistas Actividad
1
ago 22
1569
1
may 25
480
4
may 25
1771
2
may 25
1873
1
feb 25
5198