view definition 'parent'

Asked by Cuong

Hi,

In view definition of voucher_payment_receipt_form of module account_voucher, I wonder 'parent' in the code below, how openerp server can understand what parent means? I understand the meaning of this definition, but does not know how to implement this in other views. I tried but openerp reports
"NameError: name 'parent' is not defined"

===
domain="[
   ('account_id.type','in',('receivable','payable')),
   ('reconcile_id','=', False),
   ('partner_id','=',parent.partner_id)
]"
===

Thanks,

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
mjabirk (mjabirk) said :
#1

This is the view definition of one2many field(account.voucher.line) under account voucher. You can use "parent" option to get the variables in parent object(here account.voucher). Here the use is to filter the account.voucher.line according to the partner selected on account.voucher.
You got error because you may try to use the parent option in the main view instead of one2many object's view under main model.

Revision history for this message
Cuong (bhcuong2008) said :
#2

Hi mjabirk,

The code is below. Field move_line_id belongs to account_voucher_line.
===
<field name="line_cr_ids">
   <field name="move_line_id"
      context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
      on_change="onchange_move_line_id(move_line_id)"
      domain="[('account_id.type','in',('receivable','payable')),
         ('reconcile_id','=', False),
         ('partner_id','=',parent.partner_id)]"
   />
  <field name='account_id' domain="[('company_id','=', parent.company_id)]"/> => here is my additional code
===

As you see, field account_id also belongs to account_voucher_line, but can't use 'parent'.

Thanks,

Revision history for this message
Cuong (bhcuong2008) said :
#3

Hi mjabirk,

strange thing is that my code is understood when defining in account.voucher.receipt.form view but not understood in account.voucher.purchase.form view.

===
 <field name='account_id' domain="[('company_id','=', parent.company_id)]"/>
===

Do you have any suggestions?

Thanks,

Revision history for this message
Cuong (bhcuong2008) said :
#4

After doing many tests, I found the reason. If using widget="selection", it will not support 'parent' option.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#5

Hello,

Domain values that are written inside a view (or as a string value in the definition of a field) are meant to be evaluated at the client side. Therefore these may reference the fields values that are present in the form (but only those!), as well as the parent form if there is one. A domain in a view may look like [('partner_id', '=', parent.partner_id)], but it cannot following relationships that are known only on server-side, for example this will not work: [('address_id', '=', user_id.address_id)], because at the client-side 'user_id' is just an integer value, not a real relationship.
Note that in certain cases a domain will be specific in model as a Python list, which means that it should be evaluated server-side too (for example for some one2many fields)

Now there is a specific case for selection widget, because for a normal fields.selection, the available options are known in advance and directly provided by the server in the result of fields_view_get(). So when using a widget=selection for a many2one field, the server does a pre-computation of the possible values for the many2one, in order to provide that same list of options to the client.
So in that specific case, the server will evaluate the domain of the many2one on server-side, and this happens before the view is opened, so client-side field values or 'parent' values are not available.

This is currently the way it works, by design.

In the future we may provide a different mechanism to avoid this use of selection widgets for many2one fields, for example in v6.1 the new web client includes a new widget for many2one that can work using dynamic domains.

Can you help with this problem?

Provide an answer of your own, or ask Cuong for more information if necessary.

To post a message you must log in.