python - 在 Openerp 中使功能字段可编辑?

标签 python python-2.7 odoo openerp-7

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

当我们创建

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

这将以只读方式显示,我们无法编辑文本。

我们如何使这个字段具有可编辑性?

最佳答案

计算字段具有自动计算其在某些源数据上的值的功能。

可以添加反向操作,根据手动设置的值更新源数据,从而使其可编辑。

来自documentation :

to allow setting values on a computed field, use the inverse parameter. It is the name of a function reversing the computation and setting the relevant fields:

示例代码:

document = fields.Char(compute='_get_document', inverse='_set_document')

def _get_document(self):
    for record in self:
        with open(record.get_document_path) as f:
            record.document = f.read()
def _set_document(self):
    for record in self:
        if not record.document: continue
        with open(record.get_document_path()) as f:
            f.write(record.document)

关于python - 在 Openerp 中使功能字段可编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31267793/

相关文章:

python-2.7 - Odoo 如何将现有记录添加到 one2many 字段?

python - Odoo 8,获取错误 'datestyle' 设置

Python:Configparser - 转义换行符?

python - Pandas 中的 Rowwise

python - 在 Python 中实现 OpenID

python - IMDBPy 安装 mysqlclient 失败 - Python 2.7 Windows

Python不打印所有sys.argv

python - 我已经安装了 ffmpge 但收到以下 DownloadError : ERROR: ffprobe/avprobe and ffmpeg/avconv not found. 请安装一个

python - Shape Context Error 通过计算两个不同形状的距离

python-3.x - Python 2 到 Python 3 结构包问题