16
16
The on_change attribute defines a method that is called when the content of a view field has changed.
18
18
.. i18n: This method takes at least arguments: cr, uid, ids, which are the three classical arguments and also the context dictionary. You can add parameters to the method. They must correspond to other fields defined in the view, and must also be defined in the XML with fields defined this way::
20
<field name="name_of_field" on_change="name_of_method(other_field'_1_', ..., other_field'_n_')"/>.. i18n:
22
.. i18n: <field name="name_of_field" on_change="name_of_method(other_field'_1_', ..., other_field'_n_')"/>
20
.. i18n: <field name="name_of_field" on_change="name_of_method(other_field'_1_', ..., other_field'_n_')"/>
22
This method takes at least arguments: cr, uid, ids, which are the three classical arguments and also the context dictionary. You can add parameters to the method. They must correspond to other fields defined in the view, and must also be defined in the XML with fields defined this way::
24
24
<field name="name_of_field" on_change="name_of_method(other_field'_1_', ..., other_field'_n_')"/>
28
28
The example below is from the sale order view.
30
30
.. i18n: You can use the 'context' keyword to access data in the context that can be used as params of the function.::
32
<field name="shop_id" select="1" on_change="onchange_shop_id(shop_id)"/>
34
.. i18n: <field name="shop_id" select="1" on_change="onchange_shop_id(shop_id)"/>
32
.. i18n: <field name="shop_id" select="1" on_change="onchange_shop_id(shop_id)"/>
34
You can use the 'context' keyword to access data in the context that can be used as params of the function.::
36
36
<field name="shop_id" select="1" on_change="onchange_shop_id(shop_id)"/>
38
38
.. i18n: .. code-block:: python
40
.. i18n: def onchange_shop_id(self, cr, uid, ids, shop_id):
45
.. i18n: shop=self.pool.get('sale.shop').browse(cr,uid,shop_id)
46
.. i18n: v['project_id']=shop.project_id.id
47
.. i18n: if shop.pricelist_id.id:
49
.. i18n: v['pricelist_id']=shop.pricelist_id.id
51
.. i18n: v['payment_default_id']=shop.payment_default_id.id
53
.. i18n: return {'value':v}
55
.. code-block:: python
40
57
def onchange_shop_id(self, cr, uid, ids, shop_id):
42
.. i18n: def onchange_shop_id(self, cr, uid, ids, shop_id):
50
62
shop=self.pool.get('sale.shop').browse(cr,uid,shop_id)
51
63
v['project_id']=shop.project_id.id
52
64
if shop.pricelist_id.id:
54
.. i18n: shop=self.pool.get('sale.shop').browse(cr,uid,shop_id)
55
.. i18n: v['project_id']=shop.project_id.id
56
.. i18n: if shop.pricelist_id.id:
58
66
v['pricelist_id']=shop.pricelist_id.id
60
.. i18n: v['pricelist_id']=shop.pricelist_id.id
62
68
v['payment_default_id']=shop.payment_default_id.id
64
.. i18n: v['payment_default_id']=shop.payment_default_id.id
66
return {'value':v}.. i18n:
68
.. i18n: return {'value':v}
72
72
.. i18n: When editing the shop_id form field, the onchange_shop_id method of the sale_order object is called and returns a dictionary where the 'value' key contains a dictionary of the new value to use in the 'project_id', 'pricelist_id' and 'payment_default_id' fields.
86
86
See the example below:
88
88
.. i18n: .. code-block:: xml
90
<record model="ir.actions.act_window" id="a">
91
<field name="name">account.account.tree1</field>
92
<field name="res_model">account.account</field>
93
<field name="view_type">tree</field>
94
<field name="view_mode">form,tree</field>
95
<field name="view_id" ref="v"/>
96
<field name="domain">[('code','=','0')]</field>
97
<field name="context">{'project_id': active_id}</field>
100
.. i18n: <record model="ir.actions.act_window" id="a">
101
.. i18n: <field name="name">account.account.tree1</field>
102
.. i18n: <field name="res_model">account.account</field>
103
.. i18n: <field name="view_type">tree</field>
104
.. i18n: <field name="view_mode">form,tree</field>
105
.. i18n: <field name="view_id" ref="v"/>
106
.. i18n: <field name="domain">[('code','=','0')]</field>
107
.. i18n: <field name="context">{'project_id': active_id}</field>
90
.. i18n: <record model="ir.actions.act_window" id="a">
91
.. i18n: <field name="name">account.account.tree1</field>
92
.. i18n: <field name="res_model">account.account</field>
93
.. i18n: <field name="view_type">tree</field>
94
.. i18n: <field name="view_mode">form,tree</field>
95
.. i18n: <field name="view_id" ref="v"/>
96
.. i18n: <field name="domain">[('code','=','0')]</field>
97
.. i18n: <field name="context">{'project_id': active_id}</field>
110
102
<record model="ir.actions.act_window" id="a">
111
103
<field name="name">account.account.tree1</field>
120
112
.. i18n: view_type::
122
tree = (tree with shortcuts at the left), form = (switchaable view form/list).. i18n:
124
.. i18n: tree = (tree with shortcuts at the left), form = (switchaable view form/list)
114
.. i18n: tree = (tree with shortcuts at the left), form = (switchaable view form/list)
126
118
tree = (tree with shortcuts at the left), form = (switchaable view form/list)
128
120
.. i18n: view_mode::
130
tree,form : sequences of the views when switching.. i18n:
132
.. i18n: tree,form : sequences of the views when switching
122
.. i18n: tree,form : sequences of the views when switching
134
126
tree,form : sequences of the views when switching
146
138
.. i18n: Get back the value by default for one or several fields.
148
Get back the value by default for one or several fields... i18n:
140
Get back the value by default for one or several fields.
150
.. i18n: **Signature:** def default_get(self, cr, uid, fields, form=None, reference=None)
152
.. i18n: **Parameters:**
142
.. i18n: **Signature:** def default_get(self, cr, uid, fields, form=None, reference=None)
144
.. i18n: **Parameters:**
154
146
**Signature:** def default_get(self, cr, uid, fields, form=None, reference=None)
158
.. i18n: * fields: the fields list which we want to recover the value by default.
159
.. i18n: * form (optional): TODO
160
.. i18n: * reference (optional): TODO
150
.. i18n: * fields: the fields list which we want to recover the value by default.
151
.. i18n: * form (optional): TODO
152
.. i18n: * reference (optional): TODO
162
154
* fields: the fields list which we want to recover the value by default.
163
155
* form (optional): TODO
164
* reference (optional): TODO.. i18n:
166
.. i18n: **Returns:** dictionary of the default values of the form {'field_name': value, ... }
168
**Returns:** dictionary of the default values of the form {'field_name': value, ... }.. i18n:
156
* reference (optional): TODO
158
.. i18n: **Returns:** dictionary of the default values of the form {'field_name': value, ... }
160
**Returns:** dictionary of the default values of the form {'field_name': value, ... }
170
162
.. i18n: Example::
174
.. i18n: self.pool.get('hr.analytic.timesheet').default_get(cr, uid, ['product_id','product_uom_id'])
164
.. i18n: self.pool.get('hr.analytic.timesheet').default_get(cr, uid, ['product_id','product_uom_id'])
176
168
self.pool.get('hr.analytic.timesheet').default_get(cr, uid, ['product_id','product_uom_id'])
188
180
Change the default value for one or several fields.
190
.. i18n: **Signature:** def default_set(self, cr, uid, field, value, for_user=False)
192
.. i18n: **Parameters:**
182
.. i18n: **Signature:** def default_set(self, cr, uid, field, value, for_user=False)
184
.. i18n: **Parameters:**
194
186
**Signature:** def default_set(self, cr, uid, field, value, for_user=False)
198
.. i18n: * field: the name of the field that we want to change the value by default.
199
.. i18n: * value: the value by default.
200
.. i18n: * for_user (optional): boolean that determines if the new default value must be available only for the current user or for all users.
190
.. i18n: * field: the name of the field that we want to change the value by default.
191
.. i18n: * value: the value by default.
192
.. i18n: * for_user (optional): boolean that determines if the new default value must be available only for the current user or for all users.
202
194
* field: the name of the field that we want to change the value by default.
203
195
* value: the value by default.
204
* for_user (optional): boolean that determines if the new default value must be available only for the current user or for all users... i18n:
206
.. i18n: **Returns:** True
208
**Returns:** True.. i18n:
196
* for_user (optional): boolean that determines if the new default value must be available only for the current user or for all users.
198
.. i18n: **Returns:** True
210
202
.. i18n: Example::