简体   繁体   中英

Odoo10 : How can I automatically get the value for partner when customer number is given?

I am creating a module something like call log. In that i need to search the customer number and get the Partner information or have to link the partner automatically.

the following are the codes, somebody please help me.

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

Your onchange isn't correct. You don't need parameters and have to return a dictionary or nothing. The dictionary is only needed for field filtering changes and warning messages. Value changes like yours are made "directly":

@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

And try to stick to the Odoo Guidelines and change the field customer to customer_id .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM