跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • 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

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 再谈Odoo中的groups_id的应用

再谈Odoo中的groups_id的应用

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
4 帖子 3 发布者 4.4k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • K 离线
    K 离线
    KevinKong
    写于 最后由 编辑
    #1

    关于groups_id的作用,参考http://cn.openerp.cn/view_groups/,这里主要探讨的是自定义groups的创建和应用。

    一、权限的创建

      权限组的创建可以在设置中创建,也可以通过下面的方法进行创建,以下面方法创建的好处是可以在iew中通过groups_id来实现同一页面对不同权限用户显示的不同的view.

        groups的创建在模块下的security文件夹内。通常包含两个文件xml和csv。
        [img http://images.cnitblog.com/i/396990/201406/041116343951253.png /img]
        model="ir.module.category" 是创建一个应用程序目录,下面的user和manager则是属于该应用程序的两个group,category_id指定目录id(这里是新创建的目录id),implied_ids可以理解为继承的group.
        更新后的效果如下图:
        [img http://images.cnitblog.com/i/396990/201406/041117505672882.png /img]
        可以看到我们手动添加的这个group已经出现在application目录下。
        但此时,在groups中我们新建的test/user还没有任何的权限,menus和access rights都还是空,要设置这些权限就用到了上面提到的csv文件:
        [img http://images.cnitblog.com/i/396990/201406/041123101458615.png /img]
        具体这些内容的含义如下:  

    Fields => Value => Description

    id => access_testing_for_user => id must be unique.

    name => testing.for.user => name is given as we want.

    model_id:id => model_test_name => model_id:id is given like model_our_class_name.

    group_id:id => group_name_test_user => group_id:id is xml id of above we create like for User and Manager.

    perm_read => 1 for True and 0 for False for read record.

    perm_write => 1 for True and 0 for False for write record.

    perm_create => 1 for True and 0 for False for create record.

    perm_unlink => 1 for True and 0 for False for delete record.

      最后把xml和csv文件添加到__openerp__.py中。
    二、应用
          以仓库盘点表为例,想要实现的是仓库的盘点由仓库人员创建和确认,由我刚才创建的test组里的人来审核。下面是stock.inventory xml文件的内容:
         

    &lt;header&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;button name=&quot;action_confirm&quot; states=&quot;draft&quot; string=&quot;Confirm Inventory&quot; type=&quot;object&quot; class=&quot;oe_highlight&quot; groups=&quot;stock.group_stock_user&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;button name=&quot;action_done&quot; states=&quot;confirm&quot; string=&quot;Validate Inventory&quot; type=&quot;object&quot; class=&quot;oe_highlight&quot; groups=&quot;stock.group_stock_manager&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;button name=&quot;action_cancel_draft&quot; states=&quot;cancel&quot; string=&quot;Set to Draft&quot; type=&quot;object&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;button name=&quot;action_cancel_inventory&quot; states=&quot;draft,confirm,done&quot; string=&quot;Cancel Inventory&quot; type=&quot;object&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;state&quot; widget=&quot;statusbar&quot; statusbar_visible=&quot;draft,confirm&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/header&gt;
    


        这里的groups="stock.group_stock_manager",就是说,只有拥有仓库管理员权限的人才可以看到审核按钮,这里把它改成刚才我们创建的ID:module.group_rainsoft_test_user,这样就实现了,只有属于test组的用户才能看到审核按钮的效果。

    总结:通过设置settings中的groups可以对OpenERP的目录、action等进行控制,但对于view中的button等元素就需要依靠groups_id来进行精细控制了。

       

    1 条回复 最后回复
    0
    • R 离线
      R 离线
      rufeng1199
      写于 最后由 编辑
      #2

      好文,很详细

      1 条回复 最后回复
      0
      • W 离线
        W 离线
        winson97
        写于 最后由 编辑
        #3

        好文,记下了。

        1 条回复 最后回复
        0

        • 登录

        • 没有帐号? 注册

        • 登录或注册以进行搜索。
        • 第一个帖子
          最后一个帖子
        0
        • 版块
        • 标签
        • 热门
        • 用户
        • 群组