Reputation: 33
I would like to know the way to hide the "edit" button from the form view when it is in a specific state
for example: In the help desk I have the states that are shown in the image, I want the edit button to be completely hidden from all people when it goes to "closed" state
Upvotes: 2
Views: 1293
Reputation: 33
Add Html Field
test_css = fields.Html(string='CSS', sanitize=False, compute='_compute_css', store=False)
Add compute function
@api.depends('state')
def _compute_css(self):
for record in self:
# You can modify the below below condition
if record.state != 'draft':
record.test_css = '<style>.o_form_button_edit {display: none !important;}</style>'
else:
record.test_css = False
Finally Add the field in the form view
<field name="test_css" invisible="1"/>
Here is the screenshot of sample code
Upvotes: 1
Reputation: 85
If you want to do it in a specific form you can change your form element with the below line:
<form edit="false" >
If you want to do it globally you will need to do it from js code.
Upvotes: 1
Reputation: 1314
Let s try this idea ? Create a new field in the same model class of your status pipeline
is_closed = fields.Boolean('is closed', readonly=True)
@api.onchange('stage_id') # triggered fields
def on_change_stage_id(self):
if self.stage_id == 'closed':
self.is_closed = True
else:
self.is_closed = False
In the corresponding model view:
<odoo>
<record model="ir.ui.view" id="view_mymodel_form_extend">
<field name="name">event.view_mymodel_form_xsb</field>
<field name="model">mymodel.mymodel</field>
<field name="inherit_id" ref="originalmodel.view_originalmodel_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='name']" position="after">
<field name="is_closed" string="is closed" />
</xpath>
...which will display a checkbox in the in your html page.
You can now use the onchange method on this new input field, using jquery code in your custom file: src/user/my_module/static/src/js/disable_edit.js
odoo.define('my_module.disable_edit', function(require) {
"use strict";
$(document).ready(function() {
$("input[name='is_closed']").on('change', function() {
//if($("nav.o_main_navbar>a.o_menu_brand").text()=='Sale')
if (($(this).val == "True")
{
$(".button.o_form_button_edit").hide();
}
else
{
$(".button.o_form_button_edit").show();
}
});
});
});
Upvotes: 0