mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[ADD] support for direct debit orders
This commit is contained in:
@@ -209,8 +209,16 @@ class payment_mode_type(osv.osv):
|
||||
'Leave empty for manual processing'),
|
||||
domain=[('osv_memory', '=', True)],
|
||||
),
|
||||
'payment_order_type': fields.selection(
|
||||
[('payment', 'Payment'),('debit', 'Direct debit')],
|
||||
'Payment order type', required=True,
|
||||
),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'payment_order_type': lambda *a: 'payment',
|
||||
}
|
||||
|
||||
payment_mode_type()
|
||||
|
||||
class payment_mode(osv.osv):
|
||||
@@ -777,7 +785,7 @@ class payment_order(osv.osv):
|
||||
'rejected': [('readonly', True)],
|
||||
'done': [('readonly', True)]
|
||||
},
|
||||
help='Select the Payment Mode to be applied.'
|
||||
help='Select the Payment Mode to be applied.',
|
||||
),
|
||||
'state': fields.selection([
|
||||
('draft', 'Draft'),
|
||||
@@ -820,8 +828,16 @@ class payment_order(osv.osv):
|
||||
"execution."
|
||||
)
|
||||
),
|
||||
'payment_order_type': fields.selection(
|
||||
[('payment', 'Payment'),('debit', 'Direct debit')],
|
||||
'Payment order type', required=True,
|
||||
),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'payment_order_type': lambda *a: 'payment',
|
||||
}
|
||||
|
||||
def launch_wizard(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Search for a wizard to launch according to the type.
|
||||
|
||||
@@ -423,6 +423,7 @@
|
||||
<field name="name" />
|
||||
<field name="code" />
|
||||
<field name="suitable_bank_types"/>
|
||||
<field name="payment_order_type"/>
|
||||
<field name="ir_model_id"/>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
@@ -91,11 +91,17 @@ class payment_order_create(osv.osv_memory):
|
||||
else:
|
||||
state = 'normal'
|
||||
communication2 = line.invoice.reference
|
||||
# support debit orders when enabled
|
||||
if (payment.payment_order_type == 'debit' and
|
||||
'amount_to_receive' in line):
|
||||
amount_currency = line.amount_to_receive
|
||||
else:
|
||||
amount_currency = line.amount_to_pay
|
||||
### end account_banking
|
||||
|
||||
payment_obj.create(cr, uid,{
|
||||
'move_line_id': line.id,
|
||||
'amount_currency': line.amount_to_pay,
|
||||
'amount_currency': amount_currency,
|
||||
'bank_id': line2bank.get(line.id),
|
||||
'order_id': payment.id,
|
||||
'partner_id': line.partner_id and line.partner_id.id or False,
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'Account Banking NL ClieOp',
|
||||
'version': '0.63',
|
||||
'version': '0.64',
|
||||
'license': 'GPL-3',
|
||||
'author': 'EduSense BV',
|
||||
'website': 'http://www.edusense.nl',
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
eval="[(6,0,[ref('base_iban.bank_iban'),ref('base.bank_normal'),])]" />
|
||||
<field name="ir_model_id"
|
||||
ref="account_banking_nl_clieop.model_banking_export_clieop_wizard"/>
|
||||
<field name="payment_order_type">debit</field>
|
||||
</record>
|
||||
|
||||
<record model="payment.mode.type" id="account_banking_nl_clieop.export_clieop_pay">
|
||||
@@ -17,6 +18,7 @@
|
||||
eval="[(6,0,[ref('base_iban.bank_iban'),ref('base.bank_normal'),])]" />
|
||||
<field name="ir_model_id"
|
||||
ref="account_banking_nl_clieop.model_banking_export_clieop_wizard"/>
|
||||
<field name="payment_order_type">payment</field>
|
||||
</record>
|
||||
|
||||
<record model="payment.mode.type" id="account_banking_nl_clieop.export_clieop_sal">
|
||||
@@ -26,6 +28,7 @@
|
||||
eval="[(6,0,[ref('base_iban.bank_iban'),ref('base.bank_normal'),])]" />
|
||||
<field name="ir_model_id"
|
||||
ref="account_banking_nl_clieop.model_banking_export_clieop_wizard"/>
|
||||
<field name="payment_order_type">payment</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2011 Therp BV (<http://therp.nl>)
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
""" r64: introduction of the payment_mode_type in order to support of debit orders
|
||||
"""
|
||||
__name__ = "payment.mode.type:: set payment_mode_type to 'debit' for Clieop incasso export"
|
||||
|
||||
def migrate(cr, version):
|
||||
cr.execute ("UPDATE payment_mode_type"
|
||||
" SET payment_order_type = 'debit'"
|
||||
" FROM ir_model_data "
|
||||
" WHERE res_id = payment_mode_type.id"
|
||||
" AND module = 'account_banking_nl_clieop'"
|
||||
" AND model = 'payment.mode.type'"
|
||||
" AND name = 'export_clieop_inc'"
|
||||
)
|
||||
2
account_direct_debit/__init__.py
Normal file
2
account_direct_debit/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
import account_payment
|
||||
import account_move_line
|
||||
53
account_direct_debit/__openerp__.py
Normal file
53
account_direct_debit/__openerp__.py
Normal file
@@ -0,0 +1,53 @@
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
|
||||
# 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 EduSense BV
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'Direct Debit',
|
||||
'version': '6.0.1.64',
|
||||
'license': 'GPL-3',
|
||||
'author': 'Therp BV',
|
||||
'website': 'http://www.therp.nl',
|
||||
'category': 'Banking addons',
|
||||
'depends': ['account_banking'],
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'account_payment_view.xml',
|
||||
],
|
||||
'demo_xml': [],
|
||||
'description': '''
|
||||
This module adds support for direct debit orders, analogous to payment orders.
|
||||
A new entry in the Accounting/Payment menu allow you to create a direct debit order that
|
||||
helps you to select any customer invoices for you to collect.
|
||||
|
||||
This module depends on and is part of the banking addons for OpenERP. This set of
|
||||
modules helps you to provide support for communications with your local banking
|
||||
institutions. See https://launchpad.net/banking-addons.
|
||||
|
||||
The banking addons are a continuation of Account Banking Framework by Edusense BV.
|
||||
See https://launchpad.net/account-banking.
|
||||
''',
|
||||
'active': False,
|
||||
'installable': True,
|
||||
}
|
||||
90
account_direct_debit/account_move_line.py
Normal file
90
account_direct_debit/account_move_line.py
Normal file
@@ -0,0 +1,90 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
# This module additional (C) 2011 Therp BV (<http://therp.nl>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from operator import itemgetter
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
class account_move_line(osv.osv):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
def amount_to_receive(self, cr, uid, ids, name, arg={}, context=None):
|
||||
""" Return the amount still to receive regarding all the payemnt orders
|
||||
(excepting cancelled orders)
|
||||
This is the reverse from account_payment/account_move_line.py
|
||||
"""
|
||||
if not ids:
|
||||
return {}
|
||||
cr.execute("""SELECT ml.id,
|
||||
CASE WHEN ml.amount_currency > 0
|
||||
THEN ml.amount_currency
|
||||
ELSE ml.debit
|
||||
END -
|
||||
(SELECT coalesce(sum(amount_currency),0)
|
||||
FROM payment_line pl
|
||||
INNER JOIN payment_order po
|
||||
ON (pl.order_id = po.id)
|
||||
WHERE move_line_id = ml.id
|
||||
AND po.state != 'cancel') AS amount
|
||||
FROM account_move_line ml
|
||||
WHERE id IN %s""", (tuple(ids),))
|
||||
r = dict(cr.fetchall())
|
||||
return r
|
||||
|
||||
def _to_receive_search(self, cr, uid, obj, name, args, context=None):
|
||||
if not args:
|
||||
return []
|
||||
line_obj = self.pool.get('account.move.line')
|
||||
query = line_obj._query_get(cr, uid, context={})
|
||||
where = ' and '.join(map(lambda x: '''(SELECT
|
||||
CASE WHEN l.amount_currency > 0
|
||||
THEN l.amount_currency
|
||||
ELSE l.debit
|
||||
END - coalesce(sum(pl.amount_currency), 0)
|
||||
FROM payment_line pl
|
||||
INNER JOIN payment_order po ON (pl.order_id = po.id)
|
||||
WHERE move_line_id = l.id
|
||||
AND po.state != 'cancel'
|
||||
) %(operator)s %%s ''' % {'operator': x[1]}, args))
|
||||
sql_args = tuple(map(itemgetter(2), args))
|
||||
|
||||
cr.execute(('''SELECT id
|
||||
FROM account_move_line l
|
||||
WHERE account_id IN (select id
|
||||
FROM account_account
|
||||
WHERE type=%s AND active)
|
||||
AND reconcile_id IS null
|
||||
AND debit > 0
|
||||
AND ''' + where + ' and ' + query), ('receivable',)+sql_args )
|
||||
|
||||
res = cr.fetchall()
|
||||
if not res:
|
||||
return [('id', '=', '0')]
|
||||
return [('id', 'in', map(lambda x:x[0], res))]
|
||||
|
||||
_columns = {
|
||||
'amount_to_receive': fields.function(amount_to_receive, method=True,
|
||||
type='float', string='Amount to receive', fnct_search=_to_receive_search),
|
||||
}
|
||||
|
||||
account_move_line()
|
||||
|
||||
73
account_direct_debit/account_payment.py
Normal file
73
account_direct_debit/account_payment.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from osv import osv, fields
|
||||
|
||||
class payment_order(osv.osv):
|
||||
_inherit = 'payment.order'
|
||||
|
||||
def fields_view_get(self, cr, user, view_id=None, view_type='form',
|
||||
context=None, toolbar=False, submenu=False):
|
||||
"""
|
||||
Pretty awful workaround for no dynamic domain possible on
|
||||
widget='selection'
|
||||
|
||||
The domain is encoded in the context
|
||||
|
||||
Uhmm, are these results are cached?
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
res = super(payment_order, self).fields_view_get(
|
||||
cr, user, view_id, view_type, context, toolbar, submenu)
|
||||
if context.get('search_payment_order_type', False) and view_type == 'form':
|
||||
if 'mode' in res['fields'] and 'selection' in res['fields']['mode']:
|
||||
mode_obj = self.pool.get('payment.mode')
|
||||
domain = ['|', ('type', '=', False), ('type.payment_order_type', '=',
|
||||
context['search_payment_order_type'])]
|
||||
# the magic is in the value of the selection
|
||||
res['fields']['mode']['selection'] = mode_obj._name_search(
|
||||
cr, user, args=domain)
|
||||
# also update the domain
|
||||
res['fields']['mode']['domain'] = domain
|
||||
return res
|
||||
payment_order()
|
||||
|
||||
class payment_order_create(osv.osv_memory):
|
||||
_inherit = 'payment.order.create'
|
||||
|
||||
def search_entries(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
This method taken from account_payment module.
|
||||
We adapt the domain based on the payment_order_type
|
||||
"""
|
||||
line_obj = self.pool.get('account.move.line')
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
if context is None:
|
||||
context = {}
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
search_due_date = data['duedate']
|
||||
|
||||
### start account_direct_debit ###
|
||||
payment = self.pool.get('payment.order').browse(cr, uid, context['active_id'], context=context)
|
||||
# Search for move line to pay:
|
||||
if payment.payment_order_type == 'debit':
|
||||
domain = [('reconcile_id', '=', False), ('account_id.type', '=', 'receivable'), ('amount_to_receive', '>', 0)]
|
||||
else:
|
||||
domain = [('reconcile_id', '=', False), ('account_id.type', '=', 'payable'), ('amount_to_pay', '>', 0)]
|
||||
# domain = [('reconcile_id', '=', False), ('account_id.type', '=', 'payable'), ('amount_to_pay', '>', 0)]
|
||||
### end account_direct_debit ###
|
||||
|
||||
domain = domain + ['|', ('date_maturity', '<=', search_due_date), ('date_maturity', '=', False)]
|
||||
line_ids = line_obj.search(cr, uid, domain, context=context)
|
||||
context.update({'line_ids': line_ids})
|
||||
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {'name': ('Entrie Lines'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'payment.order.create',
|
||||
'views': [(resource_id,'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
payment_order_create()
|
||||
63
account_direct_debit/account_payment_view.xml
Normal file
63
account_direct_debit/account_payment_view.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- distinguish between payment orders and debit orders in the menu -->
|
||||
<record id="account_payment.action_payment_order_tree" model="ir.actions.act_window">
|
||||
<field name="domain">[('payment_order_type', '=', 'payment')]</field>
|
||||
<field name="context">{'search_payment_order_type': 'payment'}</field>
|
||||
</record>
|
||||
<record id="action_debit_order_tree" model="ir.actions.act_window">
|
||||
<field name="name">Direct Debit Orders</field>
|
||||
<field name="res_model">payment.order</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="context">{'search_payment_order_type': 'debit'}</field>
|
||||
<field name="search_view_id" ref="account_payment.view_payment_order_search"/>
|
||||
<field name="domain">[('payment_order_type', '=', 'debit')]</field>
|
||||
<field name="help">A debit order is a debit request from your company to collect customer invoices. Here you can register all debit orders that should be done, keep track of all debit orders and mention the invoice reference and the partner the withdrawal should be done for.</field>
|
||||
</record>
|
||||
|
||||
<menuitem action="action_debit_order_tree" id="menu_action_debit_order_form" parent="account_payment.menu_main_payment" sequence="4"/>
|
||||
<!-- not needed I hope
|
||||
<record id="view_create_payment_order" model="ir.ui.view">
|
||||
<field name="name">payment.order.create.form</field>
|
||||
<field name="model">payment.order.create</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="account_payment.view_create_payment_order"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='search_entries']" position="attributes">
|
||||
<attribute name="name">search_entries</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
-->
|
||||
<record id="view_payment_order_form" model="ir.ui.view">
|
||||
<field name="name">payment.order.form</field>
|
||||
<field name="model">payment.order</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="account_payment.view_payment_order_form"/>
|
||||
<field name="priority" eval="60"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<field name="reference" position="after">
|
||||
<field name="payment_order_type"/>
|
||||
</field>
|
||||
<xpath expr="/form/group/button[@string='Select Invoices to Pay']"
|
||||
position="attributes">
|
||||
<attribute name="attrs">
|
||||
{'invisible':['|',('state','!=','draft'),('payment_order_type', '!=', 'payment')]}
|
||||
</attribute>
|
||||
</xpath>
|
||||
<xpath expr="/form/group/button[@string='Select Invoices to Pay']"
|
||||
position="after">
|
||||
<button colspan="2" name="%(account_payment.action_create_payment_order)s"
|
||||
string="Select Invoices to Collect" type="action"
|
||||
attrs="{'invisible':['|',('state','!=','draft'),('payment_order_type', '!=', 'debit')]}"
|
||||
icon="gtk-find"
|
||||
/>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user