Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
4958 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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.

Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ago 22
1827
1
giu 25
850
3
mag 25
2582
1
mag 25
819
1
mag 25
1001