我正在创建一个模块,类似于调用日志。在这种情况下,我需要搜索客户编号并获取合作伙伴信息,或者必须自动链接合作伙伴。
下面是密码,有人请帮帮我。

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.",)

最佳答案

你的改变不对。你不需要参数,必须返回字典或什么都不需要。字典仅用于字段筛选更改和警告消息。像你这样的价值观变化是“直接”发生的:

@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

关于python - Odoo10:给出客户编号后,如何自动为合作伙伴获取值(value)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51740197/

10-09 01:12