holydragon
holydragon

Reputation: 6728

How to hide Edit menu on certain state for every user?

I have a scheduled action that will run every now and then to process orders in a certain state, which I will call it processing status.

I am looking for a solution to hide Edit menu to every user when the state is processing. However, the scheduled action must still be able to execute CRUD to the records.

This is because I need to have the users wait for the processing state to be processed by the system itself without any changing of the record in between the process.

Any solution for this?

Upvotes: 1

Views: 107

Answers (1)

Muhammad Yusuf
Muhammad Yusuf

Reputation: 595

You can achieve that but with a hack, so I am not sure if this would be recommended method

Make a computed field(type HTML, sanitize False,save true) in that model and also add that field in XML

            if rec.state in ['approved']:
                rec.computed_field_value= "<script>$('.o_form_button_edit').remove()</script>"

This will hide the button but now you have add it again, in else

         else:
              rec.computed_field_value= "<button type="button" class="btn btn-primary o_form_button_edit" accesskey="a">Edit</button>"

The issue with this solution:

  1. Open a record in a non-processing state, click edit, and go to the next record the edit button is hidden, but you can still edit it as you are in edit mode

How to overcome this issue Use constraints as well to make sure your logic cannot be challenged and the data stays sane. This can be done on the write(self,vals) method the second option is to hide the save button as well.

for save o_form_button_save, this class will be used you can check classes from inspect element and hide and remove values accordingly

Upvotes: 2

Related Questions