Merge lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-import-statement-hook into lp:banking-addons/bank-statement-reconcile-70

Proposed by Laurent Mignon (Acsone)
Status: Merged
Approved by: Pedro Manuel Baeza
Approved revision: 113
Merged at revision: 116
Proposed branch: lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-import-statement-hook
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 202 lines (+36/-49)
4 files modified
account_statement_base_completion/statement.py (+4/-5)
account_statement_base_import/parser/parser.py (+13/-32)
account_statement_base_import/statement.py (+14/-11)
account_statement_commission/commission.py (+5/-1)
To merge this branch: bzr merge lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-import-statement-hook
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Approve
Review via email: mp+203127@code.launchpad.net

This proposal supersedes a proposal from 2014-01-15.

Description of the change

Hi,

In some cases, the imported file may contains information about the account.bank.statement.
The proposal add a new method 'get_st_vals' on the 'BankStatementImportParser' that can be used to provide statement info from the parsed file and a new method 'prepare_statement_vals' on 'AccountStatementProfil' that fills the statement values with the profile_id and the result to the call to the new method on the parser.

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote : Posted in a previous version of this proposal

Hi, Laurent, very interesting and needed changes!

I was to say that you have made the MP to the wrong branch, but you corrected at the moment!

I have checked the code, and the solution seems perfect for Spain, where I'm adopting national standard statement format in 7.0 to these addons, and there is information about start and end date of the statement in the file that must be dumped.

Regards.

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

Hi, Laurent,

Checking pending MPs, I have found that there is already an MP that issues this problem in a similar way:

https://code.launchpad.net/~akretion-team/banking-addons/bank-statement-reconcile-70-improve-import/+merge/197759

So I'm going to put this as rejected and let the other MP continues. Please review it to contribute with your comments.

Regards.

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

> Hi, Laurent,
>
> Checking pending MPs, I have found that there is already an MP that issues
> this problem in a similar way:
>
> https://code.launchpad.net/~akretion-team/banking-addons/bank-statement-
> reconcile-70-improve-import/+merge/197759
>
> So I'm going to put this as rejected and let the other MP continues. Please
> review it to contribute with your comments.
>
> Regards.

Hi,

Thanks for the review and the link to the other proposal. I'm a little bit disappointed by your decision. I've the feeling that the proposed approach is more generic that the one proposed by akretion-team.

In the other proposal, it's not the responsibility of the parser to provide additional values to the statement creation. So if I want to provide an other value from the parser to statement (ex the date), I need to override the statement profile. My point of view is that's the responsibility of the parser to provide values for statement and statement line creation. The profile is just there to make the glue between the parser and the logic. What do you think?

Regards

lmi

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : Posted in a previous version of this proposal

In a way other MP was created and Approved before this one. So disapproving this one seems fair.

However, your changes and improvements are welcome.

Sorry that it wasn't noticed by anybody before. BTW good catch Pedro

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

Sorry Laurent if I bother you. Please contribute now with a new MP over the merge changes with your improvements, that indeed are good ones! I want to make a new MP tonight, but I think it's better that you make it and get credited.

Regards.

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

Now I see redundant to add two methods for the same purpose: get_st_vals and prepare_statement_vals. Do you agree to merge both on one? If you do, I will make inmediately an exceptional merge to fix the mess I did merging the other one without consensus.

Regards.

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

Hi Pedro and once again thanks for the review.
> Now I see redundant to add two methods for the same purpose: get_st_vals and
> prepare_statement_vals. Do you agree to merge both on one?
The change mirrors the approach for statement lines with the same approach for the statement.
* on the parser we have 'get_st_line_vals' vs 'get_st_vals'
* on the account.statement.profile we have 'prepare_statetement_lines_vals' vs 'prepare_statement_vals'
The motivation behind the 'prepare_statement_vals' is to make a place where it's possible to complete/validate data from the parser in the context of Openerp without overriding the 'statement_import' method. Take a look at the profile developed to import statement files specific to Belgium http://bazaar.launchpad.net/~acsone-openerp/+junk/coda-completion/view/head:/account_statement_coda_import/statement.py#L84 . I think it's a good illustration of the motivation behind the 'prepare_statement_val'. What do you think?

Regards,

Laurent Mignon

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

Hi, I proceed then with the merge. Sorry for the past inconveniences.

Regards.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_statement_base_completion/statement.py'
--- account_statement_base_completion/statement.py 2014-01-23 08:44:24 +0000
+++ account_statement_base_completion/statement.py 2014-01-24 17:16:24 +0000
@@ -184,7 +184,7 @@
184 inv = self._find_invoice(cr, uid, line, inv_type, context=context)184 inv = self._find_invoice(cr, uid, line, inv_type, context=context)
185 if inv:185 if inv:
186 # FIXME use only commercial_partner_id of invoice in 7.1186 # FIXME use only commercial_partner_id of invoice in 7.1
187 # this is for backward compatibility in 7.0 before 187 # this is for backward compatibility in 7.0 before
188 # the refactoring of res.partner188 # the refactoring of res.partner
189 if hasattr(inv, 'commercial_partner_id'):189 if hasattr(inv, 'commercial_partner_id'):
190 partner_id = inv.commercial_partner_id.id190 partner_id = inv.commercial_partner_id.id
@@ -418,7 +418,7 @@
418 """418 """
419 statement_line_obj = self.pool['account.bank.statement.line']419 statement_line_obj = self.pool['account.bank.statement.line']
420 model_cols = statement_line_obj._columns420 model_cols = statement_line_obj._columns
421 sparse_fields = dict([(k , col) for k, col in model_cols.iteritems() if isinstance(col, fields.sparse) and col._type == 'char'])421 sparse_fields = dict([(k, col) for k, col in model_cols.iteritems() if isinstance(col, fields.sparse) and col._type == 'char'])
422 values = []422 values = []
423 for statement in statement_store:423 for statement in statement_store:
424 to_json_k = set()424 to_json_k = set()
@@ -429,10 +429,9 @@
429 serialized = st_copy.setdefault(col.serialization_field, {})429 serialized = st_copy.setdefault(col.serialization_field, {})
430 serialized[k] = st_copy[k]430 serialized[k] = st_copy[k]
431 for k in to_json_k:431 for k in to_json_k:
432 st_copy[k] = simplejson.dumps(st_copy[k])432 st_copy[k] = simplejson.dumps(st_copy[k])
433 values.append(st_copy)433 values.append(st_copy)
434 return values434 return values
435
436435
437 def _insert_lines(self, cr, uid, statement_store, context=None):436 def _insert_lines(self, cr, uid, statement_store, context=None):
438 """ Do raw insert into database because ORM is awfully slow437 """ Do raw insert into database because ORM is awfully slow
@@ -456,7 +455,7 @@
456 when cheking security.455 when cheking security.
457 TODO / WARM: sparse fields are skipped by the method. IOW, if your456 TODO / WARM: sparse fields are skipped by the method. IOW, if your
458 completion rule update an sparse field, the updated value will never457 completion rule update an sparse field, the updated value will never
459 be stored in the database. It would be safer to call the update method 458 be stored in the database. It would be safer to call the update method
460 from the ORM for records updating this kind of fields.459 from the ORM for records updating this kind of fields.
461 """460 """
462 cols = self._get_available_columns([vals])461 cols = self._get_available_columns([vals])
463462
=== modified file 'account_statement_base_import/parser/parser.py'
--- account_statement_base_import/parser/parser.py 2013-12-11 19:11:44 +0000
+++ account_statement_base_import/parser/parser.py 2014-01-24 17:16:24 +0000
@@ -20,7 +20,6 @@
20##############################################################################20##############################################################################
21import base6421import base64
22import csv22import csv
23from datetime import datetime
2423
2524
26def UnicodeDictReader(utf8_data, **kwargs):25def UnicodeDictReader(utf8_data, **kwargs):
@@ -115,6 +114,19 @@
115 """114 """
116 return NotImplementedError115 return NotImplementedError
117116
117 def get_st_vals(self):
118 """
119 This method return a dict of vals that ca be passed to
120 create method of statement.
121 :return: dict of vals that represent additional infos for the statement
122 """
123 return {
124 'name': self.statement_name,
125 'balance_start': self.balance_start,
126 'balance_end_real': self.balance_end,
127 'date': self.statement_date
128 }
129
118 def get_st_line_vals(self, line, *args, **kwargs):130 def get_st_line_vals(self, line, *args, **kwargs):
119 """131 """
120 Implement a method in your parser that must return a dict of vals that can be132 Implement a method in your parser that must return a dict of vals that can be
@@ -155,37 +167,6 @@
155 self._post(*args, **kwargs)167 self._post(*args, **kwargs)
156 return self.result_row_list168 return self.result_row_list
157169
158 def get_start_balance(self, *args, **kwargs):
159 """
160 This is called by the importation method to set the balance start
161 amount in the bank statement.
162 return: float of the balance start (self.balance_start)
163 """
164 return self.balance_start
165
166 def get_end_balance(self, *args, **kwargs):
167 """
168 This is called by the importation method to set the balance end
169 amount in the bank statement.
170 return: float of the balance end (self.balance_end)
171 """
172 return self.balance_end
173
174 def get_statement_name(self, *args, **kwargs):
175 """
176 This is called by the importation method to set the statement
177 name in the bank statement.
178 return: string of the statement name (self.statement_name)
179 """
180 return self.statement_name or '/'
181
182 def get_statement_date(self, *args, **kwargs):
183 """
184 This is called by the importation method to set the statement
185 date in the bank statement.
186 return: datetime of the statement date (self.statement_date)
187 """
188 return self.statement_date or datetime.now()
189170
190def itersubclasses(cls, _seen=None):171def itersubclasses(cls, _seen=None):
191 """172 """
192173
=== modified file 'account_statement_base_import/statement.py'
--- account_statement_base_import/statement.py 2013-12-04 17:39:04 +0000
+++ account_statement_base_import/statement.py 2014-01-24 17:16:24 +0000
@@ -90,7 +90,7 @@
90 statement_id, context):90 statement_id, context):
91 """91 """
92 Hook to build the values of a line from the parser returned values. At92 Hook to build the values of a line from the parser returned values. At
93 least it fullfill the statement_id and account_id. Overide it to add your93 least it fullfill the statement_id and account_id. Override it to add your
94 own completion if needed.94 own completion if needed.
9595
96 :param dict of vals from parser for account.bank.statement.line (called by96 :param dict of vals from parser for account.bank.statement.line (called by
@@ -126,14 +126,14 @@
126 values['type'] = 'general'126 values['type'] = 'general'
127 return values127 return values
128128
129129 def prepare_statement_vals(self, cr, uid, profile_id, result_row_list, parser, context):
130 def _prepare_statement_vals(self, cr, uid, prof, parser, context=None):130 """
131 return {131 Hook to build the values of the statement from the parser and
132 'profile_id': prof.id,132 the profile.
133 'name': parser.get_statement_name(),133 """
134 'balance_start': parser.get_start_balance(),134 vals = {'profile_id': profile_id}
135 'balance_end_real': parser.get_end_balance(),135 vals.update(parser.get_st_vals())
136 }136 return vals
137137
138 def statement_import(self, cr, uid, ids, profile_id, file_stream, ftype="csv", context=None):138 def statement_import(self, cr, uid, ids, profile_id, file_stream, ftype="csv", context=None):
139 """139 """
@@ -168,8 +168,11 @@
168 _("Column %s you try to import is not "168 _("Column %s you try to import is not "
169 "present in the bank statement line!") % col)169 "present in the bank statement line!") % col)
170170
171 st_vals = self._prepare_statement_vals(cr, uid, prof, parser, context=context) 171 statement_vals = self.prepare_statement_vals(cr, uid, prof.id, result_row_list, parser, context)
172 statement_id = statement_obj.create(cr, uid, st_vals, context=context)172 statement_id = statement_obj.create(cr, uid,
173 statement_vals,
174 context=context)
175
173 if prof.receivable_account_id:176 if prof.receivable_account_id:
174 account_receivable = account_payable = prof.receivable_account_id.id177 account_receivable = account_payable = prof.receivable_account_id.id
175 else:178 else:
176179
=== modified file 'account_statement_commission/commission.py'
--- account_statement_commission/commission.py 2013-12-04 14:14:56 +0000
+++ account_statement_commission/commission.py 2014-01-24 17:16:24 +0000
@@ -2,9 +2,11 @@
2import datetime2import datetime
3from openerp.osv import orm, fields3from openerp.osv import orm, fields
44
5
5def float_or_zero(val):6def float_or_zero(val):
6 return float(val) if val else 0.07 return float(val) if val else 0.0
78
9
8class AccountStatementProfil(orm.Model):10class AccountStatementProfil(orm.Model):
9 _inherit = "account.statement.profile"11 _inherit = "account.statement.profile"
1012
@@ -22,7 +24,7 @@
22 commission_analytic_id = profile.commission_analytic_id and profile.commission_analytic_id.id or False24 commission_analytic_id = profile.commission_analytic_id and profile.commission_analytic_id.id or False
23 comm_values = {25 comm_values = {
24 'name': 'IN ' + _('Commission line'),26 'name': 'IN ' + _('Commission line'),
25 'date': parser.get_statement_date(),27 'date': parser.get_st_vals().get('date') or datetime.datetime.now(),
26 'amount': global_commission_amount,28 'amount': global_commission_amount,
27 'partner_id': partner_id,29 'partner_id': partner_id,
28 'type': 'general',30 'type': 'general',
@@ -36,6 +38,7 @@
36 statement_line_obj = self.pool.get('account.bank.statement.line')38 statement_line_obj = self.pool.get('account.bank.statement.line')
37 statement_line_obj.create(cr, uid, comm_values, context=context)39 statement_line_obj.create(cr, uid, comm_values, context=context)
3840
41
39class AccountStatementLineWithCommission(orm.Model):42class AccountStatementLineWithCommission(orm.Model):
40 _inherit = "account.bank.statement.line"43 _inherit = "account.bank.statement.line"
41 _columns = {44 _columns = {
@@ -45,6 +48,7 @@
45 serialization_field='additionnal_bank_fields'),48 serialization_field='additionnal_bank_fields'),
46 }49 }
4750
51
48class CreditPartnerStatementImporter(orm.TransientModel):52class CreditPartnerStatementImporter(orm.TransientModel):
49 _inherit = "credit.statement.import"53 _inherit = "credit.statement.import"
5054

Subscribers

People subscribed via source and target branches