Odoo10:给出客户编号后,如何自动为合作伙伴获取价值?

时间:2018-08-08 06:48:35

标签: python postgresql odoo odoo-10

我正在创建一个类似于呼叫日志的模块。为此,我需要搜索客户编号并获取合作伙伴信息,或者必须自动链接​​合作伙伴。

以下是代码,请有人帮助我。

class model_call(models.Model):
    _inherit = 'res.partner'
    _name = 'model.call'
    _description = 'call logs'

    """ *************** Base Fields ******************* """
    name = fields.Char(string='Topic')
    customer_number = fields.Char(string='Customer Number', track_visiility='onchange', onchange='get_partner(customer_number)')
#-------------------------------------------------
#       apis
#-------------------------------------------------

    @api.onchange('customer_number')
    def get_partner(self, customer_number):
         if customer_number:
            customer = self.env['res.partner'].search([('customer_number', '=', record.phone)])

            return customer
#------------------------------------------------------

    customer = fields.Many2one('res.partner', string='Customer', track_visibility='onchange',index=True, help="Linked partner (optional). Usually created when converting the lead.",)

1 个答案:

答案 0 :(得分:0)

您的变更不正确。您不需要参数,而必须返回字典或什么都不返回。该字典仅用于字段过滤更改和警告消息。像您这样的价值变化是“直接”进行的:

@api.onchange('customer_number')
def get_partner(self):
     if self.customer_number:
        customer = self.env['res.partner'].search(
            [('customer_number', '=', self.phone)])  # shouldn't it be self.customer_number?
        self.customer = customer

并尝试坚持使用Odoo Guidelines,并将字段customer更改为customer_id