Merge lp:~akretion-team/banking-addons/account_statement_base_import_conversion_dict into lp:banking-addons/bank-statement-reconcile-70

Proposed by Florian da Costa
Status: Needs review
Proposed branch: lp:~akretion-team/banking-addons/account_statement_base_import_conversion_dict
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 56 lines (+11/-10)
2 files modified
account_statement_base_import/parser/file_parser.py (+3/-9)
account_statement_base_import/parser/generic_file_parser.py (+8/-1)
To merge this branch: bzr merge lp:~akretion-team/banking-addons/account_statement_base_import_conversion_dict
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) Approve
Pedro Manuel Baeza code review Approve
Guewen Baconnier @ Camptocamp Needs Fixing
Joël Grand-Guillaume @ camptocamp code review, no tests Needs Fixing
Sébastien BEAU - http://www.akretion.com code review, no test Approve
Virgil Dupras Pending
Review via email: mp+198235@code.launchpad.net

Description of the change

The conversion dict is displaced from the file_parser to the generic_parser in order to avoid the error of the validate function when creating a new parser which does not contain the 4 basc fields (ref, amount, date, label).

To post a comment you must log in.
104. By Florian da Costa

[FIX] fix init function definition in order it works with conversion_dict

105. By Florian da Costa

Remove useless code

Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

I approve this merge.
Note the key "extra_fields" have been introduced here : http://bazaar.launchpad.net/~banking-addons-team/banking-addons/bank-statement-reconcile-70/revision/94#account_statement_base_import/parser/file_parser.py
I thinks it's better to come back with the convertion_dict because the FileParser is an abstract Parser for file, and can be reuse in many case (Paypal, Atos, Paybox...). So the convert dict depend of the implementation of the Parser and can not be generic

review: Approve (code review, no test)
Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

Hum, I read to fast.
The import of "float_or_zero" is missing in the generic_parser.

Add
"""
from openerp.addons.account_statement_base_import.parser.file_parser.py import float_or_zero
"""

Also test the generic import in order to be sure that everything is ok

review: Needs Fixing
106. By Florian da Costa

[FIX] Import float_or_zero function in generic_parser (goes with the 2 previous commits)

107. By Florian da Costa

[FIX] Fix previous import

Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

It's ok for me now

review: Approve (code review, no test)
Revision history for this message
Florian da Costa (florian-dacosta) wrote :

I have tested the generic parser with a basic CSV file and it seems to work properly.

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

Hi,

Thanks for the contribs !

 * Line 57 miss spaces after comma (PEP8)

Otherwise, I would like to have Virgil Dupras and Guewen opinions on that one, I'm a bit affraid that we might break some code by changing the keyword argument from extra_field to conversion_dict.

For that main reason I set as need information.

review: Needs Fixing (code review, no tests)
108. By Florian da Costa

[FIX] miss space after comma (PEP8)

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Why renaming the keyword argument extra_field in a not backward compatible manner?
I think it is unnecessary.

review: Needs Fixing
109. By Florian da Costa

[FIX] Replace conversion_dict by extra_fields

Revision history for this message
Florian da Costa (florian-dacosta) wrote :

Well, the self.conversion_dict is initialized in the file_parser by the argument coming from the generic parser, that's why I don't understand why we are talking of "extra" fields.

And the name's changement comes from a recent commit :
http://bazaar.launchpad.net/~banking-addons-team/banking-addons/bank-statement-reconcile-70/revision/94#account_statement_base_import/parser/file_parser.py

I thought it was a mistake.

I re-changed the keword argument for extra_field, is it ok now?

Revision history for this message
Florian da Costa (florian-dacosta) wrote :

Is it possible to have news for this MP?

I guess the name of the keyword is not important to me, it can be extra_field.
The important thing is to move the conversion_dict containing the file's fields from file_parser to generic parser.
Because, the goal of the file_parser is not to parse a particular file mais should be used for files very differents which could eventually not contain 'ref', 'label', 'amount'... right?

So the fields'name of the file should always be in the custom parser (or generic parser).

Or maybe I mis-understood the goal of these parsers.
Thanks

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

Hi, Florian, I see your changes correct now, so I give my appoval.

Thanks.

Regards.

review: Approve (code review)
Revision history for this message
Florian da Costa (florian-dacosta) wrote :

Guewen and Joël, does it seem ok for you now?

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

LGTM

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

This project is now hosted on https://github.com/OCA/bank-statement-reconcile. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

Unmerged revisions

109. By Florian da Costa

[FIX] Replace conversion_dict by extra_fields

108. By Florian da Costa

[FIX] miss space after comma (PEP8)

107. By Florian da Costa

[FIX] Fix previous import

106. By Florian da Costa

[FIX] Import float_or_zero function in generic_parser (goes with the 2 previous commits)

105. By Florian da Costa

Remove useless code

104. By Florian da Costa

[FIX] fix init function definition in order it works with conversion_dict

103. By Florian da Costa

[FIX] conversion_dict is now created in the generic parser in order to allow other parsers not to use file with ref, label, date, and amount keys.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_statement_base_import/parser/file_parser.py'
--- account_statement_base_import/parser/file_parser.py 2013-11-06 17:27:53 +0000
+++ account_statement_base_import/parser/file_parser.py 2014-01-31 12:14:31 +0000
@@ -42,7 +42,7 @@
42 """42 """
43 :param char: parse_name: The name of the parser43 :param char: parse_name: The name of the parser
44 :param char: ftype: extension of the file (could be csv or xls)44 :param char: ftype: extension of the file (could be csv or xls)
45 :param dict: extra_fields: extra fields to add to the conversion dict. In the format45 :param dict: extra_fields: extra fields to put into the conversion dict. In the format
46 {fieldname: fieldtype}46 {fieldname: fieldtype}
47 :param list: header : specify header fields if the csv file has no header47 :param list: header : specify header fields if the csv file has no header
48 """48 """
@@ -53,14 +53,8 @@
53 else:53 else:
54 raise except_osv(_('User Error'),54 raise except_osv(_('User Error'),
55 _('Invalid file type %s. Please use csv or xls') % ftype)55 _('Invalid file type %s. Please use csv or xls') % ftype)
56 self.conversion_dict = {56 self.conversion_dict = extra_fields
57 'ref': unicode,57
58 'label': unicode,
59 'date': datetime.datetime,
60 'amount': float_or_zero,
61 }
62 if extra_fields:
63 self.conversion_dict.update(extra_fields)
64 self.keys_to_validate = self.conversion_dict.keys()58 self.keys_to_validate = self.conversion_dict.keys()
65 self.fieldnames = header59 self.fieldnames = header
66 self._datemode = 0 # used only for xls documents,60 self._datemode = 0 # used only for xls documents,
6761
=== modified file 'account_statement_base_import/parser/generic_file_parser.py'
--- account_statement_base_import/parser/generic_file_parser.py 2013-05-03 19:57:26 +0000
+++ account_statement_base_import/parser/generic_file_parser.py 2014-01-31 12:14:31 +0000
@@ -24,6 +24,7 @@
24import tempfile24import tempfile
25import datetime25import datetime
26from file_parser import FileParser26from file_parser import FileParser
27from openerp.addons.account_statement_base_import.parser.file_parser import float_or_zero
27try:28try:
28 import xlrd29 import xlrd
29except:30except:
@@ -38,7 +39,13 @@
38 """39 """
3940
40 def __init__(self, parse_name, ftype='csv', **kwargs):41 def __init__(self, parse_name, ftype='csv', **kwargs):
41 super(GenericFileParser, self).__init__(parse_name, ftype=ftype, **kwargs)42 conversion_dict = {
43 'ref': unicode,
44 'label': unicode,
45 'date': datetime.datetime,
46 'amount': float_or_zero,
47 }
48 super(GenericFileParser, self).__init__(parse_name, ftype=ftype, extra_fields=conversion_dict, **kwargs)
4249
43 @classmethod50 @classmethod
44 def parser_for(cls, parser_name):51 def parser_for(cls, parser_name):

Subscribers

People subscribed via source and target branches