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))])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值