콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
15702 화면

Hello,

I am trying to hide "Edit" button in specific view by specific record state. Now I extended base.xml and can hide "Edit" button in specific view by view name like this:

<templates>

<t t-extend="FormView.buttons">

    <t t-jquery="button.oe_form_button_create" t-operation="replace">

        <t t-if="widget.fields_view.name == 'purchase.request.form'">

            <button t-if="widget.is_action_enabled('edit')"

                    type="button"

                    class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">

                Edit

            </button>

        </t>

</templates>

But is it possible to hide "Edit" button depend on specific record state in specific view. I tired to add <t t-if="widget.datarecord.state !== 'to_approve_first'"></t> to my extended xml:


<templates>

<t t-extend="FormView.buttons">

    <t t-jquery="button.oe_form_button_create" t-operation="replace">

        <t t-if="widget.fields_view.name == 'purchase.request.form'">

           <t t-if="widget.datarecord.state !== 'to_approve_first'">

            <button t-if="widget.is_action_enabled('edit')"

                    type="button"

                    class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">

                Edit

            </button>

          </t>

        </t>

</templates>

But nothing happens. Is it something wrong with my code or I can't do that by changing base.xml view?

How else can I solve this problem? By changing javascript code?

아바타
취소

I haven't tried it through xml , but through Jquery it's possible.

you want to hide that button for specific model only right?

베스트 답변

Try this way, hope this will work for you..

I have kept button hidden on sale.order form, when it's state=='sale'

odoo.define('custom_web_changes.custom_form_view', function (require) {
"use strict";

var core = require('web.core');
var FormView = require('web.FormView');

var _t = core._t;
var QWeb = core.qweb;

FormView.include({
	load_record: function(record) {
		this._super.apply(this, arguments);
		if (this.model=='sale.order'){
			if (this.get_fields_values().state=='sale'){
	        	this.$buttons.find('.o_form_button_edit').css({"display":"none"});
	        }
	        else{
	        	this.$buttons.find('.o_form_button_edit').css({"display":""});
	        }
		}
        
	}
	
});

});
아바타
취소
작성자

Hello, thank you for your help. I created mymodule.js file with your suggested code, just changed model name to mine - 'purchase.request' and state to - 'create_order'. Also created mymodule.xml file with code:

<?xml version="1.0" encoding="UTF-8"?>

<odoo>

<template id="assets_backend" inherit_id="web.assets_backend">

<xpath expr="." position="inside">

<script src="/purchase_request/static/src/js/mymodule.js" type="text/javascript" />

</xpath>

</template>

</odoo>

Added mymodule.js and mymodule.xml files to manifest but nothing happens. When the purchase model state is create_order "Edit" button still not hidden. What can be wrong? Also I want to ask about "custom_web_changes.custom_form_view". What does these means? Module name and what else? Thank you in advance.

hey hi,

custom_web_changes is module name and custom_form_view is unique id assigned to custom web module we are defining.

Once module is installed, please check whether your custom code is working or not,

please check browser console for that.

put some console.log() statements in load_record function defined in mymodule.js file.

in place of "custom_web_changes.custom_form_view", you can put "purchase_request.custom_form_view".

Please try installing module i have created, and let me know whether it's working or not. i hope that will be helpful for you.

get code from : https://github.com/chavanasmita/odoo-hide_edit_button.git

작성자

Thank you so much!!! I checked your github code. The problem was that I am using odoo v9 and "Edit" button class is oe_form_button_edit instead of o_form_button_edit. One more question is it a possibility with the same javascript hide button depend on user group role?

how to remove the bounce effect? when you click on the form. the edit button shows up again?

베스트 답변

Hi...

There is another solution to achieve that using java script. I've done this on odoo14 and works smoothly. Here is some code sample -

odoo.define('your_module_name.hide_form_view_edit_button', function (require) {
"use strict";

var
FormController = require('web.FormController');

FormController.include({
updateButtons: function () {
if (!this.$buttons) {
return;
}
console.log("-----------buttons")
if (this.footerToButtons) {
var $footer = this.renderer.$el && this.renderer.$('footer');
if
($footer && $footer.length) {
this.$buttons.empty().append($footer);
}
}
            //specify the model where you want to hide the edit
            //button based on field value
if (this.modelName === "your.model.name") { 
          
                console.log(this);
                // It will print a Json Object with all available
                //data regarding your current view
                //In my case I had to check the sate field and
                //I found the value of sate field in
                //this.renderer.state.data.state
            

if (this.renderer.state.data.state !== "draft") {
this.$buttons.find('.o_form_button_edit')
                            .toggleClass('o_hidden', true);
} else {
this.$buttons.find('.o_form_button_edit')
                            .toggleClass('o_hidden', false);
}
} else {
this.$buttons.find('.o_form_button_edit')
                        .toggleClass('o_hidden', false);
}
var edit_mode = (this.mode === 'edit');
this
.$buttons.find('.o_form_buttons_edit')
.toggleClass('o_hidden', !edit_mode);
this
.$buttons.find('.o_form_buttons_view')
.toggleClass('o_hidden', edit_mode);

},
});

Don't forget to add the js file to your template.xml file and the template.xml file to your manifest file.

Best of luck.


아바타
취소
베스트 답변

Hi, you can use this module

https://apps.odoo.com/apps/modules/10.0/hide_action_buttons/

It is for ODOO v 10, but you can see how it can work.

아바타
취소
베스트 답변

Hi Asmita Chavan, thanks for your answer.

I'm not expert in JS. I'm using Odoo version 14 and used your solution. I'm not sure what I'm doing wrong, the Edit button is not getting hidden.

Please let me know if we need to follow a different syntax for V14.

Thanks in advance!

아바타
취소
베스트 답변

the only problem with this, is that the form_view.js has a bouncing function for the edit button. So when you click on the form in the sale.order, the edit button displays...

any fix for that?

아바타
취소
관련 게시물 답글 화면 활동
0
10월 17
3197
2
7월 22
6876
1
3월 22
7387
5
9월 20
7744
1
10월 19
5852