dynamic views (domain key of onchange return values) does not work

Bug #911676 reported by Cuong
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Odoo Web (MOVED TO GITHUB)
Fix Released
Medium
Unassigned

Bug Description

Hi,

I test dynamic view feature with 6.1 but not successfully. Within on_change callback function, I return domain to restrict domain of values of other fields. This is my simple test.
===
def onchange_something(cr, uid, ids, something, context=context):
   res = {}
   res['partner_id'] = [('id','=',1)]
   return {'domain': res}
===
With this onchange function, I still get full list of partners.

Thanks,

Revision history for this message
Vishal Parmar(Open ERP) (vpa-openerp) wrote :

Hello Cuong,

I am not getting exactly your point "dynamic view feature" so would you please elaborate more with related
example with related screenshot or video what you did ?

Thanks and waiting for your reply.

Changed in openerp-web:
status: New → Incomplete
Revision history for this message
Cuong (bhcuong2008) wrote :

Hi Vishal,

I'm now testing with 6.1 trunk. I test feature 'dynamic view' existed in 6.0. You could refer to this feature in the document Memento, file name "OpenERP_Technical_Memento_v0.6.4_A4.pdf", page 10, title 'Dynamic views'. Here is my specific example.

In Account module, it has one table, named 'account_invoice' to store many types of invoices, such as
===
        'type': fields.selection([
            ('out_invoice','Customer Invoice'),
            ('in_invoice','Supplier Invoice'),
            ('out_refund','Customer Refund'),
            ('in_refund','Supplier Refund'),
===

In Customer Invoices, partner_id must filter only customer type in res_partner table. With current implementation of OpenERP, type is passed into context in action definition as below
===
<record id="action_invoice_tree" model="ir.actions.act_window">
            <field name="name">Invoices</field>
            <field name="res_model">account.invoice</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form,calendar,graph</field>
            <field name="view_id" ref="invoice_tree"/>
=> <field name="context">{'type':'out_invoice'}</field>
            <field name="search_view_id" ref="view_account_invoice_filter"/>
        </record>
===

This is static filter, and we can change the type of partner in search view. We are implementing with different views, such as Customer Invoice, Supplier Invoice,...And we are setting 'type' statically and invisible on the form.

In many cases, we want to show all in just one form view, and 'type' field must be visible on the form for user selection. In account_invoice case, for example, user selects Customer Invoice (type = 'out_invoice'), then select partner_id. At this time, we must dynamically filter only partner of 'Customer' type. How do we do this?

OpenERP provides us dynamic view feature to do this job. In this case, I must write an onchange function and set it in field definition as below
===
<field name="type" on_change="onchange_type(type)"/>
===

In onchange_type(type) function, we will do the job as below,
===
def onchange_type(cr, uid, ids, type, context=context):
   res = {}
   if type == 'out_invoice' or type == 'out_refund':
      res['partner_id'] = [('customer','=',True)]
   elif type == 'in_invoice' or type == 'in_refund':
      res['partner_id'] = [('supplier','=',True)]

   return {'domain': res}
===

Currently, It can't do the job.

FYI: I write my own application. It takes a long time to explain many things. So I take Account Invoice as an example that we are familiar with.

Thanks,

Revision history for this message
Vishal Parmar(Open ERP) (vpa-openerp) wrote :

Hello Cuong,

Thanks for your reply.

You want dynamically filter only partner of 'Customer' type. Already domain in partner_id.

<field string="Customer" name="partner_id" on_change="onchange_partner_id(type,partner_id,date_invoice,payment_term, partner_bank_id,company_id)" groups="base.group_user" context="{'search_default_customer': 1}" options='{"quick_create": false}' domain="[('customer', '=', True)]"/>

So in customer invoice you can see only partner who has customer. If partner is both like Customer and Supplier then partner is show in both the invoice.

Thanks and waiting for your reply.

Revision history for this message
Cuong (bhcuong2008) wrote :

Hi Vishal,

There are many ways to do filter in OpenERP. Your above solution is also static filter. You know it's Customer type before. If we let the field 'type' visible on the form, and user can choose one of four values out_invoice, out_refund, in_invoice, in_refund. Only after user choose a value, then we know what it is, and we can apply filter only at that time.

Anyway, I want to know dynamic filter feature is implemented or not in 6.1. I've not tested this feature in 6.0 yet. But based on the document, I think it works properly. Could you test this feature in 6.1? Hope to see your result. It's a very nice feature.

Thanks,

summary: - dynamic view feature in 6.0
+ dynamic views (domain key of onchange return values) does not work
Changed in openerp-web:
status: Incomplete → Confirmed
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

> I want to know dynamic filter feature is implemented or not in 6.1.

It currently is not implemented, you can see the code where it might one day be at http://bazaar.launchpad.net/~openerp/openerp-web/trunk/view/head:/addons/web/static/src/js/view_form.js#L369

Changed in openerp-web:
importance: Undecided → Medium
status: Confirmed → In Progress
assignee: nobody → OpenERP R&D Web Team (openerp-dev-web)
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Support for dynamic domains (returned from onchange handlers) should be available in trunk as of revision <email address hidden>, please report any issue with it.

Changed in openerp-web:
assignee: OpenERP R&D Web Team (openerp-dev-web) → nobody
status: In Progress → Fix Released
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.