*bugfixed the suitable_bank_type method

*improvements: 
	- onchange move line now fills the payment date smartly
	- onchange partner now fills the bank account taking in consideration the allowed bank types

bzr revid: qdp@tinyerp.com-20080829152006-uty7fk90syo16he8
This commit is contained in:
qdp 2008-08-29 17:20:06 +02:00
parent 6edbff86a0
commit 7670578649
2 changed files with 28 additions and 24 deletions

View File

@ -84,7 +84,7 @@ class account_move_line(osv.osv):
return [('id','=','0')] return [('id','=','0')]
return [('id','in',map(lambda x:x[0], res))] 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=None, context=None):
""" """
Try to return for each account move line a corresponding bank Try to return for each account move line a corresponding bank
account according to the payment type. This work using one of account according to the payment type. This work using one of

View File

@ -62,16 +62,20 @@ class payment_mode(osv.osv):
'type': fields.many2one('payment.type','Payment type',required=True), 'type': fields.many2one('payment.type','Payment type',required=True),
} }
def suitable_bank_types(self,cr,uid,payment_code= 'manual',context={}): def suitable_bank_types(self,cr,uid,payment_code=None,context={}):
"""Return the codes of the bank type that are suitable """Return the codes of the bank type that are suitable
for the given payment type code""" for the given payment type code"""
if not payment_code:
return []
cr.execute(""" select t.code cr.execute(""" select t.code
from res_partner_bank_type t from res_partner_bank_type t
join bank_type_payment_type_rel r on (r.bank_type_id = t.id) join bank_type_payment_type_rel r on (r.bank_type_id = t.id)
join payment_type pt on (r.pay_type_id = pt.id) join payment_type pt on (r.pay_type_id = pt.id)
where pt.code = %s """, [payment_code]) join payment_mode pm on (pm.type = pt.id)
where pm.id = %s """, [payment_code])
return [x[0] for x in cr.fetchall()] return [x[0] for x in cr.fetchall()]
payment_mode() payment_mode()
@ -232,8 +236,6 @@ class payment_line(osv.osv):
where pl.id in (%s)"""% where pl.id in (%s)"""%
(self.translate(name), ','.join(map(str,ids))) ) (self.translate(name), ','.join(map(str,ids))) )
res = dict(cr.fetchall()) res = dict(cr.fetchall())
print "res: ", res
print "name ", name
if name == 'partner_id': if name == 'partner_id':
partner_name = {} partner_name = {}
@ -354,9 +356,7 @@ class payment_line(osv.osv):
res={} res={}
for id in self.browse(cr, uid, ids): for id in self.browse(cr, uid, ids):
res[id.id] = "" res[id.id] = ""
print "test"
if id.move_line_id: if id.move_line_id:
print "blablabl"
res[id.id] = "pas de invoice" res[id.id] = "pas de invoice"
if id.move_line_id.invoice: if id.move_line_id.invoice:
res[id.id] = str(id.move_line_id.invoice.number) res[id.id] = str(id.move_line_id.invoice.number)
@ -387,7 +387,7 @@ class payment_line(osv.osv):
'communication': fields.char('Communication', size=64, required=True), 'communication': fields.char('Communication', size=64, required=True),
'communication2': fields.char('Communication 2', size=64), 'communication2': fields.char('Communication 2', size=64),
'move_line_id': fields.many2one('account.move.line','Entry line', domain=[('reconcile_id','=', False), ('account_id.type', '=','payable')]), 'move_line_id': fields.many2one('account.move.line','Entry line', domain=[('reconcile_id','=', False), ('account_id.type', '=','payable')]),
'amount_currency': fields.float('Amount', digits=(16,2), 'amount_currency': fields.float('Amount in Partner Currency', digits=(16,2),
required=True, help='Payment amount in the partner currency'), required=True, help='Payment amount in the partner currency'),
# 'to_pay_currency': fields.function(_to_pay_currency, string='To Pay', # 'to_pay_currency': fields.function(_to_pay_currency, string='To Pay',
# method=True, type='float', # method=True, type='float',
@ -400,7 +400,7 @@ class payment_line(osv.osv):
'order_id': fields.many2one('payment.order', 'Order', required=True, 'order_id': fields.many2one('payment.order', 'Order', required=True,
ondelete='cascade', select=True), ondelete='cascade', select=True),
'partner_id': fields.many2one('res.partner', string="Partner",required=True), 'partner_id': fields.many2one('res.partner', string="Partner",required=True),
'amount': fields.function(_amount, string='Amount', 'amount': fields.function(_amount, string='Amount in Company Currency',
method=True, type='float', method=True, type='float',
help='Payment amount in the company currency'), help='Payment amount in the company currency'),
# 'to_pay': fields.function(select_by_name, string="To Pay", method=True, # 'to_pay': fields.function(select_by_name, string="To Pay", method=True,
@ -433,36 +433,36 @@ class payment_line(osv.osv):
('name_uniq', 'UNIQUE(name)', 'The payment line name must be unique!'), ('name_uniq', 'UNIQUE(name)', 'The payment line name must be unique!'),
] ]
def onchange_move_line(self,cr,uid,ids,move_line_id,payment_type,context=None): def onchange_move_line(self,cr,uid,ids,move_line_id,payment_type,date_prefered,date_planned,context=None):
data={} data={}
data['amount_currency']=data['currency']=data['communication']=data['partner_id']=data['reference']=data['date_created']=data['bank_id']=False data['amount_currency']=data['currency']=data['communication']=data['partner_id']=data['reference']=data['date_created']=data['bank_id']=False
if move_line_id: if move_line_id:
line=self.pool.get('account.move.line').browse(cr,uid,move_line_id) line = self.pool.get('account.move.line').browse(cr,uid,move_line_id)
data['amount_currency']=line.amount_to_pay data['amount_currency']=line.amount_to_pay
data['partner_id']=line.partner_id.id data['partner_id']=line.partner_id.id
data['currency']=line.currency_id and line.currency_id.id or False data['currency']=line.currency_id and line.currency_id.id or False
if not data['currency']: if not data['currency']:
data['currency']=line.invoice and line.invoice.currency_id.id or False data['currency']=line.invoice and line.invoice.currency_id.id or False
# calling onchange of partner and updating data dictionary # calling onchange of partner and updating data dictionary
temp_dict=self.onchange_partner(cr,uid,ids,line.partner_id.id) temp_dict=self.onchange_partner(cr,uid,ids,line.partner_id.id,payment_type)
data.update(temp_dict['value']) data.update(temp_dict['value'])
data['reference']=line.ref data['reference']=line.ref
data['date_created']=line.date_created data['date_created'] = line.date_created
data['communication']=line.ref data['communication']=line.ref
if payment_type: if date_prefered == 'now':
payment_mode = self.pool.get('payment.mode').browse(cr,uid,payment_type).type.code #no payment date => immediate payment
else: data['date'] = False
payment_mode=False elif date_prefered == 'due':
data['date'] = line.date_maturity
# data['bank_id']=self.pool.get('account.move.line').line2bank(cr, uid, elif date_prefered == 'fixed':
# [move_line_id], if date_planned:
# payment_mode or 'manual', context)[move_line_id] data['date'] = date_planned
return {'value': data} return {'value': data}
def onchange_partner(self,cr,uid,ids,partner_id,context=None): def onchange_partner(self,cr,uid,ids,partner_id,payment_type,context=None):
data={} data={}
data['info_partner']=data['bank_id']=False data['info_partner']=data['bank_id']=False
@ -488,8 +488,12 @@ class payment_line(osv.osv):
data['info_partner']=info data['info_partner']=info
if part_obj.bank_ids and len(part_obj.bank_ids)==1: if part_obj.bank_ids and payment_type:
data['bank_id']=self.pool.get('res.partner.bank').name_get(cr,uid,[part_obj.bank_ids[0].id])[0][0] bank_type = self.pool.get('payment.mode').suitable_bank_types(cr, uid, payment_type, context=context)
for bank in part_obj.bank_ids:
if bank.state in bank_type:
data['bank_id'] = bank.id
break
return {'value': data} return {'value': data}