Opening form view from act_window broken

Bug #628767 reported by Daniel Watkins (credativ)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Invalid
Undecided
OpenERP Publisher's Warranty Team

Bug Description

With the XML below, I get a list view containing a single opportunity when I click on the 'Opportunity' button. If I click on the 'Form' button in the GTK client, then I get the form view for that single opportunity. All is well.

If, however, I change the sequence fields so that the form view comes before the list view and then click the 'Opportunity' button, I get an empty Opportunity form. If I click on the List button in the GTK client, I get the correct list, as above. I can then click the Form button, as above, and get to the expected form view.

I would expect to be able to load the form view straight off, without the indirection via the list view.

<?xml version="1.0"?>
<openerp>
    <data>

        <act_window
            id="action_opportunities_from_quotes"
            name="Opportunity"
            res_model="crm.lead"
            src_model="sale.order"
            view_mode="form"
            domain="[('id','=', opportunity_id)]"
            view_type="form" />

        <record id="action_opportunities_from_quotes_view1" model="ir.actions.act_window.view">
            <field name="act_window_id" ref="action_opportunities_from_quotes" />
            <field eval="0" name="multi" />
            <field eval="&quot;&quot;&quot;form&quot;&quot;&quot;" name="view_mode" />
            <field name="view_id" ref="crm.crm_case_form_view_oppor" />
            <field eval="1" name="sequence" />
        </record>

        <record id="action_opportunities_from_quotes_view2" model="ir.actions.act_window.view">
            <field name="act_window_id" ref="action_opportunities_from_quotes" />
            <field eval="0" name="multi" />
            <field eval="&quot;&quot;&quot;tree&quot;&quot;&quot;" name="view_mode" />
            <field name="view_id" ref="crm.crm_case_tree_view_oppor" />
            <field eval="0" name="sequence" />
        </record>
    </data>
</openerp>

Tags: maintenance
Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

Bug #489183 and Bug #601480 might be relevant, but neither seem to describe exactly the problem I am facing.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Daniel,

You should try view_mode="form,tree" or view_mode="tree,form" in order to achieve your aim.

Let me know if it still doesn't work.

Thank you.

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

Hi Jay,

Thanks for looking at this. I have updated XML as below and am still getting exactly the same issue.

Dan

<?xml version="1.0"?>
<openerp>
    <data>
        <act_window
            id="action_opportunities_from_quotes"
            name="Opportunity"
            res_model="crm.lead"
            src_model="sale.order"
            view_mode="form, tree"
            domain="[('id','=', opportunity_id)]"
            view_type="form" />

        <record id="action_opportunities_from_quotes_view1" model="ir.actions.act_window.view">
            <field name="act_window_id" ref="action_opportunities_from_quotes" />
            <field eval="0" name="multi" />
            <field eval="&quot;&quot;&quot;form&quot;&quot;&quot;" name="view_mode" />
            <field name="view_id" ref="crm.crm_case_form_view_oppor" />
        </record>

        <record id="action_opportunities_from_quotes_view2" model="ir.actions.act_window.view">
            <field name="act_window_id" ref="action_opportunities_from_quotes" />
            <field eval="0" name="multi" />
            <field eval="&quot;&quot;&quot;tree&quot;&quot;&quot;" name="view_mode" />
            <field name="view_id" ref="crm.crm_case_tree_view_oppor" />
        </record>
    </data>
</openerp>

Changed in openobject-server:
status: Invalid → New
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Doesn't look like a bug, we can communicate here.
Thanks.

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Olivier Macchioni (olivier-macchioni) wrote :

I would like to understand why this doesn't qualify as a bug. To me it's at least a severe limitation. As far as I know, it's just impossible to open a new tab in the GTK client which would be in "form" mode and which would be on a specific record ID using act_window.

The only workaround I've found is for the web client, and is quite ugly: http://www.openerp.com/forum/viewtopic.php?f=11&t=21250&view=previous

Changed in openobject-server:
assignee: nobody → OpenERP Publisher's Warranty Team (openerp-opw)
status: Invalid → New
tags: added: maintenance
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :
Download full text (4.2 KiB)

Hello,
This bug is invalid because what you want to achieve is perfectly doable. The part you are missing is the fact that the dynamic definition of an ir.actions.act_window may contain an extra 'res_id' key, which combined with view_mode="form" will directly open the form view of the given record. As of v7.0 the res_id column is explicitly defined on ir.actions.act_window. Before v7.0 this key was only supported in dynamic action definitions, such as those returned by a method call.

Based on the above, and assuming you have a many2one field 'opportunity_id' on the sale.order model, there are many different ways to directly open the form view of the related opportunity from the sale.order. Here are a few options:

1. The simplest way does not even use an action and does not need the 'res_id' trick at all. You simply add the opportunity_id field in the form view of sale.order, and make sure to pass a special context to choose the "Opportunity" form view instead of the default "Lead" form. This is as simple as adding the following field to the sale.order form view:
  <field name="opportunity_id" context="{'form_view_ref': 'crm.crm_case_form_view_oppor'}"/>
Users can now open the form view of the opportunity from the sale.order directly.

2. As the 'res_id' value of the action will be dynamic, we can't simply create a static 'act_window' action in the database. But we can instead add a new method to sale.order that will return the appropriate action. An example method would be:
    def open_opportunity(self, cr, uid, ids, context=None):
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'crm.lead',
            'res_id': self.browse(cr, uid, ids[0], context).opportunity_id.id,
            'view_mode': 'form',
            'view_type': 'form',
            'view_id': self.pool.get('ir.model.data').get_object(cr, uid, 'crm','crm_case_form_view_oppor').id,
        }
And can be executed by adding a button in the form view of the sale.order, as follows:
   <button type="object" name="open_opportunity" string="Open Opportunity"/>
This achieves the same result.

3. If you need the action to be present in the sidebar, you can't directly an <act_window> that will call a python method, so you will need to go through an ir.actions.server that will accomplish the same thing. You can make the server action call the 'open_opportunity' method from example 2 (or move the code of the method in the server action altogether).
The XML definition for the server action and the 'ir.values' entry to bind it to the sidebar could look like this:

        <!-- Define the server action that returns the special action definition -->
        <record model="ir.actions.server" id="open_related_opportunity">
            <field name="type">ir.actions.server</field>
            <field name="name">Related Opportunity</field>
            <field name="state">code</field>
            <field name="model_id" ref="sale.model_sale_order"/>
            <field name="code">
# Set the value of the `action` variable to return a custom action to
# be executed by the client. 'object' is initialized based on the 'active_id' in...

Read more...

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Eyes Fitt (eyesfitt) wrote :

Techloyce is a top Odoo partner (https://www.techloyce.com/odoo-partner/), offering fully customized solutions. Odoo is a set of open source software that can be customized to fit the needs of any business. It can handle anything from ERP Consultant, e-commerce, accounting, inventory, point of sale, and project management. It's a one-of-a-kind CRM that's fully integrated and simple to use.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.