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))])

 

posted @   *感悟人生*  阅读(53)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示