1
# -*- encoding: utf-8 -*-
3
##############################################################################
5
# Copyright (c) 2009 Zikzakmedia S.L. (http://www.zikzakmedia.com) All Rights Reserved.
6
# Copyright (c) 2008 Pablo Rocandio (salbet@gmail.com) All Rights Reserved.
7
# Copyright (c) 2006 ACYSOS S.L. (http://acysos.com) All Rights Reserved.
9
# WARNING: This program as such is intended to be used by professional
10
# programmers who take the whole responsability of assessing all potential
11
# consequences resulting from its eventual inadequacies and bugs
12
# End users who are looking for a ready-to-use solution with commercial
13
# garantees and support are strongly adviced to contract a Free Software
16
# This program is Free Software; you can redistribute it and/or
17
# modify it under the terms of the GNU General Public License
18
# as published by the Free Software Foundation; either version 2
19
# of the License, or (at your option) any later version.
21
# This program is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU General Public License for more details.
26
# You should have received a copy of the GNU General Public License
27
# along with this program; if not, write to the Free Software
28
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30
##############################################################################
33
from osv import fields, osv
35
class account_invoice(osv.osv):
36
_inherit='account.invoice'
38
'payment_type': fields.many2one('payment.type', 'Payment type'),
41
def onchange_partner_id2(self, cr, uid, ids, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False):
42
# Copy partner data to invoice, also the new field payment_type
43
result = self.onchange_partner_id(cr, uid, ids, type, partner_id, date_invoice, payment_term, partner_bank_id)
46
partner_line = self.pool.get('res.partner').browse(cr, uid, partner_id)
48
if type=='in_invoice' or type=='in_refund':
49
payment_type = partner_line.payment_type_supplier.id
51
payment_type = partner_line.payment_type_customer.id
53
result['value']['payment_type'] = payment_type
54
return self.onchange_payment_type(cr, uid, ids, payment_type, partner_id, result)
56
def onchange_payment_type(self, cr, uid, ids, payment_type, partner_id, result = {'value': {}}):
57
if payment_type and partner_id:
58
bank_types = self.pool.get('payment.type').browse(cr, uid, payment_type).suitable_bank_types
59
if bank_types: # If the payment type is related with a bank account
60
bank_types = [bt.code for bt in bank_types]
61
partner_bank_obj = self.pool.get('res.partner.bank')
62
args = [('partner_id', '=', partner_id), ('default_bank', '=', 1), ('state', 'in', bank_types)]
63
bank_account_id = partner_bank_obj.search(cr, uid, args)
65
result['value']['partner_bank'] = bank_account_id[0]
67
result['value']['partner_bank'] = False
70
def action_move_create(self, cr, uid, ids, *args):
71
ret = super(account_invoice, self).action_move_create(cr, uid, ids, *args)
73
for inv in self.browse(cr, uid, ids):
75
for move_line in inv.move_id.line_id:
76
if (move_line.account_id.type == 'receivable' or move_line.account_id.type == 'payable') and move_line.state != 'reconciled' and not move_line.reconcile_id.id:
77
move_line_ids.append(move_line.id)
78
if len(move_line_ids) and inv.partner_bank:
79
aml_obj = self.pool.get("account.move.line")
80
aml_obj.write(cr, uid, move_line_ids, {'partner_bank': inv.partner_bank.id})