mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Use attachments instead of creating a specific object for each kind of payment order
This commit is contained in:
committed by
Pedro M. Baeza
parent
57d586d7d4
commit
dd8f5d173a
@@ -1,8 +1,8 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# SEPA Direct Debit module for OpenERP
|
||||
# Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
# SEPA Direct Debit module for Odoo
|
||||
# Copyright (C) 2013-2015 Akretion (http://www.akretion.com)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@@ -34,18 +34,13 @@
|
||||
'account_banking_pain_base',
|
||||
'account_banking_mandate',
|
||||
],
|
||||
'external_dependencies': {
|
||||
'python': ['unidecode', 'lxml'],
|
||||
},
|
||||
'data': [
|
||||
'views/account_banking_sdd_view.xml',
|
||||
'views/account_banking_mandate_view.xml',
|
||||
'views/res_company_view.xml',
|
||||
'wizard/export_sdd_view.xml',
|
||||
'data/mandate_expire_cron.xml',
|
||||
'data/payment_type_sdd.xml',
|
||||
'security/original_mandate_required_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'demo': ['demo/sepa_direct_debit_demo.xml'],
|
||||
'description': '''
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 openerp import pooler, SUPERUSER_ID
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
cr.execute('''
|
||||
SELECT
|
||||
old_sepa.file,
|
||||
rel.account_order_id AS payment_order_id,
|
||||
payment_order.reference
|
||||
FROM migration_banking_export_sdd old_sepa
|
||||
LEFT JOIN migration_account_payment_order_sdd_rel rel
|
||||
ON old_sepa.id=rel.banking_export_sepa_id
|
||||
LEFT JOIN payment_order ON payment_order.id=rel.account_order_id
|
||||
''')
|
||||
|
||||
for sepa_file in cr.dictfetchall():
|
||||
filename = 'sdd_%s.xml' % sepa_file['reference'].replace('/', '-')
|
||||
pool['ir.attachment'].create(
|
||||
cr, SUPERUSER_ID, {
|
||||
'name': filename,
|
||||
'res_id': sepa_file['payment_order_id'],
|
||||
'res_model': 'payment.order',
|
||||
'datas': str(sepa_file['file']),
|
||||
})
|
||||
return
|
||||
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
|
||||
cr.execute(
|
||||
'ALTER TABLE banking_export_sdd '
|
||||
'RENAME TO migration_banking_export_sdd')
|
||||
cr.execute(
|
||||
'ALTER TABLE account_payment_order_sdd_rel '
|
||||
'RENAME TO migration_account_payment_order_sdd_rel')
|
||||
@@ -20,6 +20,5 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import banking_export_sdd
|
||||
from . import res_company
|
||||
from . import account_banking_mandate
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# SEPA Direct Debit module for OpenERP
|
||||
# Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# 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 openerp import models, fields, api
|
||||
from openerp.addons.decimal_precision import decimal_precision as dp
|
||||
|
||||
try:
|
||||
from unidecode import unidecode
|
||||
except ImportError:
|
||||
unidecode = None
|
||||
|
||||
|
||||
class BankingExportSdd(models.Model):
|
||||
"""SEPA Direct Debit export"""
|
||||
_name = 'banking.export.sdd'
|
||||
_description = __doc__
|
||||
_rec_name = 'filename'
|
||||
|
||||
@api.one
|
||||
@api.depends('payment_order_ids', 'payment_order_ids.reference')
|
||||
def _generate_filename(self):
|
||||
if self.payment_order_ids:
|
||||
ref = self.payment_order_ids[0].reference
|
||||
label = unidecode(ref.replace('/', '-')) if ref else 'error'
|
||||
filename = 'sdd_%s.xml' % label
|
||||
else:
|
||||
filename = 'sdd.xml'
|
||||
self.filename = filename
|
||||
|
||||
payment_order_ids = fields.Many2many(
|
||||
comodel_name='payment.order',
|
||||
relation='account_payment_order_sdd_rel',
|
||||
column1='banking_export_sepa_id', column2='account_order_id',
|
||||
string='Payment Orders',
|
||||
readonly=True)
|
||||
nb_transactions = fields.Integer(
|
||||
string='Number of Transactions', readonly=True)
|
||||
total_amount = fields.Float(
|
||||
string='Total Amount', digits_compute=dp.get_precision('Account'),
|
||||
readonly=True)
|
||||
batch_booking = fields.Boolean(
|
||||
'Batch Booking', readonly=True,
|
||||
help="If true, the bank statement will display only one credit line "
|
||||
"for all the direct debits of the SEPA file ; if false, the bank "
|
||||
"statement will display one credit line per direct debit of the "
|
||||
"SEPA file.")
|
||||
charge_bearer = fields.Selection(
|
||||
[('SLEV', 'Following Service Level'),
|
||||
('SHAR', 'Shared'),
|
||||
('CRED', 'Borne by Creditor'),
|
||||
('DEBT', 'Borne by Debtor')], 'Charge Bearer', readonly=True,
|
||||
help="Following service level : transaction charges are to be applied "
|
||||
"following the rules agreed in the service level and/or scheme "
|
||||
"(SEPA Core messages must use this). Shared : transaction "
|
||||
"charges on the creditor side are to be borne by the creditor, "
|
||||
"transaction charges on the debtor side are to be borne by the "
|
||||
"debtor. Borne by creditor : all transaction charges are to be "
|
||||
"borne by the creditor. Borne by debtor : all transaction "
|
||||
"charges are to be borne by the debtor.")
|
||||
create_date = fields.Datetime(string='Generation Date', readonly=True)
|
||||
file = fields.Binary(string='SEPA File', readonly=True)
|
||||
filename = fields.Char(compute=_generate_filename, size=256,
|
||||
string='Filename', readonly=True, store=True)
|
||||
state = fields.Selection([('draft', 'Draft'), ('sent', 'Sent')],
|
||||
string='State', readonly=True, default='draft')
|
||||
@@ -1,2 +0,0 @@
|
||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_banking_export_sdd","Full access on banking.export.sdd","model_banking_export_sdd","account_payment.group_account_payment",1,1,1,1
|
||||
|
@@ -1,77 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_banking_export_sdd_form" model="ir.ui.view">
|
||||
<field name="name">account.banking.export.sdd.form</field>
|
||||
<field name="model">banking.export.sdd</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="SEPA Direct Debit" version="7.0">
|
||||
<header>
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<notebook>
|
||||
<page string="General Information">
|
||||
<group name="main">
|
||||
<field name="total_amount" />
|
||||
<field name="nb_transactions" />
|
||||
<field name="batch_booking" />
|
||||
<field name="charge_bearer"/>
|
||||
<field name="create_date" />
|
||||
<field name="file" filename="filename"/>
|
||||
<field name="filename" invisible="True"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Payment Orders">
|
||||
<field name="payment_order_ids" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_banking_export_sdd_tree" model="ir.ui.view">
|
||||
<field name="name">account.banking.export.sdd.tree</field>
|
||||
<field name="model">banking.export.sdd</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="SEPA Direct Debit">
|
||||
<field name="filename"/>
|
||||
<field name="create_date"/>
|
||||
<field name="nb_transactions"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="action_account_banking_sdd" model="ir.actions.act_window">
|
||||
<field name="name">SEPA Direct Debit Files</field>
|
||||
<field name="res_model">banking.export.sdd</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
|
||||
<menuitem id="menu_account_banking_sdd"
|
||||
parent="account_payment.menu_main_payment"
|
||||
action="action_account_banking_sdd"
|
||||
sequence="20"
|
||||
/>
|
||||
|
||||
<act_window id="act_banking_export_sdd_payment_order"
|
||||
name="Generated SEPA Direct Debit Files"
|
||||
domain="[('payment_order_ids', '=', active_id)]"
|
||||
res_model="banking.export.sdd"
|
||||
src_model="payment.order"
|
||||
view_type="form"
|
||||
view_mode="tree,form"
|
||||
/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,8 +1,8 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# SEPA Direct Debit module for OpenERP
|
||||
# Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
# SEPA Direct Debit module for Odoo
|
||||
# Copyright (C) 2013-2015 Akretion (http://www.akretion.com)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@@ -24,7 +24,6 @@
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp import workflow
|
||||
from datetime import datetime
|
||||
from lxml import etree
|
||||
|
||||
|
||||
@@ -56,19 +55,14 @@ class BankingExportSddWizard(orm.TransientModel):
|
||||
"transaction charges are to be borne by the creditor. Borne "
|
||||
"by debtor : all transaction charges are to be borne by the "
|
||||
"debtor."),
|
||||
'nb_transactions': fields.related(
|
||||
'file_id', 'nb_transactions', type='integer',
|
||||
'nb_transactions': fields.integer(
|
||||
string='Number of Transactions', readonly=True),
|
||||
'total_amount': fields.related(
|
||||
'file_id', 'total_amount', type='float', string='Total Amount',
|
||||
readonly=True),
|
||||
'file_id': fields.many2one(
|
||||
'banking.export.sdd', 'SDD File', readonly=True),
|
||||
'file': fields.related(
|
||||
'file_id', 'file', string="File", type='binary', readonly=True),
|
||||
'filename': fields.related(
|
||||
'file_id', 'filename', string="Filename", type='char', size=256,
|
||||
readonly=True),
|
||||
'total_amount': fields.float(
|
||||
string='Total Amount', readonly=True),
|
||||
'file': fields.binary(
|
||||
string="File", readonly=True),
|
||||
'filename': fields.char(
|
||||
string="Filename", readonly=True),
|
||||
'payment_order_ids': fields.many2many(
|
||||
'payment.order', 'wiz_sdd_payorders_rel', 'wizard_id',
|
||||
'payment_order_id', 'Payment Orders', readonly=True),
|
||||
@@ -144,9 +138,9 @@ class BankingExportSddWizard(orm.TransientModel):
|
||||
'name_maxsize': name_maxsize,
|
||||
'convert_to_ascii': convert_to_ascii,
|
||||
'payment_method': 'DD',
|
||||
'file_prefix': 'sdd_',
|
||||
'pain_flavor': pain_flavor,
|
||||
'sepa_export': sepa_export,
|
||||
'file_obj': self.pool['banking.export.sdd'],
|
||||
'pain_xsd_file':
|
||||
'account_banking_sepa_direct_debit/data/%s.xsd' % pain_flavor,
|
||||
}
|
||||
@@ -397,29 +391,21 @@ class BankingExportSddWizard(orm.TransientModel):
|
||||
cr, uid, ids, xml_root, total_amount, transactions_count_1_6,
|
||||
gen_args, context=context)
|
||||
|
||||
def cancel_sepa(self, cr, uid, ids, context=None):
|
||||
"""Cancel the SEPA file: just drop the file"""
|
||||
sepa_export = self.browse(cr, uid, ids[0], context=context)
|
||||
self.pool.get('banking.export.sdd').unlink(
|
||||
cr, uid, sepa_export.file_id.id, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def save_sepa(self, cr, uid, ids, context=None):
|
||||
"""Save the SEPA Direct Debit file: mark all payments in the file
|
||||
as 'sent'. Write 'last debit date' on mandate and set oneoff
|
||||
mandate to expired.
|
||||
"""
|
||||
sepa_export = self.browse(cr, uid, ids[0], context=context)
|
||||
self.pool.get('banking.export.sdd').write(
|
||||
cr, uid, sepa_export.file_id.id, {'state': 'sent'},
|
||||
context=context)
|
||||
for order in sepa_export.payment_order_ids:
|
||||
workflow.trg_validate(uid, 'payment.order', order.id, 'done', cr)
|
||||
mandate_ids = [line.mandate_id.id for line in order.line_ids]
|
||||
self.pool['account.banking.mandate'].write(
|
||||
cr, uid, mandate_ids,
|
||||
{'last_debit_date': datetime.today().strftime('%Y-%m-%d')},
|
||||
context=context)
|
||||
self.pool['ir.attachment'].create(
|
||||
cr, uid, {
|
||||
'res_model': 'payment.order',
|
||||
'res_id': order.id,
|
||||
'name': sepa_export.filename,
|
||||
'datas': sepa_export.file,
|
||||
}, context=context)
|
||||
to_expire_ids = []
|
||||
first_mandate_ids = []
|
||||
for line in order.line_ids:
|
||||
@@ -438,4 +424,4 @@ class BankingExportSddWizard(orm.TransientModel):
|
||||
'recurrent_sequence_type': 'recurring',
|
||||
'sepa_migrated': True,
|
||||
}, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
return True
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<field name="name">banking.export.sdd.wizard.view</field>
|
||||
<field name="model">banking.export.sdd.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="SEPA Direct Debit XML file generation" version="7.0">
|
||||
<form string="SEPA Direct Debit XML file generation">
|
||||
<field name="state" invisible="True"/>
|
||||
<group states="create">
|
||||
<field name="batch_booking" />
|
||||
@@ -25,9 +25,8 @@
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Generate" name="create_sepa" type="object" class="oe_highlight" states="create"/>
|
||||
<button string="Cancel" special="cancel" class="oe_link" states="create"/>
|
||||
<button string="Validate" name="save_sepa" type="object" class="oe_highlight" states="finish"/>
|
||||
<button string="Cancel" name="cancel_sepa" type="object" class="oe_link" states="finish"/>
|
||||
<button string="Cancel" special="cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user