From 5ea034d92a0a5d2db76492c6a4f9eea8b116333f Mon Sep 17 00:00:00 2001
From: ced <>
Date: Mon, 26 Nov 2007 15:46:33 +0000
Subject: [PATCH] Add partner bank on invoice
- new field partner_bank on invoice
- use the partner bank for the payment
- don't fill the payment line wizard by default
bzr revid: ced-57fdec04527d5105ca707e17514424752dc14241
---
addons/account/account_invoice_view.xml | 5 ++-
addons/account/invoice.py | 5 +++
addons/account_payment/account_move_line.py | 40 ++++++++-----------
.../wizard/wizard_payment_order.py | 2 +-
4 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml
index 38db475eb11..7156d2e01ec 100644
--- a/addons/account/account_invoice_view.xml
+++ b/addons/account/account_invoice_view.xml
@@ -138,7 +138,9 @@
-
+
+
diff --git a/addons/account/invoice.py b/addons/account/invoice.py
index d869ea38ea8..1b0b5b19195 100644
--- a/addons/account/invoice.py
+++ b/addons/account/invoice.py
@@ -149,6 +149,8 @@ class account_invoice(osv.osv):
'company_id': fields.many2one('res.company', 'Company', required=True),
'check_total': fields.float('Total', digits=(16,2), states={'open':[('readonly',True)],'close':[('readonly',True)]}),
'reconciled': fields.function(_reconciled, method=True, string='Reconciled', type='boolean'),
+ 'partner_bank': fields.many2one('res.partner.bank', 'Bank Account',
+ help='The partner bank account to pay\nKeep empty to use the default'),
}
_defaults = {
'type': _get_type,
@@ -238,6 +240,9 @@ class account_invoice(osv.osv):
def onchange_invoice_line(self, cr, uid, ids, lines):
return {}
+ def onchange_partner_bank(self, cursor, user, ids, partner_bank_id):
+ return {'value': {}}
+
# go from canceled state to draft state
def action_cancel_draft(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state':'draft'})
diff --git a/addons/account_payment/account_move_line.py b/addons/account_payment/account_move_line.py
index 2e5d9f0ef9c..f7578385d2b 100644
--- a/addons/account_payment/account_move_line.py
+++ b/addons/account_payment/account_move_line.py
@@ -81,7 +81,7 @@ class account_move_line(osv.osv):
return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))]
- def line2bank(self,cr,uid,ids,payment_type= 'manual',context=None):
+ def line2bank(self, cr, uid, ids, payment_type='manual', context=None):
"""
Try to return for each account move line a corresponding bank
account according to the payment type. This work using one of
@@ -89,28 +89,22 @@ class account_move_line(osv.osv):
associated to the line.
Return the first suitable bank for the corresponding partner.
"""
- if not ids: return {}
- bank_type= self.pool.get('payment.mode').suitable_bank_types(cr,uid,payment_type,context=context)
- cr.execute('''select DISTINCT l.id,b.id,b.state
- from account_invoice i
- join account_move m on (i.move_id = m.id)
- join account_move_line l on (m.id = l.move_id)
- join res_partner p on (p.id = i.partner_id)
- join res_partner_bank b on (p.id = b.partner_id)
- where l.id in (%s)
- ''' % ",".join(map(str,ids)) )
-
- r= cr.fetchall()
- type_ok=[]
- line2bank={}.fromkeys(ids)
- for line,bank,t in r:
- if not line2bank[line]:
- line2bank[line]= bank
- if t in bank_type:
- type_ok.append(line)
- elif (line not in type_ok) and (t in bank_type) :
- line2bank[line]= bank
- type_ok.append(line)
+ payment_mode_obj = self.pool.get('payment.mode')
+ line2bank = {}
+ if not ids:
+ return {}
+ bank_type = payment_mode_obj.suitable_bank_types(cr, uid, payment_type,
+ context=context)
+ for line in self.browse(cr, uid, ids, context=context):
+ if line.invoice and line.invoice.partner_bank:
+ line2bank[line.id] = line.invoice.partner_bank.id
+ elif line.partner:
+ for bank in line.partner.bank_ids:
+ if bank.state in bank_type:
+ line2bank[line.id] = bank.id
+ break
+ if line.id not in line2bank and line.partner.bank_ids:
+ line2bank[line.id] = line.partner.bank_ids[0].id
return line2bank
_columns = {
diff --git a/addons/account_payment/wizard/wizard_payment_order.py b/addons/account_payment/wizard/wizard_payment_order.py
index bf4388ec36b..1e65308817c 100644
--- a/addons/account_payment/wizard/wizard_payment_order.py
+++ b/addons/account_payment/wizard/wizard_payment_order.py
@@ -52,7 +52,7 @@ def search_entries(self, cr, uid, data, context):
''' % (','.join([str(x) for x in line_ids]))
- return {'entries': line_ids}
+ return {}
def create_payment(self, cr, uid, data, context):
line_ids= data['form']['entries'][0][2]