I would like to reset all the fields of one form with one instruction in Odoo v8. Is that possible? If not, I will have to reset each field one by one and that is not very clean code
我想在Odoo v8中用一条指令重置一个表单的所有字段。那可能吗?如果没有,我将不得不逐个重置每个字段,这不是很干净的代码
1 个解决方案
#1
3
You can assign to all fields (except MAGIC_COLUMNS) the values of the empty model.
您可以为所有字段(MAGIC_COLUMNS除外)分配空模型的值。
from openerp import models
# ... other code
@api.multi
def reset(self):
empty_obj = self.env[self._name]
for key, value in self._fields.iteritems():
if value.name not in models.MAGIC_COLUMNS:
setattr(self, key, getattr(empty_obj, key))
#1
3
You can assign to all fields (except MAGIC_COLUMNS) the values of the empty model.
您可以为所有字段(MAGIC_COLUMNS除外)分配空模型的值。
from openerp import models
# ... other code
@api.multi
def reset(self):
empty_obj = self.env[self._name]
for key, value in self._fields.iteritems():
if value.name not in models.MAGIC_COLUMNS:
setattr(self, key, getattr(empty_obj, key))