如何在 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/