Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 开发与实施交流
  4. OpenERP 7 默认值详解

OpenERP 7 默认值详解

Scheduled Pinned Locked Moved Odoo 开发与实施交流
5 Posts 2 Posters 8.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JoshuaJ Offline
    JoshuaJ Offline
    Joshua
    管理员
    wrote on last edited by
    #1

    来自先安博客: http://cn.openerp.cn/openerp-7-set-dafault/ ‎

    [size=12pt]1.激活开发者模式[/size]

    在OpenERP 7目前的版本中,设置默认值必须进入开发者模式。

    [size=12pt]2.设置默认值
    [/size]
    然后在你要配置默认值的表单里面,先填入对应的数据然后,在表单左上方的调试视图里面选择设置默认值。
    [attachimg=1]

    默认值的配置界面很直观。
    [attachimg=2]


    默认:就是你要设置的默认值,下拉列表里面已经根据你当前表单显示出相应的字段和值,你只需要选取
    条件:  就是你的默认值生效的条件。例如下图意思就是,当产品类别是服务的,产品类型默认值为服务。(这里涉及到一个 https://bugs.launchpad.net/openerp-web/+bug/1112232 不过在最新的版本里面已经修复好了)。
    [attachimg=3]

    怎么样的字段才能成为默认值的条件呢?字段定义里面的 change_default属性为True。

    <br />&#039;categ_id&#039;: fields.many2one(&#039;product.category&#039;,&#039;Category&#039;,<br />required=True, change_default=True, domain=&quot;[(&#039;type&#039;,&#039;=&#039;,&#039;normal&#039;)]&quot; ,<br />help=&quot;Select category for the current product&quot;),<br />
    


    仅用于你个人/所有用户:此默认值是只对当前用户生效还是对于所有用户生效。


    [size=12pt]3.删除默认值[/size]

    到 设置->技术->动作->用户设定默认值 就能看到目前已经设定的默认值。

    [size=12pt]4.更多默认值[/size]

    OpenERP的默认值还可以通过代码的方式来实现。例如下图就是产品模块的默认值

    <br /><br />_defaults = {<br /> &#039;company_id&#039;: lambda s,cr,uid,c: s.pool.get(&#039;res.company&#039;)._company_default_get(cr, uid, &#039;product.template&#039;, context=c),<br /> &#039;list_price&#039;: 1,<br /> &#039;cost_method&#039;: &#039;standard&#039;,<br /> &#039;standard_price&#039;: 0.0,<br /> &#039;sale_ok&#039;: 1,<br /> &#039;produce_delay&#039;: 1,<br /> &#039;uom_id&#039;: _get_uom_id,<br /> &#039;uom_po_id&#039;: _get_uom_id,<br /> &#039;uos_coeff&#039; : 1.0,<br /> &#039;mes_type&#039; : &#039;fixed&#039;,<br /> &#039;categ_id&#039; : _default_category,<br /> &#039;type&#039; : &#039;consu&#039;,<br /> }<br />
    



    问题:如果我既配置了_defaults 又在界面上配置了默认值那么怎么办?
    答案:界面的优先级大于代码里面的。

    问题:如果在界面上配置了多次默认值,那么会取哪个默认值呢?
    答案:取最新的。

    【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wjfonhand
      wrote on last edited by
      #2

      如果我要设两个字段的默认值呢?设两次?会不会把之前的覆盖掉?

      GoodERP -- Odoo China fork

      1 Reply Last reply
      0
      • JoshuaJ Offline
        JoshuaJ Offline
        Joshua
        管理员
        wrote on last edited by
        #3

        对的,设置2次,不会覆盖的。。

        【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wjfonhand
          wrote on last edited by
          #4

          谢谢楼上解疑

          GoodERP -- Odoo China fork

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Tags
          • Popular
          • Users
          • Groups