0
votes

I have made some custom fields into my_purchase_custom.py class like as below.

  • Custom A
  • Custom B
  • Custom C
  • etc.

Now, there are two menu items in purchase.order model

  1. Requests for Quotations [menu_id=314]
  2. Purchase Orders [menu_id=315]

What I want to do is I want to put field Custom A into menu_id=314 and fields Custom B and Custom C into menu_id=315

Please help in this regards how to change my .xml file. I went through this link: https://www.odoo.com/fr_FR/forum/help-1/question/hide-menu-for-existing-group-18704 but couldnot understand properly. An example code snippet will be good idea

2

2 Answers

0
votes

You can assign an action to your menuitem and load the specific views that you want. For instance:

<record id="action_sale_order_view" model="ir.actions.act_window">
    <field name="name">Quotations</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">sale.order</field>            
    <field name="view_type">form</field>
    <field name="view_mode">tree,form,calendar,graph</field>
    <field name="domain">[('field_name','=',False)]</field>
    <field name="help" type="html">
      <p class="oe_view_nocontent_create">
        Click to define a new quotation.
      </p>
    </field>             
</record> 

<record id="view_act_object_tree" model="ir.actions.act_window.view">
    <field name="view_mode">tree</field>
    <field name="view_id" ref="sale.view_quotation_tree" />
    <field name="act_window_id" ref="action_sale_order_view" />
</record>

<record id="view_act_object_form" model="ir.actions.act_window.view">
    <field name="view_mode">form</field>
    <field name="view_id" ref="sale.view_order_form" />
    <field name="act_window_id" ref="action_sale_order_view" />         
</record>       

<record id="view_act_object_calendar" model="ir.actions.act_window.view">
    <field name="view_mode">calendar</field>
    <field name="view_id" ref="sale.view_sale_order_calendar" />
    <field name="act_window_id" ref="action_sale_order_view" />
</record>   

<record id="view_act_object_graph" model="ir.actions.act_window.view">
    <field name="view_mode">graph</field>
    <field name="view_id" ref="sale.view_sale_order_graph" />
    <field name="act_window_id" ref="action_sale_order_view" />
</record> 

<menuitem id="main_sale_order_view" 
          name="Quotations" 
          parent="base.menu_sales" 
          sequence="4" 
          action="action_sale_order_view" />

And you can show or hide the elements that you wish in your custom views. Is that what you are looking for?

0
votes

You can try to do the following way some things like this.

Add the Below code in your .py File from openerp.osv import fields, osv

class purchase_order(osv.osv):
    _inherit ="purchase.order"
    _columns = {
        'custom_a': fields.char('Custom A'),
        'custom_b': fields.char('Custom B'),
        'custom_b': fields.char('Custom C'),
    }

Add the Below code in your .xml File

<record model="ir.ui.view" id="r3x_inherit_purchase_ord">
    <field name="name">Purchase Order Inherit Form</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="arch" type="xml">

        <xpath expr="//field[@name='pricelist_id']" position="after">
            <field name="custom_a  attrs={'invisible':[('state','!=','draft')]}/>
            <field name="custom_b attrs={'invisible':[('state','=','draft')]} />
            <field name="custom_c attrs={'invisible':[('state','=','draft')]}/ />
        </xpath>

    </field>
</record>

please you can also set the path of the openerp.py file and add the entry in your .py file in init.py file.

check with the upgrade the module and restart the server and check the effect on purchase order form view.

I hope my answer may helpful for you :)