【问题标题】:OpenERP - Restrict the product module edit operation for Purchase\User based on status?OpenERP - 根据状态限制购买\用户的产品模块编辑操作?
【发布时间】:2014-07-17 03:43:06
【问题描述】:

我继承了 OpenERP Products 模块并添加了一个名为 stage 的新字段。 代码是,

_columns =  {
    'stage': fields.selection([
        ('pending', 'Pending'),
        ('confirmed', 'Confirmed'),
        ('cancel', 'Cancelled'),
    ], 'Status', select=True, track_visibility='onchange', help='Product Workflow Stages')

现在我需要一个条件,当产品处于confirmed 阶段时,应该阻止Purchase/User 的编辑操作。

def write(self, cr, uid, ids, datas, context = {} ):
        product_stage = datas['stage']
        if product_stage == 'confirmed':
            return super(purchase_order, self).write(cr, uid, ids, datas, context)
        else:
            raise osv.except_osv('Warning!',"You are not allowed to make changes! '%s'." % product_stage)

此条件仅适用于Purchase\User

我是 python 代码的新手。谁能帮我解决这个问题。

【问题讨论】:

  • 我找到了答案。我的代码是错误的。现在我知道如何编码了。
  • 如果你找到了解决方案,很高兴分享代码。您的问题已被投票 4 次,这可能意味着至少有四个其他用户对解决方案感兴趣 :-)

标签: python-2.7 openerp openerp-7


【解决方案1】:

以下代码对我来说工作正常。

def write(self, cr, uid, ids,  datas = {}, context = {} ):
    product_obj=self.pool.get('product.product')
    new_product_obj=product_obj.browse(cr, uid, ids[0], context=context)
    all_groups=self.pool.get('res.groups')
    edit_group = all_groups.browse(cr, uid, all_groups.search(cr,uid,[('name','=','User')])[3])
    groups_users=edit_group.users
    for groups_user in groups_users:
        if uid == groups_user.id:
            if 'confirmed' == new_product_obj.stage:
                raise osv.except_osv('Warning!',"You are not allowed to make any changes in confirmed products!")
            else:
                return super(purchase_order, self).write(cr, uid, ids, datas, context)
    return super(purchase_order, self).write(cr, uid, ids, datas, context)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    • 2021-03-07
    相关资源
    最近更新 更多