From e4c5016dc32efa1284b796e6b58564ebac811f7f 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 --- .../__openerp__.py | 9 +-- .../models/__init__.py | 3 +- .../models/account_banking_sepa.py | 80 ------------------- .../security/ir.model.access.csv | 2 - .../views/account_banking_sepa_view.xml | 77 ------------------ .../wizard/export_sepa.py | 45 +++++------ .../wizard/export_sepa_view.xml | 7 +- 7 files changed, 25 insertions(+), 198 deletions(-) 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/__openerp__.py b/account_banking_sepa_credit_transfer/__openerp__.py index 506310486..6e5a69fbd 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/models/__init__.py b/account_banking_sepa_credit_transfer/models/__init__.py index 90e481210..bbec915f3 100644 --- a/account_banking_sepa_credit_transfer/models/__init__.py +++ b/account_banking_sepa_credit_transfer/models/__init__.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# SEPA Credit Transfer module for OpenERP +# SEPA Credit Transfer module for Odoo # Copyright (C) 2010-2013 Akretion (http://www.akretion.com) # @author: Alexis de Lattre # @@ -20,4 +20,3 @@ # ############################################################################## -from . import account_banking_sepa 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..01c1fcb2d 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,14 @@ 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) + payment_order_ids = [] 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 @@