'Update the following fields when the partner is changed:
- Pricelist
- Payment term
- Invoice address
- Delivery address'

@api.multi
@api.onchange('partner_id')
def onchange_partner_id(self):

    if (not self.partner_id):
        self.update({'partner_invoice_id': False, 'partner_shipping_id': False, 'payment_term_id': False, 'fiscal_position_id': False})
        return
    addr = self.partner_id.address_get(['delivery', 'invoice'])
    values = {'pricelist_id': ((self.partner_id.property_product_pricelist and self.partner_id.property_product_pricelist.id) or False), 'payment_term_id': ((self.partner_id.property_payment_term_id and self.partner_id.property_payment_term_id.id) or False), 'partner_invoice_id': addr['invoice'], 'partner_shipping_id': addr['delivery']}
    if self.env.user.company_id.sale_note:
        values['note'] = self.with_context(lang=self.partner_id.lang).env.user.company_id.sale_note
    if self.partner_id.user_id:
        values['user_id'] = self.partner_id.user_id.id
    if self.partner_id.team_id:
        values['team_id'] = self.partner_id.team_id.id
    self.update(values)
