Odoo View 常用技巧
隐藏Field
<field name="currency_id" invisible="True"/> <field name="currency_id" invisible="1"/>
在某种条件下隐藏
<field name="expense_description" attrs="{'invisible':[('expense_audit','!=','1')]}" />
隐藏label
<field name="description" widget="html" nolabel="True"/> <field name="description" widget="html" nolabel="1"/>
只读 readonly
<field name="budget_id" readonly="True"/>
条件 domain
<field name="product_id" domain="[('pro_type','=','rests')]"/>
设定值 eval
<field name="fill_date" eval="datetime.now()" readonly="True"/>
表单传值 context (以 default_
开始代表直接赋值过去)
<button class="oe_stat_button" name="%(budget_review_action)d" type="action" icon="fa-calendar-check-o" attrs="{'invisible':[('state','!=','check')]}" context="{'default_budget_id': id, 'default_contract_area': square, 'default_contract_price': total_price, 'default_start_date': start_date, 'default_end_date': end_date}" string="创建审核单"/>a
Widget
many2one widget (default)
- no_quick_create - remove the Create and edit... option.
- no_create_edit - remove the Create "search_value" option.
- no_create - no_quick_create and no_create_edit combined.
- no_open - in read mode: do not render as a link.
<field name="field_name" options="{'no_quick_create': True, 'no_create_edit' : True}"/>
many2many widget (default)
- no_create - remove the Create button.
<field name="field_name" options="{'no_create': True}"/>
many2many_tags widget
- no_quick_create - remove the Create and edit... option.
- no_create_edit - remove the Create "search_value" option.
- no_create - no_quick_create and no_create_edit together.
<field name="field_name" widget="many2many_tags" options="{'no_create_edit': True}"/>
one2many tree
- create - remove the Create button.
- edit - remove the Edit button.
- delete - remove the Delete button.
<field name="basic_incidentals" mode="tree" nolabel="1"> <tree create="false" edit="false" delete="false"> <field name="name"/> <field name="model"/> <field name="specifications"/> <field name="price" invisible="True"/> <field name="number" invisible="True"/> <field name="unit" invisible="True"/> <field name="total_price" invisible="True"/> <field name="remarks" invisible="True"/> </tree> </field>
Fields
生成一个动态的Selection,比如当前时间的前后5年!
import datetime year = fields.Selection(string=u'年度', selection=[(num, str(num)) for num in range((datetime.datetime.now().year - 5), (datetime.datetime.now().year + 5))])