コンテンツへスキップ
メニュー
この質問にフラグが付けられました
5 返信
98825 ビュー

i want my field int the form <when i create a new record> to have some text inside like

when we use placeholder but i want it to be a value not a place holder

how can i do that :

     i tried  <field  name="may_field" value="my_value"/>

                 <field name⁼"may_field" default="my_value"/>

but nothing

アバター
破棄
最善の回答

If you like to set default value in XML, for a particular page or view, than you can consider following option: In the "action" record that opens your Form View, you can add an entry in a "context" dictionary, like this:

"default_field_name" : "default value for field_name field",

so that key should be the field's name prefixed by "default_" and value should be whatever you like to be default value for that field in this form.

アバター
破棄
最善の回答

Try it another ways

Here is step for filling default  value in ODOO8/9.

  1. Go to Setting->Technical->Actions->User defined Defaults.

  2. Create a record  for your model.

  3. Inside name place your filed name(my_field).

  4. Inside model place your model name(my.model).

  5. inside Default value  place the default value (my_value) 



In python you can do it this way:

link_text = fields.Char(string='Link Text',default='Size Guide',required=True)
アバター
破棄

That was helpful. Thanks for the tip.

Thanks a lot @Prakesh

最善の回答

You have to do this in .py file

Some examples from  sale.py

Odoo 9:

  • date_order = fields.Datetime(string='Order Date', required=True, readonly=True, index=True, states={'draft': [('readonly',     False)], 'sent': [('readonly', False)]}, copy=False, default=fields.Datetime.now)

  • price_unit = fields.Float('Unit Price', required=True, digits=dp.get_precision('Product Price'), default=0.0)

Odoo 8:

'date_order': fields.datetime('Date', required=True, readonly=True, select=True, states={'draft': [('readonly', False)], 'sent':     [('readonly', False)]}, copy=False),

'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True,     states={'draft': [('readonly', False)]}),

_defaults = {

        'date_order': fields.datetime.now,

        'price_unit': 0.0,

}


アバター
破棄
著作者 最善の回答

i want to do this in code when i write my form structure

<form>

<group>

     <field name="field_name" value="defaul_value"/> // when i clique on create button my field will have the value defaul_value not empty text did understand me

</group>

アバター
破棄

link_text = fields.Char(string='Link Text',default='Size Guide',required=True)

関連投稿 返信 ビュー 活動
1
12月 24
5992
3
8月 24
6863
4
7月 24
41154
3
11月 22
4286
3
8月 22
4292