ACCOUNT_PAYMENT: Added multi-wizard support and bugfixes.
bzr revid: bch-3217f246b7f5338e941ae2b49db6f323b266bdf7
This commit is contained in:
parent
4f3766780e
commit
7c712e115b
|
@ -62,17 +62,16 @@ class account_move_line(osv.osv):
|
|||
return [('id','in',map(lambda x:x[0], res))]
|
||||
|
||||
|
||||
def line2bank(self,cr,uid,ids,payment_mode= '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 mode. This work using one of
|
||||
account according to the payment type. This work using one of
|
||||
the bank of the partner defined on the invoice eventually
|
||||
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_mode,context=context)
|
||||
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)
|
||||
|
|
|
@ -34,6 +34,7 @@ class payment_type(osv.osv):
|
|||
_description= 'Payment type'
|
||||
_columns= {
|
||||
'name': fields.char('Name', size=64, required=True),
|
||||
'code': fields.char('Code', size=64, required=True),
|
||||
'suitable_bank_types': fields.many2many('res.partner.bank.type',
|
||||
'bank_type_payment_type_rel',
|
||||
'pay_type_id','bank_type_id',
|
||||
|
@ -49,20 +50,19 @@ class payment_mode(osv.osv):
|
|||
_description= 'Payment mode'
|
||||
_columns= {
|
||||
'name': fields.char('Name', size=64, required=True),
|
||||
'code': fields.char('Code', size=64, required=True,unique=True,select=True),
|
||||
'bank_id': fields.many2one('res.partner.bank',"Bank account",required=True),
|
||||
'journal': fields.many2one('account.journal','Journal',required=True,domain=[('type','=','cash')]),
|
||||
'type': fields.many2one('payment.type','Payment type',required=True),
|
||||
'account': fields.many2one('account.account','Default payable account',domain=[('type','=','payable')],required=True),
|
||||
}
|
||||
|
||||
def suitable_bank_types(self,cr,uid,payment_code,context):
|
||||
""" Return the codes of the bank type that are suitable for the given payment mode"""
|
||||
def suitable_bank_types(self,cr,uid,payment_code= 'manual',context={}):
|
||||
""" Return the codes of the bank type that are suitable for the given payment type code"""
|
||||
cr.execute(""" select t.code
|
||||
from res_partner_bank_type t
|
||||
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_mode m on (pt.id=m.type)
|
||||
where m.code = %s""", [payment_code])
|
||||
where pt.code = %s """, [payment_code])
|
||||
return [x[0] for x in cr.fetchall()]
|
||||
|
||||
payment_mode()
|
||||
|
@ -73,6 +73,11 @@ class payment_order(osv.osv):
|
|||
_description = 'Payment Order'
|
||||
_rec_name = 'date'
|
||||
|
||||
def get_wizard(self,type):
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel("warning", netsvc.LOG_WARNING, "No wizard found for the payment type '%s'."%type)
|
||||
return None
|
||||
|
||||
def _total(self, cr, uid, ids, name, args, context={}):
|
||||
if not ids: return {}
|
||||
cr.execute("""select o.id, coalesce(sum(amount),0)
|
||||
|
@ -89,16 +94,10 @@ class payment_order(osv.osv):
|
|||
res.update(dict(cr.fetchall()))
|
||||
return res
|
||||
|
||||
def mode_get(self, cr, uid, context={}):
|
||||
pay_type_obj = self.pool.get('payment.mode')
|
||||
ids = pay_type_obj.search(cr, uid, [])
|
||||
res = pay_type_obj.read(cr, uid, ids, ['code','name'], context)
|
||||
return [(r['code'],r['name']) for r in res] + [('manual', 'Manual')]
|
||||
|
||||
_columns = {
|
||||
'date_planned': fields.date('Scheduled date if fixed'),
|
||||
'reference': fields.char('Reference',size=128),
|
||||
'mode': fields.selection(mode_get, 'Payment mode',size=16,required=True, select=True),
|
||||
'mode': fields.many2one('payment.mode','Payment mode', select=True),
|
||||
'state': fields.selection([('draft', 'Draft'),('open','Open'),
|
||||
('cancel','Cancelled'),('done','Done')], 'State', select=True),
|
||||
'line_ids': fields.one2many('payment.line','order_id','Payment lines'),
|
||||
|
@ -112,7 +111,6 @@ class payment_order(osv.osv):
|
|||
|
||||
_defaults = {
|
||||
'user_id': lambda self,cr,uid,context: uid,
|
||||
'mode': lambda *a : 'manual',
|
||||
'state': lambda *a: 'draft',
|
||||
'date_prefered': lambda *a: 'due',
|
||||
'date_created': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
|
@ -132,10 +130,15 @@ class payment_order(osv.osv):
|
|||
self.write(cr,uid,order['id'],{'reference':reference})
|
||||
return True
|
||||
|
||||
def action_done(self, cr, uid, ids, *args):
|
||||
self.write(cr,uid,ids,{'date_done':time.strftime('%Y-%m-%d')})
|
||||
def set_done(self, cr, uid, id, *args):
|
||||
self.write(cr,uid,id,{'date_done':time.strftime('%Y-%m-%d'),
|
||||
'state':'done',})
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'payment.order', id, 'done', cr)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
payment_order()
|
||||
|
||||
class payment_line(osv.osv):
|
||||
|
@ -147,7 +150,9 @@ class payment_line(osv.osv):
|
|||
if not ids: return {}
|
||||
partners= self.read(cr, uid, ids, ['partner_id'], context)
|
||||
partners= dict(map(lambda x: (x['id'],x['partner_id']),partners))
|
||||
debit= self.pool.get('res.partner')._debit_get(cr, uid, partners.values(), name, args, context)
|
||||
debit= self.pool.get('res.partner')._debit_get(cr, uid,
|
||||
partners.values(), name,
|
||||
args, context)
|
||||
for i in partners:
|
||||
partners[i]= debit[partners[i]]
|
||||
return partners
|
||||
|
@ -178,16 +183,17 @@ class payment_line(osv.osv):
|
|||
'reference': fields.function(select_by_name, string="Ref", method=True, type='char'),
|
||||
'partner_payable': fields.function(partner_payable, string="Partner payable", method=True, type='float'),
|
||||
}
|
||||
def onchange_move_line(self, cr, uid, id, move_line_id, type,context={}):
|
||||
def onchange_move_line(self, cr, uid, id, move_line_id, payment_type,context={}):
|
||||
if not move_line_id:
|
||||
return {}
|
||||
line=self.pool.get('account.move.line').browse(cr,uid,move_line_id)
|
||||
return {'value': {'amount': line.amount_to_pay,
|
||||
'to_pay': line.amount_to_pay,
|
||||
'partner_id': line.partner_id,
|
||||
'partner_id': line.partner_id.id,
|
||||
'reference': line.ref,
|
||||
'date_created': line.date_created,
|
||||
'bank_id': self.pool.get('account.move.line').line2bank(cr,uid,[move_line_id],type,context)[move_line_id]
|
||||
'bank_id': self.pool.get('account.move.line').line2bank(cr,uid,[move_line_id],
|
||||
payment_type or 'manual',context)[move_line_id]
|
||||
}}
|
||||
|
||||
payment_line()
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Payment type">
|
||||
<field name="name" select="1"/>
|
||||
<field name="code"/>
|
||||
<newline/>
|
||||
<field name="suitable_bank_types" select="1"/>
|
||||
</form>
|
||||
|
@ -31,8 +32,8 @@
|
|||
<field name="arch" type="xml">
|
||||
<tree string="Payment mode">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
<field name="journal" />
|
||||
<field name="account" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -43,10 +44,10 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Payment mode">
|
||||
<field name="name" select="1"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="type" />
|
||||
<field name="journal" />
|
||||
<field name="bank_id" />
|
||||
<field name="type"/>
|
||||
<field name="journal"/>
|
||||
<field name="bank_id"/>
|
||||
<field name="account"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -56,8 +57,10 @@
|
|||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
<menuitem name="Financial Management/Payment Management/Configuration/Payment Mode" id="menu_action_payment_mode_form" action="action_payment_mode_form"/>
|
||||
|
||||
<menuitem
|
||||
name="Financial Management/Payment Management/Configuration/Payment Mode"
|
||||
id="menu_action_payment_mode_form" action="action_payment_mode_form"/>
|
||||
<record model="ir.ui.view" id="view_payment_order_form">
|
||||
<field name="name">payment.order.form</field>
|
||||
<field name="model">payment.order</field>
|
||||
|
@ -69,7 +72,8 @@
|
|||
<field name="date_prefered" />
|
||||
<field name="date_planned" select="1"/>
|
||||
<field name="user_id" select="2"/>
|
||||
<button name="%(wizard_payment)d" string="Add payment lines" type="action" colspan="2"/>
|
||||
<button name="%(wizard_populate_payment)d"
|
||||
string="Add payment lines" type="action" colspan="2"/>
|
||||
<field name="line_ids" colspan="4" nolabel="1"/>
|
||||
<field name="total"/>
|
||||
<field name="nb_line"/>
|
||||
|
@ -79,8 +83,10 @@
|
|||
<group colspan="2" col="4">
|
||||
<button name="cancel" states="draft,open" string="Cancel"/>
|
||||
<button name="open" states="draft" string="Open"/>
|
||||
<button name="done" states="open" string="Make Payment"/>
|
||||
<button name="set_to_draft" states="cancel" type="object" string="Set to draft"/>
|
||||
<button name="%(wizard_pay_payment)d" states="open,done"
|
||||
string="Make Payment" type="action"/>
|
||||
<button name="set_to_draft" states="cancel"
|
||||
type="object" string="Set to draft"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -150,7 +156,8 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Payment Line">
|
||||
<field name="move_line_id" select="1" on_change="onchange_move_line(move_line_id,parent.mode)" domain="[('reconcile_id','=', False), ('credit', '>',0),('amount_to_pay','>',0)] "/>
|
||||
<field name="move_line_id"
|
||||
select="1" on_change="onchange_move_line(move_line_id,parent.mode.type.code)" domain="[('reconcile_id','=', False), ('credit', '>',0),('amount_to_pay','>',0)] "/>
|
||||
<field name="amount" select="1" />
|
||||
<field name="bank_id" domain="[('partner_id','=',partner_id)]"/>
|
||||
<field name="to_pay"/>
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<terp>
|
||||
<data>
|
||||
<data>
|
||||
<wizard
|
||||
string="Payement Order"
|
||||
model="payment.order"
|
||||
name="make_payment"
|
||||
menu="False"
|
||||
id="wizard_payment"/>
|
||||
</data>
|
||||
string="Populate payment"
|
||||
model="payment.order"
|
||||
name="populate_payment"
|
||||
menu="False"
|
||||
id="wizard_populate_payment"/>
|
||||
|
||||
<wizard
|
||||
string="Pay"
|
||||
model="payment.order"
|
||||
name="pay_payment"
|
||||
menu="False"
|
||||
id="wizard_pay_payment"/>
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
<field name="name">done</field>
|
||||
<field name="wkf_id" ref="wkf_payment_order"/>
|
||||
<field name="flow_stop">True</field>
|
||||
<field name="action">action_done() write({'state':'done'})</field>
|
||||
<field name="kind">function</field>
|
||||
</record>
|
||||
<record model="workflow.activity" id="act_cancel">
|
||||
<field name="name">cancel</field>
|
||||
|
|
|
@ -28,6 +28,4 @@
|
|||
##############################################################################
|
||||
|
||||
import wizard_payment_order
|
||||
|
||||
|
||||
|
||||
import wizard_pay
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# garantees and support are strongly adviced to contract a Free Software
|
||||
# Service Company
|
||||
#
|
||||
# This program is Free Software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
from osv import osv
|
||||
import pooler
|
||||
from osv import fields
|
||||
import time
|
||||
|
||||
|
||||
def _launch_wizard(self, cr, uid, data, context):
|
||||
"""
|
||||
Search for a wizard to launch according to the type.
|
||||
If type is manual. just confirm the order.
|
||||
"""
|
||||
|
||||
order_ref= pooler.get_pool(cr.dbname).get('payment.order')
|
||||
order= order_ref.browse(cr,uid,data['id'],context)
|
||||
t= order.mode and order.mode.type.code or 'manual'
|
||||
if t == 'manual' :
|
||||
order_ref.set_done(cr,uid,data['id'],context)
|
||||
return {}
|
||||
|
||||
gw= order_ref.get_wizard(t)
|
||||
if not gw:
|
||||
order_ref.set_done(cr,uid,data['id'],context)
|
||||
return {}
|
||||
|
||||
mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
|
||||
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.wizard')
|
||||
module, wizard= gw
|
||||
result = mod_obj._get_id(cr, uid, module, wizard)
|
||||
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
|
||||
result = act_obj.read(cr, uid, [id])[0]
|
||||
#result['context'] = str({'fiscalyear': data['form']['fiscalyear']})
|
||||
return result
|
||||
|
||||
|
||||
class wizard_pay(wizard.interface):
|
||||
|
||||
states= {'init' : {'actions': [],
|
||||
'result':{'type':'action',
|
||||
'action':_launch_wizard,
|
||||
'state':'end'}
|
||||
}
|
||||
}
|
||||
wizard_pay('pay_payment')
|
|
@ -64,9 +64,10 @@ def create_payment(self, cr, uid, data, context):
|
|||
if not mline_ids: return {}
|
||||
|
||||
pool= pooler.get_pool(cr.dbname)
|
||||
payment = pool.get('payment.order').read(cr,uid,data['id'],['mode'])
|
||||
payment = pool.get('payment.order').browse(cr,uid,data['id'],context)
|
||||
t= payment.mode and payment.mode.type.code or 'manual'
|
||||
line2bank= pool.get('account.move.line').line2bank(cr,uid,
|
||||
mline_ids,payment['mode'],context)
|
||||
mline_ids,t,context)
|
||||
|
||||
## Finally populate the current payment with new lines:
|
||||
for line in pool.get('account.move.line').browse(cr,uid,mline_ids,context=context):
|
||||
|
@ -74,7 +75,7 @@ def create_payment(self, cr, uid, data, context):
|
|||
'move_line_id': line.id,
|
||||
'amount':line.amount_to_pay,
|
||||
'bank_id':line2bank.get(line.id),
|
||||
'order_id': payment['id'],
|
||||
'order_id': payment.id,
|
||||
})
|
||||
|
||||
return {}
|
||||
|
@ -104,6 +105,6 @@ class wizard_payment_order(wizard.interface):
|
|||
},
|
||||
|
||||
}
|
||||
wizard_payment_order('make_payment')
|
||||
wizard_payment_order('populate_payment')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue