mirror of
				https://github.com/brain-tec/account_ebics.git
				synced 2025-11-04 07:00:35 +00:00 
			
		
		
		
	improved support empty statements and oca camt parser
This commit is contained in:
		@@ -1,9 +1,9 @@
 | 
			
		||||
# Copyright 2009-2018 Noviat.
 | 
			
		||||
# Copyright 2009-2019 Noviat.
 | 
			
		||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    'name': 'EBICS banking protocol',
 | 
			
		||||
    'version': '11.0.1.5.0',
 | 
			
		||||
    'version': '11.0.1.6.0',
 | 
			
		||||
    'license': 'AGPL-3',
 | 
			
		||||
    'author': 'Noviat',
 | 
			
		||||
    'category': 'Accounting & Finance',
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
# Copyright 2009-2018 Noviat.
 | 
			
		||||
# Copyright 2009-2019 Noviat.
 | 
			
		||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
@@ -288,7 +288,7 @@ class EbicsConfig(models.Model):
 | 
			
		||||
            user = EbicsUser(
 | 
			
		||||
                keyring=keyring, partnerid=self.ebics_partner,
 | 
			
		||||
                userid=self.ebics_user)
 | 
			
		||||
        except:
 | 
			
		||||
        except Exception:
 | 
			
		||||
            exctype, value = exc_info()[:2]
 | 
			
		||||
            error = _("EBICS Initialisation Error:")
 | 
			
		||||
            error += '\n' + str(exctype) + '\n' + str(value)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
# Copyright 2009-2018 Noviat.
 | 
			
		||||
# Copyright 2009-2019 Noviat.
 | 
			
		||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
@@ -136,7 +136,7 @@ class EbicsFile(models.Model):
 | 
			
		||||
 | 
			
		||||
    def _check_import_module(self, module):
 | 
			
		||||
        mod = self.env['ir.module.module'].search(
 | 
			
		||||
            [('name', '=', module),
 | 
			
		||||
            [('name', '=like', module),
 | 
			
		||||
             ('state', '=', 'installed')])
 | 
			
		||||
        if not mod:
 | 
			
		||||
            raise UserError(_(
 | 
			
		||||
@@ -207,14 +207,15 @@ class EbicsFile(models.Model):
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def _process_camt053(self):
 | 
			
		||||
        import_module = 'account_bank_statement_import_camt'
 | 
			
		||||
        import_module = 'account_bank_statement_import_camt%'
 | 
			
		||||
        self._check_import_module(import_module)
 | 
			
		||||
        wiz_model = 'account.bank.statement.import'
 | 
			
		||||
        wiz_vals = {
 | 
			
		||||
            'data_file': self.data,
 | 
			
		||||
            'filename': self.name,
 | 
			
		||||
        }
 | 
			
		||||
        wiz = self.env[wiz_model].create(wiz_vals)
 | 
			
		||||
        ctx = dict(self.env.context, active_model='ebics.file')
 | 
			
		||||
        wiz = self.env[wiz_model].with_context(ctx).create(wiz_vals)
 | 
			
		||||
        res = wiz.import_file()
 | 
			
		||||
        if res.get('res_model') \
 | 
			
		||||
                == 'account.bank.statement.import.journal.creation':
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
# Copyright 2009-2018 Noviat.
 | 
			
		||||
# Copyright 2009-2019 Noviat.
 | 
			
		||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
@@ -32,7 +32,7 @@ except RuntimeError as e:
 | 
			
		||||
    else:
 | 
			
		||||
        _logger.error(e.message)
 | 
			
		||||
        fintech.register()
 | 
			
		||||
except:
 | 
			
		||||
except Exception:
 | 
			
		||||
    msg = "fintech.register error"
 | 
			
		||||
    tb = ''.join(format_exception(*exc_info()))
 | 
			
		||||
    msg += '\n%s' % tb
 | 
			
		||||
 
 | 
			
		||||
@@ -64,6 +64,7 @@
 | 
			
		||||
                  type="object"
 | 
			
		||||
                  groups="account.group_account_manager"
 | 
			
		||||
                  help="Process the EBICS File"/>
 | 
			
		||||
          <button name="set_to_done" states="draft" string="Set to Done" type="object" groups="account.group_account_manager"/>
 | 
			
		||||
          <field name="state" widget="statusbar"/>
 | 
			
		||||
        </header>
 | 
			
		||||
        <group colspan="4" col="4">
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,3 @@
 | 
			
		||||
from . import account_bank_statement_import
 | 
			
		||||
from . import ebics_change_passphrase
 | 
			
		||||
from . import ebics_xfer
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										62
									
								
								account_ebics/wizard/account_bank_statement_import.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								account_ebics/wizard/account_bank_statement_import.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
# Copyright 2009-2019 Noviat.
 | 
			
		||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from odoo import models, _
 | 
			
		||||
 | 
			
		||||
_logger = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AccountBankStatementImport(models.TransientModel):
 | 
			
		||||
    _inherit = 'account.bank.statement.import'
 | 
			
		||||
 | 
			
		||||
    def _check_parsed_data(self, stmts_vals):
 | 
			
		||||
        """ Basic and structural verifications """
 | 
			
		||||
        if self.env.context.get('active_model') == 'ebics.file':
 | 
			
		||||
            message = False
 | 
			
		||||
            if len(stmts_vals) == 0:
 | 
			
		||||
                message = _('This file doesn\'t contain any statement.')
 | 
			
		||||
            if not message:
 | 
			
		||||
                no_st_line = True
 | 
			
		||||
                for vals in stmts_vals:
 | 
			
		||||
                    if vals['transactions'] and len(vals['transactions']) > 0:
 | 
			
		||||
                        no_st_line = False
 | 
			
		||||
                        break
 | 
			
		||||
                if no_st_line:
 | 
			
		||||
                    message = _('This file doesn\'t contain any transaction.')
 | 
			
		||||
                if message:
 | 
			
		||||
                    log_msg = _(
 | 
			
		||||
                        "Error detected while processing and EBICS File"
 | 
			
		||||
                    ) + ':\n' + message
 | 
			
		||||
                    _logger.warn(log_msg)
 | 
			
		||||
                    return
 | 
			
		||||
        super()._check_parsed_data(stmts_vals)
 | 
			
		||||
 | 
			
		||||
    def _create_bank_statements(self, stmts_vals):
 | 
			
		||||
        """
 | 
			
		||||
        Return error message to ebics.file when handling empty camt.
 | 
			
		||||
 | 
			
		||||
        Remarks/TODO:
 | 
			
		||||
        We could add more info to the message (e.g. date, balance, ...)
 | 
			
		||||
        and write this to the ebics.file, note field.
 | 
			
		||||
        We could also create empty bank statement (in state done) to clearly
 | 
			
		||||
        show days without transactions via the bank statement list view.
 | 
			
		||||
        """
 | 
			
		||||
        if self.env.context.get('active_model') == 'ebics.file':
 | 
			
		||||
            transactions = False
 | 
			
		||||
            for st_vals in stmts_vals:
 | 
			
		||||
                if st_vals.get('transactions'):
 | 
			
		||||
                    transactions = True
 | 
			
		||||
                    break
 | 
			
		||||
            if not transactions:
 | 
			
		||||
                message = _('This file doesn\'t contain any transaction.')
 | 
			
		||||
                statement_ids = []
 | 
			
		||||
                notifications = {
 | 
			
		||||
                    'type': 'warning',
 | 
			
		||||
                    'message': message,
 | 
			
		||||
                    'details': ''
 | 
			
		||||
                }
 | 
			
		||||
                return statement_ids, [notifications]
 | 
			
		||||
 | 
			
		||||
        return super()._create_bank_statements(stmts_vals)
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
# Copyright 2009-2018 Noviat.
 | 
			
		||||
# Copyright 2009-2019 Noviat.
 | 
			
		||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
# Copyright 2009-2018 Noviat.
 | 
			
		||||
# Copyright 2009-2019 Noviat.
 | 
			
		||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
@@ -199,7 +199,7 @@ class EbicsXfer(models.TransientModel):
 | 
			
		||||
                    self.note += _("Warning:")
 | 
			
		||||
                    self.note += '\n'
 | 
			
		||||
                    self.note += e.message
 | 
			
		||||
                except:
 | 
			
		||||
                except Exception:
 | 
			
		||||
                    self.note += '\n'
 | 
			
		||||
                    self.note += _("Unknown Error")
 | 
			
		||||
                    tb = ''.join(format_exception(*exc_info()))
 | 
			
		||||
@@ -321,7 +321,7 @@ class EbicsXfer(models.TransientModel):
 | 
			
		||||
                self.note += _("EBICS Verification Error:")
 | 
			
		||||
                self.note += '\n'
 | 
			
		||||
                self.note += _("The EBICS response could not be verified.")
 | 
			
		||||
            except:
 | 
			
		||||
            except Exception:
 | 
			
		||||
                self.note += '\n'
 | 
			
		||||
                self.note += _("Unknown Error")
 | 
			
		||||
                tb = ''.join(format_exception(*exc_info()))
 | 
			
		||||
@@ -359,7 +359,7 @@ class EbicsXfer(models.TransientModel):
 | 
			
		||||
        try:
 | 
			
		||||
            client = EbicsClient(
 | 
			
		||||
                bank, user, version=self.ebics_config_id.ebics_version)
 | 
			
		||||
        except:
 | 
			
		||||
        except Exception:
 | 
			
		||||
            self.note += '\n'
 | 
			
		||||
            self.note += _("Unknown Error")
 | 
			
		||||
            tb = ''.join(format_exception(*exc_info()))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user