Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
10 Відповіді
15730 Переглядів

How can I hide the edit button in the purchase.order for a specific state?

Is there any exmaple ? 

Аватар
Відмінити
Найкраща відповідь

Hi wizards,

I've found a solution for this, and that's working with js files. Here is the example

odoo.define('module.extension_name', function (require) {
    var FormView = require('web.FormView');
    FormView.include({ load_record: function() { this._super.apply(this, arguments);
      if (this.model === 'your.model') {
         if (this.datarecord && (this.datarecord.state === 'state')) {
            this.$buttons.find('.o_form_button_edit').css({'display':'none'});
          }
         else { this.$buttons.find('.o_form_button_edit').css({'display':''}); }
       }
    });
});

You also have to include the file in assets:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
  <data>
    <template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
      <xpath expr="." position="inside">
        <script type="text/javascript" src="/path_to_js/static/src/js/file.js"/>
      </xpath>
    </template>
  </data>
</odoo>

I don't really like this solution as, if you wan't to do this for a lot of models, you'll have to work with a lot of if and elses, incrementing a lot the cyclomatic complexity, but it's the only way I've found to hide that button (you can also disable it with css).


Hope it helps!


Regards,

Benjamin

Аватар
Відмінити

how to include file in assets

Oh I forgot to include that detail!

Add the .xml file to your module manifest, in the data array, as any view you could've develop.

Найкраща відповідь


odoo.define('module.extension_name', function (require) {
    var FormView = require('web.FormView');
    FormView.include({ init: function() { this._super.apply(this, arguments);
      if (this.controllerParams.modelName === 'your.model') {
                this.rendererParams.activeActions.edit = false;                                                                                                                                                                                                                                                                                                                                                                                 
       }
    });
});
Аватар
Відмінити

its work

its hide full model edit but, i need to hide edit button to specific state please send a code to hide a edit button in purchase model for specific state......

Найкраща відповідь

It would be inheriting the form and adding edit='false' just like here:

<record model="ir.ui.view" id="view_stock_quant_form">

<field name="name">stock.quant.form</field>

<field name="model">stock.quant</field>

<field eval="10" name="priority"/>

<field name="arch" type="xml">

<form string="Inventory Valuation" create="false" edit="false">

<group>

<group>

<field name="product_id"/>

</group>

</form>

</field>

</record>


Аватар
Відмінити
Автор

and where is the filter for the state?

This is just an example, it will not work for you anyways. Do not expect other people to solve your problems and you just copy and paste. Read the tips here, search some more and solve your own damn problems. Thats the way to go. Cheers

Найкраща відповідь

Hi Wizardz,

You can do this by creating a button where you set invisible on the attributes. In these attributes you can use the 'state not in' in order to hide the button when it is not in a specific state (or the other way around, when it is). An example of both:

<button name="your_action" string="Your text" type="object" attrs="{'invisible': [('state','not in', ('purchase','done'))]}"/> <button name="your_other_action" string="Your other text" type="object" attrs="{'invisible': [('state', 'in', ('draft','sent','to approve'))]}"/>

Regards,

Yenthe

Аватар
Відмінити
Автор

but those are not doing the same as the edit?

how to remove the edit button from purchase order

Автор

with some user rights or you do it in the odoo js like this:

if (this.model === 'purchase.order') {

this is wrong answer

u didn't git the question

Related Posts Відповіді Переглядів Дія
1
трав. 17
3195
6
груд. 17
8846
5
вер. 20
12783
1
трав. 18
6812
1
бер. 15
5229