跳至内容
菜单
此问题已终结
7 回复
13631 查看

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')]}"/>                  
形象
丢弃
最佳答案

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 ...

形象
丢弃
最佳答案

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. :)

形象
丢弃
编写者 最佳答案

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>
形象
丢弃
最佳答案

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.

形象
丢弃
编写者

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

编写者

@raaj Please see my updated answer

相关帖文 回复 查看 活动
3
4月 21
8290
2
6月 20
5583
1
10月 19
4544
1
9月 18
106
1
9月 17
6879