Skip to Content
Menu
This question has been flagged
7 Replies
13604 Rodiniai

Hello,

I need to replace a button function which is a window action in sale.order form view, for making the button visible to a certain group of users.How to achieve that.

This is the button function to be replaced:

<button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"        
    type="action" class="btn-primary"                      
    attrs="{'invisible': [('invoice_status', '!=', 'to invoice')]}"/> 

<button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"
    type="action" context="{'default_advance_payment_method': 'percentage'}"
    attrs="{'invisible': ['|',('invoice_status', '!=', 'no'), ('state', '!=', 'sale')]}"/>                  
Portretas
Atmesti
Best Answer

Hi,

You can use the following code to reach the button and update it:

<record id="view_order_form" model="ir.ui.view">
 <field name="name">sale.order.form</field>
  <field name="model">sale.order</field>
 <field name="inherit_id" ref="sale.view_order_form"/>
  <field name="arch" type="xml">
 <button name="%(sale.action_view_sale_advance_payment_inv)d" position="attributes">
 <attribute ... > ...</attribute>
 </button>
 </field>
 </record>


Hope this could helps ...

Portretas
Atmesti
Best Answer

I wanted to limit the "Create Invoice" Button to the Billing group and I found that the code from Ahmed and Pravitha only removed the first instance of the button but I used the following code to remove both:

<xpath expr="//button[@name='%(sale.action_view_sale_advance_payment_inv)d'][1]" position="attributes">
    <attribute name="groups">account.group_account_invoice</attribute>
</xpath>
<xpath expr="//button[@name='%(sale.action_view_sale_advance_payment_inv)d'][2]" position="attributes">
    <attribute name="groups">account.group_account_invoice</attribute>
</xpath>

Hope this helps anyone trying to do the same thing. :)

Portretas
Atmesti
Autorius Best Answer

The solution for the above query is:

inherit the sale_order view then add the below code

 <button name="%(sale.action_view_sale_advance_payment_inv)d" position="attributes">
    <attribute name="groups">sale.group_sale_manager,sale.group_sale_coo,sale.group_sale_ceo</attribute>
</button>
Portretas
Atmesti
Best Answer

Hi Pravitha,you can check using the position for that button for example:

<xpath expr="//form/sheet/....button[num]" position="replace"/>

where, num = 0,1,2..

Or else you can check the id for that windows action and you can user that id as name at your xpath. like, I have assumed the id as 456.But this Id may be change once you upgrade or migrate the module.

<xpath expr="//form/sheet/header/button[@name='456']" position="replace"/>

I hope it will help you.

If avove 2 methods will not work then, you can go with redefining the view to achive the required functionality.

Portretas
Atmesti
Autorius

Thankyou , but it didnt work

Then may be you need to redefine the entire from view and there you can provide the required groups to buttons.

Also please let me know if you get any alternate and best solution for this.Thanks

Autorius

@raaj Please see my updated answer

Related Posts Replies Rodiniai Veikla
3
bal. 21
8279
2
birž. 20
5569
1
spal. 19
4538
1
rugs. 18
106
1
rugs. 17
6860