我试图覆盖旧的api功能字段但没有成功。
这个函数字段(display_name
)带有辅助方法:
def _display_name_compute(self, cr, uid, ids, name, args, context=None):
context = dict(context or {})
context.pop('show_address', None)
context.pop('show_address_only', None)
context.pop('show_email', None)
return dict(self.name_get(cr, uid, ids, context=context))
_display_name = lambda self, *args, **kwargs: self._display_name_compute(*args, **kwargs)
_display_name_store_triggers = {
'res.partner': (lambda self,cr,uid,ids,context=None: self.search(cr, uid, [('id','child_of',ids)], context=dict(active_test=False)),
['parent_id', 'is_company', 'name'], 10)
}
'display_name': fields.function(_display_name, type='char', string='Name', store=_display_name_store_triggers, select=True)
我需要在此处更改,在display_name_store_triggers
中,使用新字段进行更新(如果使用),将触发此函数字段进行计算。
如果我在源代码中这样做:
_display_name_store_triggers = {
'res.partner': (lambda self,cr,uid,ids,context=None: self.search(cr, uid, [('id','child_of',ids)], context=dict(active_test=False)),
['parent_id', 'is_company', 'name', 'parent_root_id', 'is_branch'], 10)
}
然后它按我的需要工作。但我似乎无法继承触发器并覆盖我的模块。
如果我在我的模块上执行此操作:
from openerp.addons.base.res.res_partner import res_partner as res_partner_orig
_display_name_store_triggers = res_partner_orig._display_name_store_triggers
_display_name_store_triggers = {
'res.partner': (lambda self,cr,uid,ids,context=None: self.search(cr, uid, [('id','child_of',ids)], context=dict(active_test=False)),
['parent_id', 'is_company', 'name', 'parent_root_id', 'is_branch'], 10)
}
什么都没发生。 <{1}}字段不会在字段display_name
或parent_root_id
被修改时计算。
我在文档中找不到如何使用新API覆盖旧函数字段。方法是什么?
答案 0 :(得分:3)
请尝试以下操作:
@api.one
@api.depends('parent_id','is_company','name')
def _display_name(self):
for partner in self:
<<operation on context... you need to check yourself>>
<<you will have to check how name_get is called and based on
the return value set the value as shown below>>
partner.display_name = <<returned value from name_get>>
display_name = fields.Char(compute="_display_name",string="Display Name")