Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Odoo新API-重写旧API函数字段_Api_Overriding_Odoo_Openerp 8 - Fatal编程技术网

Odoo新API-重写旧API函数字段

Odoo新API-重写旧API函数字段,api,overriding,odoo,openerp-8,Api,Overriding,Odoo,Openerp 8,我试图重写旧的api函数字段,但没有成功。 此函数字段(display\u 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) contex

我试图重写旧的api函数字段,但没有成功。 此函数字段(
display\u 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)
我需要在这里更改的是在
显示\u名称\u存储\u触发器中
,使用新字段进行更新,如果使用这些字段,将触发此函数字段进行计算

如果我在源代码中执行此操作:

_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)
    }
什么也没发生<代码>显示\u名称当修改字段
父\u根\u id
为分支
时,不计算字段

我在文档中找不到如何使用新API覆盖旧函数字段。方法是什么?

尝试以下方法:

@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")
@api.one
@api.depends('parent\u id'、'is\u company'、'name')
def_显示_名称(自身):
对于自我伴侣:
partner.display\u name=
display\u name=fields.Char(compute=“\u display\u name”,string=“display name”)

我已经尝试过类似的方法。问题在于,即使在函数字段中添加
store=True
,它也不会在数据库中保存值。看起来它仍然使用旧的函数字段并忽略此实现。同样在您的示例中,您使用的是
api.one
,但要像使用多个api一样进行迭代。它不应该直接从
self
访问吗?因为它是一个记录集,在self上的迭代并不重要。是的,我忘了添加
store=True
。如果有机会,我会去看看。但是你能告诉我为什么要在新的api中实现吗?我重新实现了新的
name\u get
方法,如果设置了新字段(我实现了),该方法将更改
display\u name
is\u branch
parent\u root\u id
)。因此,如果合作伙伴是分支机构,并且拥有
父公司\u根公司\u id
(也称为主要合作伙伴),它将显示如下名称
主要公司/分支机构公司
。问题是,只有在写入时更改了
name
字段时才会更新,因为如果更改了新字段,则不会触发更新。因此,
display\u name
不会在应该更新的时候更新。如果我在
\u display\u name\u store\u triggers
中添加那些需要触发的字段,那么它就可以工作,但只有在source中这样做了。这很奇怪,你能在这里发布你的最新代码吗?我在问题中发布了我是如何修改源代码的。在我自己的模块中尝试同样的事情是行不通的(如果我从标准模块导入原始的res_partner类)。你可以看到我关于奥多问题的例子-