This question has been flagged
2 Replies
3843 Views

I have create a new class using inherited by delegation of res.partner and created a new view for this class. I'm able to view my records in the new view, however when I try to create a child agent (child_ids is in res.partner) a view for res.partner is shown an a res.partner row is created with no custom.agent row. How can I force the view for a custom.agent?

Thanks Steve

class custom_agent(Model):
    _inherits = {
        'res.partner': 'partner_id',
    }    
    _name    = "custom.agent"
    _columns = {
        'commission_rate' : fields.float("Commission Rate"),
    }

Stripped down view

        <record id="view_custom_agent_form" model="ir.ui.view">
            <field name="name">custom.agent.form</field>
            <field name="model">custom.agent</field>
            <field eval="1" name="priority"/>
            <field name="arch" type="xml">
                <form string="Agent" version="7.0">
                <sheet>
                    <notebook colspan="4">
                        <page string="Contacts">
                            <field name="child_ids">
                            </field>
                        </page>
                    </notebook>
                </sheet>
                </form>
            </field>
        </record>       

Avatar
Discard
Author Best Answer

I found the solution, adding 'form_view_ref' : 'module.view_id', 'tree_view_ref' : 'model.view_id' to the context

https://doc.openerp.com/v5.0/developer/2_6_views_events/views/specify_view_to_use/#using-the-context

Avatar
Discard
Best Answer

Make an action (act_window) for your view. In that action you can define which view should be opened using the "view_id" field. I think that will help.

This is an example from the default CRM module:

 

        <!-- Stage Form view -->
        <record id="crm_lead_stage_act" model="ir.actions.act_window">
            <field name="name">Stages</field>
            <field name="res_model">crm.case.stage</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="crm.crm_case_stage_tree"/>   <-- this is the field to look for.
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to set a new stage in your lead/opportunity pipeline.
              </p><p>
                Stages will allow salespersons to easily track how a specific
                lead or opportunity is positioned in the sales cycle.
              </p>
            </field>
        </record>

Avatar
Discard