From 9c6ece2d8c0bd90f8da1764042dafe587e47c4a5 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 29 Jan 2015 16:30:02 +0100 Subject: [PATCH] Use attachments instead of creating a specific object for each kind of payment order --- .../__init__.py | 1 - .../__openerp__.py | 9 +-- .../migrations/8.0.0.3/post-migration.py | 50 ++++++++++++ .../8.0.0.3/pre-migration.py} | 17 +++- .../models/account_banking_sepa.py | 80 ------------------- .../security/ir.model.access.csv | 2 - .../views/account_banking_sepa_view.xml | 77 ------------------ .../wizard/export_sepa.py | 44 +++++----- .../wizard/export_sepa_view.xml | 7 +- 9 files changed, 86 insertions(+), 201 deletions(-) create mode 100644 account_banking_sepa_credit_transfer/migrations/8.0.0.3/post-migration.py rename account_banking_sepa_credit_transfer/{models/__init__.py => migrations/8.0.0.3/pre-migration.py} (70%) delete mode 100644 account_banking_sepa_credit_transfer/models/account_banking_sepa.py delete mode 100644 account_banking_sepa_credit_transfer/security/ir.model.access.csv delete mode 100644 account_banking_sepa_credit_transfer/views/account_banking_sepa_view.xml diff --git a/account_banking_sepa_credit_transfer/__init__.py b/account_banking_sepa_credit_transfer/__init__.py index c30bd487e..73b1281b2 100644 --- a/account_banking_sepa_credit_transfer/__init__.py +++ b/account_banking_sepa_credit_transfer/__init__.py @@ -21,4 +21,3 @@ ############################################################################## from . import wizard -from . import models diff --git a/account_banking_sepa_credit_transfer/__openerp__.py b/account_banking_sepa_credit_transfer/__openerp__.py index b7c3ff00e..0b9ccd552 100644 --- a/account_banking_sepa_credit_transfer/__openerp__.py +++ b/account_banking_sepa_credit_transfer/__openerp__.py @@ -1,8 +1,8 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# SEPA Credit Transfer module for OpenERP -# Copyright (C) 2010-2013 Akretion (http://www.akretion.com) +# SEPA Credit Transfer module for Odoo +# Copyright (C) 2010-2015 Akretion (http://www.akretion.com) # @author: Alexis de Lattre # # This program is free software: you can redistribute it and/or modify @@ -30,14 +30,9 @@ 'website': 'https://github.com/OCA/bank-payment', 'category': 'Banking addons', 'depends': ['account_banking_pain_base'], - 'external_dependencies': { - 'python': ['unidecode', 'lxml'], - }, 'data': [ - 'views/account_banking_sepa_view.xml', 'wizard/export_sepa_view.xml', 'data/payment_type_sepa_sct.xml', - 'security/ir.model.access.csv', ], 'demo': [ 'demo/sepa_credit_transfer_demo.xml' diff --git a/account_banking_sepa_credit_transfer/migrations/8.0.0.3/post-migration.py b/account_banking_sepa_credit_transfer/migrations/8.0.0.3/post-migration.py new file mode 100644 index 000000000..58c5831f0 --- /dev/null +++ b/account_banking_sepa_credit_transfer/migrations/8.0.0.3/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_sepa old_sepa + LEFT JOIN migration_account_payment_order_sepa_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 = 'sct_%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_credit_transfer/models/__init__.py b/account_banking_sepa_credit_transfer/migrations/8.0.0.3/pre-migration.py similarity index 70% rename from account_banking_sepa_credit_transfer/models/__init__.py rename to account_banking_sepa_credit_transfer/migrations/8.0.0.3/pre-migration.py index 90e481210..f1f5f7b0f 100644 --- a/account_banking_sepa_credit_transfer/models/__init__.py +++ b/account_banking_sepa_credit_transfer/migrations/8.0.0.3/pre-migration.py @@ -1,8 +1,7 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # -# SEPA Credit Transfer module for OpenERP -# Copyright (C) 2010-2013 Akretion (http://www.akretion.com) +# Copyright (C) 2015 Akretion (http://www.akretion.com/) # @author: Alexis de Lattre # # This program is free software: you can redistribute it and/or modify @@ -20,4 +19,14 @@ # ############################################################################## -from . import account_banking_sepa + +def migrate(cr, version): + if not version: + return + + cr.execute( + 'ALTER TABLE banking_export_sepa ' + 'RENAME TO migration_banking_export_sepa') + cr.execute( + 'ALTER TABLE account_payment_order_sepa_rel ' + 'RENAME TO migration_account_payment_order_sepa_rel') diff --git a/account_banking_sepa_credit_transfer/models/account_banking_sepa.py b/account_banking_sepa_credit_transfer/models/account_banking_sepa.py deleted file mode 100644 index f463a5050..000000000 --- a/account_banking_sepa_credit_transfer/models/account_banking_sepa.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# SEPA Credit Transfer module for OpenERP -# Copyright (C) 2010-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 BankingExportSepa(models.Model): - """SEPA export""" - _name = 'banking.export.sepa' - _description = __doc__ - _rec_name = 'filename' - - @api.one - def _generate_filename(self): - ref = self.payment_order_ids.reference - if ref: - label = unidecode(ref.replace('/', '-')) - else: - label = 'error' - self.filename = 'sct_%s.xml' % label - - payment_order_ids = fields.Many2many( - comodel_name='payment.order', column1='banking_export_sepa_id', - column2='account_order_id', relation='account_payment_order_sepa_rel', - 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 debit line " - "for all the wire transfers of the SEPA XML file ; if false, " - "the bank statement will display one debit line per wire " - "transfer of the SEPA XML file.") - charge_bearer = fields.Selection( - [('SLEV', 'Following Service Level'), - ('SHAR', 'Shared'), - ('CRED', 'Borne by Creditor'), - ('DEBT', 'Borne by Debtor')], string='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('Generation Date', readonly=True) - file = fields.Binary('SEPA XML File', readonly=True) - filename = fields.Char(string='Filename', size=256, readonly=True, - compute=_generate_filename) - state = fields.Selection([('draft', 'Draft'), ('sent', 'Sent')], - string='State', readonly=True, default='draft') diff --git a/account_banking_sepa_credit_transfer/security/ir.model.access.csv b/account_banking_sepa_credit_transfer/security/ir.model.access.csv deleted file mode 100644 index 96fda5eec..000000000 --- a/account_banking_sepa_credit_transfer/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_sepa","Full access on banking.export.sepa","model_banking_export_sepa","account_payment.group_account_payment",1,1,1,1 diff --git a/account_banking_sepa_credit_transfer/views/account_banking_sepa_view.xml b/account_banking_sepa_credit_transfer/views/account_banking_sepa_view.xml deleted file mode 100644 index a5896c757..000000000 --- a/account_banking_sepa_credit_transfer/views/account_banking_sepa_view.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - account.banking.export.sepa.form - banking.export.sepa - -
-
- -
- - - - - - - - - - - - - - - - -
-
-
- - - - account.banking.export.sepa.tree - banking.export.sepa - - - - - - - - - - - - - SEPA Credit Transfer Files - banking.export.sepa - form - tree,form - - - - - - - -
-
diff --git a/account_banking_sepa_credit_transfer/wizard/export_sepa.py b/account_banking_sepa_credit_transfer/wizard/export_sepa.py index c9e941e54..100e626e8 100644 --- a/account_banking_sepa_credit_transfer/wizard/export_sepa.py +++ b/account_banking_sepa_credit_transfer/wizard/export_sepa.py @@ -1,8 +1,8 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# SEPA Credit Transfer module for OpenERP -# Copyright (C) 2010-2013 Akretion (http://www.akretion.com) +# SEPA Credit Transfer module for Odoo +# Copyright (C) 2010-2015 Akretion (http://www.akretion.com) # @author: Alexis de Lattre # # This program is free software: you can redistribute it and/or modify @@ -56,19 +56,14 @@ class BankingExportSepaWizard(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.sepa', 'SEPA XML 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_sepa_payorders_rel', 'wizard_id', 'payment_order_id', 'Payment Orders', readonly=True), @@ -132,9 +127,9 @@ class BankingExportSepaWizard(orm.TransientModel): 'name_maxsize': name_maxsize, 'convert_to_ascii': convert_to_ascii, 'payment_method': 'TRF', + 'file_prefix': 'sct_', 'pain_flavor': pain_flavor, 'sepa_export': sepa_export, - 'file_obj': self.pool['banking.export.sepa'], 'pain_xsd_file': 'account_banking_sepa_credit_transfer/data/%s.xsd' % pain_flavor, @@ -256,13 +251,6 @@ class BankingExportSepaWizard(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['banking.export.sepa'].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 file: send the done signal to all payment orders in the file. With the default workflow, they will @@ -271,9 +259,13 @@ class BankingExportSepaWizard(orm.TransientModel): reconciliation. """ sepa_export = self.browse(cr, uid, ids[0], context=context) - self.pool['banking.export.sepa'].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) - return {'type': 'ir.actions.act_window_close'} + 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) + return True diff --git a/account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml b/account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml index c85acf454..38ab4b7a1 100644 --- a/account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml +++ b/account_banking_sepa_credit_transfer/wizard/export_sepa_view.xml @@ -1,6 +1,6 @@ @@ -11,7 +11,7 @@ banking.export.sepa.wizard.view banking.export.sepa.wizard -
+ @@ -25,9 +25,8 @@