← Back to team overview

banking-addons-team team mailing list archive

[Merge] lp:~pedro.baeza/banking-addons/7.0-bank-statement-reconcile-prof_parsing into lp:banking-addons/bank-statement-reconcile-7.0

 

Pedro Manuel Baeza has proposed merging lp:~pedro.baeza/banking-addons/7.0-bank-statement-reconcile-prof_parsing into lp:banking-addons/bank-statement-reconcile-7.0.

Requested reviews:
  Laurent Mignon (Acsone) (lmi): code review, no tests
  Yannick Vaucher @ Camptocamp (yvaucher-c2c)
  Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c): code review, no tests

For more details, see:
https://code.launchpad.net/~pedro.baeza/banking-addons/7.0-bank-statement-reconcile-prof_parsing/+merge/218991

Simple improvement on the account_statement_base_import module to have profile data on parse method to use it to customize parsing with, for example, a parameter introduced on profiles.

There is no need to do it anything more, because parse method already contains *args and **kwargs. You can access profile data with args[0] in parse method.
-- 
https://code.launchpad.net/~pedro.baeza/banking-addons/7.0-bank-statement-reconcile-prof_parsing/+merge/218991
Your team Banking Addons Core Editors is subscribed to branch lp:banking-addons/bank-statement-reconcile-7.0.
=== modified file 'account_statement_base_import/parser/parser.py'
--- account_statement_base_import/parser/parser.py	2014-02-28 13:02:35 +0000
+++ account_statement_base_import/parser/parser.py	2014-05-09 13:51:31 +0000
@@ -42,7 +42,7 @@
     from the FileParser instead.
     """
 
-    def __init__(self, parser_name, *args, **kwargs):
+    def __init__(self, parser_name, profile, *args, **kwargs):
         # The name of the parser as it will be called
         self.parser_name = parser_name
         # The result as a list of row. One row per line of data in the file, but
@@ -50,6 +50,8 @@
         self.result_row_list = None
         # The file buffer on which to work on
         self.filebuffer = None
+        # The profile record to access its parameters in any parser method
+        self.profile = profile
         self.balance_start = None
         self.balance_end = None
         self.statement_name = None
@@ -210,7 +212,7 @@
                 yield sub
 
 
-def new_bank_statement_parser(parser_name, *args, **kwargs):
+def new_bank_statement_parser(parser_name, profile, *args, **kwargs):
     """
     Return an instance of the good parser class base on the providen name
     :param char: parser_name
@@ -218,5 +220,5 @@
     """
     for cls in itersubclasses(BankStatementImportParser):
         if cls.parser_for(parser_name):
-            return cls(parser_name, *args, **kwargs)
+            return cls(parser_name, profile, *args, **kwargs)
     raise ValueError

=== modified file 'account_statement_base_import/statement.py'
--- account_statement_base_import/statement.py	2014-05-07 08:50:38 +0000
+++ account_statement_base_import/statement.py	2014-05-09 13:51:31 +0000
@@ -156,7 +156,7 @@
                                  _("You must provide a valid profile to import a bank statement!"))
         prof = prof_obj.browse(cr, uid, profile_id, context=context)
 
-        parser = new_bank_statement_parser(prof.import_type, ftype=ftype)
+        parser = new_bank_statement_parser(prof, ftype=ftype)
         result_row_list = parser.parse(file_stream)
         # Check all key are present in account.bank.statement.line!!
         if not result_row_list:


References