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

Proposed by Pedro Manuel Baeza
Status: Rejected
Rejected by: Pedro Manuel Baeza
Proposed branch: lp:~pedro.baeza/banking-addons/7.0-bank-statement-reconcile-prof_parsing
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 98 lines (+15/-20)
4 files modified
account_statement_base_import/parser/parser.py (+11/-9)
account_statement_base_import/statement.py (+1/-1)
account_statement_ofx_import/parser/ofx_parser.py (+1/-8)
account_statement_transactionid_import/parser/transactionid_file_parser.py (+2/-2)
To merge this branch: bzr merge lp:~pedro.baeza/banking-addons/7.0-bank-statement-reconcile-prof_parsing
Reviewer Review Type Date Requested Status
Joël Grand-Guillaume @ camptocamp code review, no tests Approve
Yannick Vaucher @ Camptocamp code review, no test Needs Fixing
Laurent Mignon (Acsone) (community) code review, no tests Approve
Review via email: mp+218991@code.launchpad.net

This proposal supersedes a proposal from 2014-04-05.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : Posted in a previous version of this proposal

Next time someone review this module, he will wander why prof is passed to parser and why it is unused.

You should at least add a comment if you don't want it to be removed. Otherwise you should create a hook.

review: Needs Fixing
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote : Posted in a previous version of this proposal

Hi, Yannick,

I have added a comment to explain the purpose of prof variable.

Thanks for you review.

Regards.

Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote : Posted in a previous version of this proposal

Hi,

Why not spend the profile to the parser factory in place of to the parse method?

Regards,

lmi

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote : Posted in a previous version of this proposal

I have made it in this way to make little changes, but that can be another solution. What do you prefer?

Regards.

Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote : Posted in a previous version of this proposal

I'm a little bit uneasy with the proposed merge since part of the profile information is spend to the parser factory (import_type) and the profile itself to the parse method. We can imagine use cases where information from the profile could be required to initialize the parser. I would prefer to spent the profile object at the earlier to the parser.
It's just my point of view ...

Regards

> I have made it in this way to make little changes, but that can be another
> solution. What do you prefer?
>
> Regards.

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : Posted in a previous version of this proposal

Hi Pedro,

Thanks for the contrib. After thinking about, I must admit I'm in favor of Laurent's suggestion here. Can you make the changes please ?

Regards,

review: Approve (code review, no tests)
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

I have changed the approach taking in consideration Yannick's comments. Please check it this new approach.

Regards.

Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

Hi Pedro,

Thanks for the contrib and the changes!

LGTM,

Regards,

lmi

review: Approve (code review, no tests)
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Sorry, it was Laurent's comments, not Yannick's comments.

Regards.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Doc string should be updated and signature seems wrong at l.47 parser_name is missing

Cheers.

review: Needs Fixing (code review, no test)
144. By Pedro Manuel Baeza

Docstring and change in parser factory params

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Yannick, see if this fits your requests.

Thanks for the review.

Regards.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

You must also ensure it remains compatible with child classes.

account_statement_ofx_import and account_statement_transactionid_import depends on account_statement_base_import

One inherit directly and the other indirecly from parser defined in account_statement_base_import.

145. By Pedro Manuel Baeza

Change account_statement_transactionid_import and account_statement_ofx_import accordingly.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Yannick,

That was the reason why I didn't want signature at first instance, but it doesn't matter. I have changed both modules, even cleaning a bit ofx_import, because __init__ method is not needed.

Regards.

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi Pedro,

Thanks for changing this !

LGTM,

Regards

review: Approve (code review, no tests)
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Unmerged revisions

145. By Pedro Manuel Baeza

Change account_statement_transactionid_import and account_statement_ofx_import accordingly.

144. By Pedro Manuel Baeza

Docstring and change in parser factory params

143. By Pedro Manuel Baeza

[IMP] account_statement_base_import: Profile passed and stored on parser initialisation instead of an argument for parse method

142. By Pedro Manuel Baeza

[IMP] account_statement_base_import: Comment for prof variable.

141. By Pedro Manuel Baeza

[IMP] account_statement_base_import: Allow to use profile data for customizing parsing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_statement_base_import/parser/parser.py'
2--- account_statement_base_import/parser/parser.py 2014-02-28 13:02:35 +0000
3+++ account_statement_base_import/parser/parser.py 2014-05-12 13:41:04 +0000
4@@ -42,14 +42,16 @@
5 from the FileParser instead.
6 """
7
8- def __init__(self, parser_name, *args, **kwargs):
9+ def __init__(self, profile, *args, **kwargs):
10 # The name of the parser as it will be called
11- self.parser_name = parser_name
12+ self.parser_name = profile.import_type
13 # The result as a list of row. One row per line of data in the file, but
14 # not the commission one !
15 self.result_row_list = None
16 # The file buffer on which to work on
17 self.filebuffer = None
18+ # The profile record to access its parameters in any parser method
19+ self.profile = profile
20 self.balance_start = None
21 self.balance_end = None
22 self.statement_name = None
23@@ -210,13 +212,13 @@
24 yield sub
25
26
27-def new_bank_statement_parser(parser_name, *args, **kwargs):
28- """
29- Return an instance of the good parser class base on the providen name
30- :param char: parser_name
31- :return: class instance of parser_name providen.
32+def new_bank_statement_parser(profile, *args, **kwargs):
33+ """Return an instance of the good parser class based on the given profile.
34+
35+ :param profile: browse_record of import profile.
36+ :return: class instance for given profile import type.
37 """
38 for cls in itersubclasses(BankStatementImportParser):
39- if cls.parser_for(parser_name):
40- return cls(parser_name, *args, **kwargs)
41+ if cls.parser_for(profile.import_type):
42+ return cls(profile, *args, **kwargs)
43 raise ValueError
44
45=== modified file 'account_statement_base_import/statement.py'
46--- account_statement_base_import/statement.py 2014-05-07 08:50:38 +0000
47+++ account_statement_base_import/statement.py 2014-05-12 13:41:04 +0000
48@@ -156,7 +156,7 @@
49 _("You must provide a valid profile to import a bank statement!"))
50 prof = prof_obj.browse(cr, uid, profile_id, context=context)
51
52- parser = new_bank_statement_parser(prof.import_type, ftype=ftype)
53+ parser = new_bank_statement_parser(prof, ftype=ftype)
54 result_row_list = parser.parse(file_stream)
55 # Check all key are present in account.bank.statement.line!!
56 if not result_row_list:
57
58=== modified file 'account_statement_ofx_import/parser/ofx_parser.py'
59--- account_statement_ofx_import/parser/ofx_parser.py 2013-11-04 12:22:39 +0000
60+++ account_statement_ofx_import/parser/ofx_parser.py 2014-05-12 13:41:04 +0000
61@@ -29,14 +29,7 @@
62 raise Exception(_('Please install python lib ofxparse'))
63
64 class OfxParser(BankStatementImportParser):
65- """
66- Class for defining parser for OFX file format.
67- """
68-
69- def __init__(self, parser_name, *args, **kwargs):
70- """
71- """
72- super(OfxParser, self).__init__(parser_name, *args, **kwargs)
73+ """Class for defining parser for OFX file format."""
74
75 @classmethod
76 def parser_for(cls, parser_name):
77
78=== modified file 'account_statement_transactionid_import/parser/transactionid_file_parser.py'
79--- account_statement_transactionid_import/parser/transactionid_file_parser.py 2013-11-06 15:23:49 +0000
80+++ account_statement_transactionid_import/parser/transactionid_file_parser.py 2014-05-12 13:41:04 +0000
81@@ -27,7 +27,7 @@
82 bank statement.
83 """
84
85- def __init__(self, parse_name, ftype='csv', extra_fields=None, header=None, **kwargs):
86+ def __init__(self, profile, ftype='csv', extra_fields=None, header=None, **kwargs):
87 """
88 Add transaction_id in header keys
89 :param char: parse_name: The name of the parser
90@@ -37,7 +37,7 @@
91 :param list: header : specify header fields if the csv file has no header
92 """
93 extra_fields = {'transaction_id': unicode}
94- super(TransactionIDFileParser, self).__init__(parse_name, extra_fields=extra_fields,
95+ super(TransactionIDFileParser, self).__init__(profile, extra_fields=extra_fields,
96 ftype=ftype, header=header, **kwargs)
97 # ref is replaced by transaction_id thus we delete it from check
98 self.keys_to_validate = [k for k in self.keys_to_validate if k != 'ref']

Subscribers

People subscribed via source and target branches