diff --git a/account_banking_sepa_direct_debit/__openerp__.py b/account_banking_sepa_direct_debit/__openerp__.py index 6a95f0255..3fa29c1eb 100644 --- a/account_banking_sepa_direct_debit/__openerp__.py +++ b/account_banking_sepa_direct_debit/__openerp__.py @@ -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 # # 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': ''' diff --git a/account_banking_sepa_direct_debit/migrations/8.0.0.2/post-migration.py b/account_banking_sepa_direct_debit/migrations/8.0.0.2/post-migration.py new file mode 100644 index 000000000..dd759cac6 --- /dev/null +++ b/account_banking_sepa_direct_debit/migrations/8.0.0.2/post-migration.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Akretion (http://www.akretion.com/) +# @author: Alexis de Lattre +# +# 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 . +# +############################################################################## + +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 diff --git a/account_banking_sepa_direct_debit/migrations/8.0.0.2/pre-migration.py b/account_banking_sepa_direct_debit/migrations/8.0.0.2/pre-migration.py new file mode 100644 index 000000000..42fa23b0a --- /dev/null +++ b/account_banking_sepa_direct_debit/migrations/8.0.0.2/pre-migration.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Akretion (http://www.akretion.com/) +# @author: Alexis de Lattre +# +# 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 . +# +############################################################################## + + +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') diff --git a/account_banking_sepa_direct_debit/models/__init__.py b/account_banking_sepa_direct_debit/models/__init__.py index 274855e14..153ab3543 100644 --- a/account_banking_sepa_direct_debit/models/__init__.py +++ b/account_banking_sepa_direct_debit/models/__init__.py @@ -20,6 +20,5 @@ # ############################################################################## -from . import banking_export_sdd from . import res_company from . import account_banking_mandate diff --git a/account_banking_sepa_direct_debit/models/banking_export_sdd.py b/account_banking_sepa_direct_debit/models/banking_export_sdd.py deleted file mode 100644 index 84ac0b5e7..000000000 --- a/account_banking_sepa_direct_debit/models/banking_export_sdd.py +++ /dev/null @@ -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 -# -# 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 . -# -############################################################################## - -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') diff --git a/account_banking_sepa_direct_debit/security/ir.model.access.csv b/account_banking_sepa_direct_debit/security/ir.model.access.csv deleted file mode 100644 index 0cd579511..000000000 --- a/account_banking_sepa_direct_debit/security/ir.model.access.csv +++ /dev/null @@ -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 diff --git a/account_banking_sepa_direct_debit/views/account_banking_sdd_view.xml b/account_banking_sepa_direct_debit/views/account_banking_sdd_view.xml deleted file mode 100644 index f74b60353..000000000 --- a/account_banking_sepa_direct_debit/views/account_banking_sdd_view.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - account.banking.export.sdd.form - banking.export.sdd - -
-
- -
- - - - - - - - - - - - - - - - -
-
-
- - - - account.banking.export.sdd.tree - banking.export.sdd - - - - - - - - - - - - - SEPA Direct Debit Files - banking.export.sdd - form - tree,form - - - - - - - -
-
diff --git a/account_banking_sepa_direct_debit/wizard/export_sdd.py b/account_banking_sepa_direct_debit/wizard/export_sdd.py index 948fa68be..9fc1e2876 100644 --- a/account_banking_sepa_direct_debit/wizard/export_sdd.py +++ b/account_banking_sepa_direct_debit/wizard/export_sdd.py @@ -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 # # 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 diff --git a/account_banking_sepa_direct_debit/wizard/export_sdd_view.xml b/account_banking_sepa_direct_debit/wizard/export_sdd_view.xml index 3699de91c..95117e270 100644 --- a/account_banking_sepa_direct_debit/wizard/export_sdd_view.xml +++ b/account_banking_sepa_direct_debit/wizard/export_sdd_view.xml @@ -11,7 +11,7 @@ banking.export.sdd.wizard.view banking.export.sdd.wizard -
+ @@ -25,9 +25,8 @@