# -*- coding: utf-8 -*-
# © 2014 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields, api


class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    payment_mode_id = fields.Many2one(
        comodel_name='payment.mode', string="Payment Mode",
        domain="[('type', '=', type)]")

    @api.multi
    def onchange_partner_id(
            self, type, partner_id, date_invoice=False,
            payment_term=False, partner_bank_id=False, company_id=False):
        res = super(AccountInvoice, self).onchange_partner_id(
            type, partner_id, date_invoice=date_invoice,
            payment_term=payment_term, partner_bank_id=partner_bank_id,
            company_id=company_id)
        if partner_id:
            partner = self.env['res.partner'].browse(partner_id)
            if type == 'in_invoice':
                res['value']['payment_mode_id'] = \
                    partner.supplier_payment_mode.id
            elif type == 'out_invoice':
                res['value'].update({
                    'payment_mode_id': partner.customer_payment_mode.id,
                    'partner_bank_id': partner.customer_payment_mode.bank_id.id
                })
        else:
            res['value']['payment_mode_id'] = False
        return res

@@ -1160,56 +1160,232 @@
 ue'%5D
-.update(%7B%0A                    'payment_mode_id':
+%5B'payment_mode_id'%5D = %5C%0A                    partner.customer_payment_mode.id%0A                # Do not change the default value of partner_bank_id if%0A                # partner.customer_payment_mode is False%0A                if
  par
@@ -1411,19 +1411,24 @@
 nt_mode.
+bank_
 id
-,
+:
 %0A       
@@ -1440,16 +1440,29 @@
         
+res%5B'value'%5D%5B
 'partner
@@ -1470,17 +1470,45 @@
 bank_id'
-:
+%5D = %5C%0A                       
  partner
@@ -1545,27 +1545,8 @@
 .id%0A
-                %7D)%0A
     

Invoice partner onchange: when partner.customer_payment_mode is False, don't change 'partner_bank_id'