Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Is it possible hide "Edit" button on form view by extending base.xml?

Naroči se

Get notified when there's activity on this post

This question has been flagged
viewseditpython2.7odooodoo-v9
5 Odgovori
16579 Prikazi
Avatar
Ugne Sinkeviciene

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?

1
Avatar
Opusti
Asmita Chavan

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

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

Avatar
Asmita Chavan
Best Answer

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":""});
	        }
		}
        
	}
	
});

});
4
Avatar
Opusti
Ugne Sinkeviciene
Avtor

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.

Asmita Chavan

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.

Asmita Chavan

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

Ugne Sinkeviciene
Avtor

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?

wizardz

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

Avatar
Rafiul
Best Answer

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.


0
Avatar
Opusti
Avatar
XFanis
Best Answer

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.

0
Avatar
Opusti
Avatar
Praveen Kumar
Best Answer

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!

0
Avatar
Opusti
Avatar
wizardz
Best Answer

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
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Filter many2one values
python2.7 odoo odoo-v9 odoo9 odoo9.0
Avatar
0
okt. 17
3694
How does line item display as kanban mode on mobile device Solved
views odoo
Avatar
Avatar
Avatar
2
jul. 22
7839
How to hide bugs and error message for users in odoo
python2.7 odoo-v9
Avatar
Avatar
1
mar. 22
8385
how to do for many2one domain filter?
python2.7 odoo
Avatar
5
sep. 20
8489
How to add a list of product in a view?
python2.7 odoo
Avatar
Avatar
1
okt. 19
6630
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now