Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    再谈Odoo中的groups_id的应用

    Odoo 开发与实施交流
    3
    4
    3953
    Loading More Posts
    • 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.
    • KevinKong
      KevinKong last edited by

      关于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 Reply Last reply Reply Quote 0
      • R
        rufeng1199 last edited by

        好文,很详细

        1 Reply Last reply Reply Quote 0
        • W
          winson97 last edited by

          好文,记下了。

          1 Reply Last reply Reply Quote 0
          • First post
            Last post