~camptocamp/account-invoicing/correct_payment_term_balance_mdh

« back to all changes in this revision

Viewing changes to account_invoice_partner/model/account_invoice.py

  • Committer: Guewen Baconnier
  • Author(s): Stefan Rijnhart
  • Date: 2014-02-28 13:23:48 UTC
  • mfrom: (18.6.5 7.0-add_account_invoice_partner)
  • Revision ID: guewen.baconnier@camptocamp.com-20140228132348-emyn9u764mlxx3s9
[ADD] account_invoice_partner

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    This module copyright (C) 2013 Therp BV (<http://therp.nl>).
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
from openerp.osv import orm
 
22
 
 
23
 
 
24
class AccountInvoice(orm.Model):
 
25
    _inherit = 'account.invoice'
 
26
 
 
27
    def onchange_partner_id(
 
28
            self, cr, uid, ids, type, partner_id,
 
29
            date_invoice=False, payment_term=False,
 
30
            partner_bank_id=False, company_id=False):
 
31
        """
 
32
        Replace the selected partner with the preferred invoice contact
 
33
        """
 
34
        partner_invoice_id = partner_id
 
35
        if partner_id:
 
36
            partner_invoice_id = self.pool.get('res.partner').address_get(
 
37
                cr, uid, [partner_id], adr_pref=['invoice'])['invoice']
 
38
        result = super(AccountInvoice, self).onchange_partner_id(
 
39
            cr, uid, ids, type, partner_invoice_id,
 
40
            date_invoice=date_invoice, payment_term=payment_term,
 
41
            partner_bank_id=partner_bank_id, company_id=company_id)
 
42
        if partner_invoice_id != partner_id:
 
43
            result['value']['partner_id'] = partner_invoice_id
 
44
        return result