16

我想readonly根据组和状态制作字段。就像我有两组:

  1. 经理组
  2. 用户组

如果我将User Group提供给任何用户,然后将Status更改为Done,则该字段将readonly用于该用户。

希望我能说清楚明白。谢谢。

4

4 回答 4

32

创建一个布尔类型的函数字段。如果登录的用户在用户组下并且状态已完成,则返回 true。然后在视图中,指定attrs="{'readonly':[('boolean_field_name','=',True)]}"

或者

首先创建您的表单视图。然后继承视图也指定组。例如,在销售订单表单视图中,当状态不在草稿或已发送时,我想让组用户的客户参考字段只读。

<record id="view_order_form_cust_ref_readonly" model="ir.ui.view">
    <field name="name">sale.order.form.readonly.cust</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="groups_id" eval="[(6, 0, [ref('base.group_user') ])]"/>
    <field name="arch" type="xml">
        <field name='client_order_ref'" position="attributes">
            <attribute name="attrs">{'readonly':[('state','not in',['draft','sent'])]}</attribute>
        </field>
    </field>
</record>
于 2013-10-02T18:22:11.273 回答
4

您可以在 OpenERP 中的字段级别应用访问规则,例如在 py 中

'name': fields.char('Name', size=128, required=True, select=True,
 read=['base.group_user'] ),

对于 xml 中的状态:

<field name="name " attrs="{'readonly': [('state','=','done')]}"/>
于 2013-09-20T11:17:30.823 回答
3

还有另一种甜蜜的方式来实现这一点。创建一个功能字段并在其中检查分配给该用户的组并且不存储该字段。在视图中使用 attrs 中的该字段。

假设在产品中,如果用户不属于产品修改组,您不希望任何用户修改内部参考。

创建一个组。

<data noupdate="1" >
    <record model="res.groups" id="group_product_modify">
        <field name="name">Product Modify</field>
        <field name="users" eval="[(4, ref('base.user_root'))]"/> 
    </record>
</data>     

Python 文件

class product_template(models.Model):
    _inherit="product.template"

    @api.one
    def set_access_for_product(self):
        self.able_to_modify_product = self.env['res.users'].has_group('product_extended_ecom_ept.group_product_modify')

    able_to_modify_product = fields.Boolean(compute=set_access_for_product, string='Is user able to modify product?')

XML文件应该看起来像,

<record model="ir.ui.view" id="product_template_update_internal_code_ept">
            <field name="name">Product Template extension</field>
            <field name="inherit_id" ref="product.product_template_only_form_view"/>
            <field name="model">product.template</field>
            <field name="priority" eval="50" />
            <field name="arch" type="xml">
                <field name="default_code" position="before">
                    <field name="able_to_modify_product" invisible="1" />
                </field>
                <field name="default_code" position="attributes">
                    <attribute name="attrs">{'readonly' : [('able_to_modify_product','=',False)]}</attribute>
                </field>
            </field>
        </record>   
于 2017-06-16T11:31:39.417 回答
0

如果您使用的是 Odoo Web 客户端(GUI)而不是代码,那么有一些非正统的方法可以做到这一点。只需复制包含与原始字段相同的值的字段副本(在Related Field下面给出原始字段名称Advanced Properties)并将其标记为只读。

在此处输入图像描述 然后,您可以向无法编辑该字段的用户隐藏原始字段,并使用组属性向可以编辑的用户隐藏复制字段。

在此处输入图像描述

于 2017-09-07T07:11:35.553 回答