问题
this question already asked by someone, this in an example question
How to hide the edit button form only when invoice' state is 'paid' Odoo v8?
but i dont get true answer, somebody can help me, i really need to hide or disabled this button.
For your information im using odoo v.10
Thanks in advance
回答1:
The only way to this is by Javascript
you need to add this behavior to your form view
build a custom addon and just add this javascript file to your backend assets template
//file: static/src/js/disable_edit_for_paid_invoice.js
openerp.your_addon_name = function(instance, local) {
var instance = openerp;
var FormView = instance.web.FormView;
// override load_record
FormView.include({
load_record: function(record) {
// disable only for cancel and paid account.invoice
if (record){
if (this.model == 'account.invoice' & _.contains(['paid', 'cancel'], record.state)){
$('button.oe_form_button_edit').hide()
}else {
$('button.oe_form_button_edit').show()
}
}
// call super
return this._super(record);
}
});
}
Add this to backend asset template
<template id="assets_backend" name="disable edit paid invoice assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/your_addon_name/static/src/js/disable_edit_for_paid_invoice.js"></script>
</xpath>
</template>
Don't forget to replace your_addon_name
by the real addon name that you create
.
来源:https://stackoverflow.com/questions/46663748/odoo-disabled-edit-button-depending-on-state