在Openerp中使功能字段可编辑? [英] Make a functional field editable in Openerp?

查看:55
本文介绍了在Openerp中使功能字段可编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Openerp中使功能字段可编辑?

How to make functional field editable in Openerp?

创建时

'capname': fields.function(
    _convert_capital, string='Display Name', type='char', store=True
),

这将显示为只读,我们将无法编辑文本.

This will be displayed has read-only and we can't able to edit the text.

我们如何使该字段可编辑?

How we make this field has editable?

推荐答案

您必须添加一个反函数以使该字段可编辑.此参数在OpenERP v7中称为fnct_inv.一个例子:

You must add a inverse function to make the field editable. This parameter is called fnct_inv in OpenERP v7. An example:

def _get_test(self, cr, uid, ids, name, args=None, context=None):
    result = dict.fromkeys(ids, False)
    for line in self.browse(cr, uid, ids, context=context):
        if line.test:
            result[line.id] = line.test
    return result       

def _set_test(self, cr, uid, id, field_name, field_value, args=None, context=None):
    obj = self.browse(cr, uid, id)
    for record in obj:
        if record.test != field_value:
            # The record already exists

            ...

            cr.execute(
                'UPDATE your_table '
                'SET test=%s '
                'WHERE id=%s', (field_value, id)
            )
        else:
            # It is a new record 
            # (or the value of the field was not modified)

    return True

_columns = {
    'test': fields.function(
        string='String for testing', 
        fnct=_get_test, 
        fnct_inv=_set_test,            
        type='char', 
        size=50, 
        store=True,
    ),
}

这篇关于在Openerp中使功能字段可编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆