diff --git a/account_statement_base_completion/__init__.py b/account_statement_base_completion/__init__.py
index f6c46966..3397bf58 100644
--- a/account_statement_base_completion/__init__.py
+++ b/account_statement_base_completion/__init__.py
@@ -19,4 +19,5 @@
#
##############################################################################
-import statement
\ No newline at end of file
+import statement
+import partner
\ No newline at end of file
diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py
index 551707ac..ef43001c 100644
--- a/account_statement_base_completion/statement.py
+++ b/account_statement_base_completion/statement.py
@@ -24,6 +24,7 @@ logger = netsvc.Logger()
from openerp.osv.orm import Model, fields
from openerp.osv import fields, osv
from operator import itemgetter, attrgetter
+import datetime
class ErrorTooManyPartner(Exception):
"""
@@ -146,7 +147,7 @@ class AccountStatementCompletionRule(Model):
inv = inv_obj.browse(cursor, uid, inv_id[0])
res['partner_id'] = inv.partner_id.id
elif inv_id and len(inv_id) > 1:
- raise ErrorTooManyPartner(_('Line named "%s" was matched by more than one partner.')%(st_line.name,st_line.id))
+ raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
res.update(st_vals)
@@ -178,7 +179,7 @@ class AccountStatementCompletionRule(Model):
so = so_obj.browse(cursor, uid, so_id[0])
res['partner_id'] = so.partner_id.id
elif so_id and len(so_id) > 1:
- raise ErrorTooManyPartner(_('Line named "%s" was matched by more than one partner.')%(st_line.name,st_line.id))
+ raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
res.update(st_vals)
@@ -209,13 +210,13 @@ class AccountStatementCompletionRule(Model):
compt = 0
if st_line:
ids = partner_obj.search(cursor, uid, [['bank_statement_label', '!=', False]], context=context)
- for partner in self.browse(cursor, uid, ids, context=context):
+ for partner in partner_obj.browse(cursor, uid, ids, context=context):
for partner_label in partner.bank_statement_label.split(';'):
if partner_label in st_line.label:
compt += 1
res['partner_id'] = partner.id
if compt > 1:
- raise ErrorTooManyPartner(_('Line named "%s" was matched by more than one partner.')%(st_line.name,st_line.id))
+ raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
if res:
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
@@ -243,12 +244,13 @@ class AccountStatementCompletionRule(Model):
st_obj = self.pool.get('account.bank.statement.line')
st_line = st_obj.browse(cursor,uid,line_id)
if st_line:
- sql = "SELECT id FROM res_partner WHERE name ~* '.*%s.*'"
- cursor.execute(sql, (st_line.label,))
+ sql = "SELECT id FROM res_partner WHERE name ~* %s"
+ pattern = ".*%s.*" % st_line.label
+ cursor.execute(sql, (pattern,))
result = cursor.fetchall()
if len(result) > 1:
- raise ErrorTooManyPartner(_('Line named "%s" was matched by more than one partner.')%(st_line.name,st_line.id))
- for id in result:
+ raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
+ for id in result[0]:
res['partner_id'] = id
if res:
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
@@ -290,12 +292,9 @@ class AccountStatementLine(Model):
the profile.. We will ignore line for which already_completed is ticked.
:return:
- A dict of value that can be passed directly to the write method of
- the statement line or {}
- {'partner_id': value,
- 'account_id' : value,
-
- ...}
+ A dict of dict value that can be passed directly to the write method of
+ the statement line or {}. The first dict has statement line ID as a key:
+ {117009: {'partner_id': 100997, 'account_id': 489L}}
"""
profile_obj = self.pool.get('account.statement.profil')
st_obj = self.pool.get('account.bank.statement.line')
@@ -312,7 +311,7 @@ class AccountStatementLine(Model):
# Merge the result
res[line.id].update(vals)
except ErrorTooManyPartner, exc:
- msg = "Line ID %s had following error: %s" % (line.id, str(exc))
+ msg = "Line ID %s had following error: %s" % (line.id, exc.value)
errors_stack.append(msg)
if errors_stack:
msg = u"\n".join(errors_stack)
@@ -326,36 +325,64 @@ class AccountBankSatement(Model):
"""
_inherit = "account.bank.statement"
+ _columns = {
+ 'completion_logs': fields.text('Completion Log', readonly=True),
+ }
+
+ def write_completion_log(self, cr, uid, stat_id, error_msg, number_imported, context=None):
+ """
+ Write the log in the completion_logs field of the bank statement to let the user
+ know what have been done. This is an append mode, so we don't overwrite what
+ already recoded.
+
+ :param int/long stat_id: ID of the account.bank.statement
+ :param char error_msg: Message to add
+ :number_imported int/long: Number of lines that have been completed
+ :return : True
+
+ """
+ error_log = ""
+ user_name = self.pool.get('res.users').read(cr, uid, uid, ['name'])['name']
+ log = self.read(cr, uid, stat_id, ['completion_logs'], context=context)['completion_logs']
+ log_line = log and log.split("\n") or []
+ completion_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+ if error_msg:
+ error_log = error_msg
+ log_line[0:0] = [completion_date + ' : '
+ + _("Bank Statement ID %s has %s lines completed by %s") %(stat_id, number_imported, user_name)
+ + "\n" + error_log + "-------------" + "\n"]
+ log = "\n".join(log_line)
+ self.write(cr, uid, [stat_id], {'completion_logs' : log}, context=context)
+ logger.notifyChannel('Bank Statement Completion', netsvc.LOG_INFO,
+ "Bank Statement ID %s has %s lines completed"%(stat_id, number_imported))
+ return True
+
def button_auto_completion(self, cr, uid, ids, context=None):
"""
Complete line with values given by rules and tic the already_completed
checkbox so we won't compute them again unless the user untick them !
"""
- # TODO: Test the errors system, we should be able to complete all line that
- # passed, and raise an error for all other at once..
if not context:
context={}
stat_line_obj = self.pool.get('account.bank.statement.line')
- errors_msg=False
+ msg = ""
+ compl_lines = 0
for stat in self.browse(cr, uid, ids, context=context):
ctx = context.copy()
- line_ids = map(lambda x:x.id, stat.line_ids)
- try:
- res = stat_line_obj.get_line_values_from_rules(cr, uid, line_ids, context=ctx)
- except ErrorTooManyPartner, exc:
- errors_msg = str(exc)
- for id in line_ids:
- vals = res.get(id, False)
- if vals:
+ for line in stat.line_ids:
+ res = {}
+ try:
+ res = stat_line_obj.get_line_values_from_rules(cr, uid, [line.id], context=ctx)
+ if res:
+ compl_lines += 1
+ except ErrorTooManyPartner, exc:
+ msg += exc.value + "\n"
+ except Exception, exc:
+ msg += exc.value + "\n"
+ # vals = res and res.keys() or False
+ if res:
+ vals = res[line.id]
vals['already_completed'] = True
- stat_line_obj.write(cr, uid, id, vals, context=ctx)
- # cr.commit()
- # TOTEST: I don't know if this is working...
- if errors_msg:
- # raise osv.except_osv(_('Error'), errors_msg)
- warning = {
- 'title': _('Error!'),
- 'message' : errors_msg,
- }
- return {'warning': warning}
+ stat_line_obj.write(cr, uid, line.id, vals, context=ctx)
+ self.write_completion_log(cr, uid, stat.id, msg, compl_lines, context=context)
return True
diff --git a/account_statement_base_completion/statement_view.xml b/account_statement_base_completion/statement_view.xml
index 4c1fb2b3..5101a0b0 100644
--- a/account_statement_base_completion/statement_view.xml
+++ b/account_statement_base_completion/statement_view.xml
@@ -26,6 +26,12 @@
+
+
+
+
+
+
diff --git a/account_statement_base_import/wizard/import_statement.py b/account_statement_base_import/wizard/import_statement.py
index 0c76946b..574a8979 100644
--- a/account_statement_base_import/wizard/import_statement.py
+++ b/account_statement_base_import/wizard/import_statement.py
@@ -110,6 +110,11 @@ class CreditPartnerStatementImporter(osv.osv_memory):
ftype.replace('.',''),
context=context
)
-
- # We should return here the profile for which we executed the import
- return {'type': 'ir.actions.act_window_close'}
+ return {
+ 'domain': "[('id','in', ["+','.join(map(str,[sid]))+"])]",
+ 'name': 'Imported Bank Statement',
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'account.bank.statement',
+ 'type': 'ir.actions.act_window',
+ }
diff --git a/account_statement_ext/statement_view.xml b/account_statement_ext/statement_view.xml
index 6f8761a9..1639c30f 100644
--- a/account_statement_ext/statement_view.xml
+++ b/account_statement_ext/statement_view.xml
@@ -91,6 +91,7 @@
search
+
@@ -109,6 +110,9 @@
tree
+
+
+
@@ -132,7 +136,8 @@
-
+
+
diff --git a/account_statement_transactionid_completion/data.xml b/account_statement_transactionid_completion/data.xml
index 23f366df..09460078 100644
--- a/account_statement_transactionid_completion/data.xml
+++ b/account_statement_transactionid_completion/data.xml
@@ -4,9 +4,8 @@
Match from line reference (based on transaction ID)
- 40
+ 30get_from_transaction_id_and_so
-
diff --git a/account_statement_transactionid_completion/statement.py b/account_statement_transactionid_completion/statement.py
index 4d25d85e..ff25cc28 100644
--- a/account_statement_transactionid_completion/statement.py
+++ b/account_statement_transactionid_completion/statement.py
@@ -31,8 +31,9 @@ class AccountStatementCompletionRule(Model):
_inherit = "account.statement.completion.rule"
- def _get_functions(self):
- res = super (self,AccountStatementCompletionRule)._get_functions()
+ def _get_functions(self, cr, uid, context=None):
+ res = super (AccountStatementCompletionRule, self)._get_functions(
+ cr, uid, context=context)
res.append(('get_from_transaction_id_and_so', 'From line reference (based on SO transaction ID'))
return res
@@ -58,16 +59,16 @@ class AccountStatementCompletionRule(Model):
res = {}
if st_line:
so_obj = self.pool.get('sale.order')
- so_id = so_obj.search(cursor, uid, [('transaction_id', '=', st_line.transaction_id)])
+ so_id = so_obj.search(cr, uid, [('transaction_id', '=', st_line.transaction_id)])
if so_id and len(so_id) == 1:
- so = so_obj.browse(cursor, uid, so_id[0])
+ so = so_obj.browse(cr, uid, so_id[0])
res['partner_id'] = so.partner_id.id
res['ref'] = so.name
elif so_id and len(so_id) > 1:
- raise ErrorTooManyPartner(_('Line named "%s" was matched by more than one partner.')%(st_line.name,st_line.id))
+ raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
if so_id:
st_vals = st_obj.get_values_for_line(cr, uid, profile_id = st_line.statement_id.profile_id.id,
- partner_id = res.get('partner_id',False), line_type = st_line.type, st_line.amount, context)
+ partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context=context)
res.update(st_vals)
return res
diff --git a/account_statement_transactionid_completion/statement_view.xml b/account_statement_transactionid_completion/statement_view.xml
index f7612d17..cf04e6bd 100644
--- a/account_statement_transactionid_completion/statement_view.xml
+++ b/account_statement_transactionid_completion/statement_view.xml
@@ -6,7 +6,7 @@
account_bank_statement_import_base.bank_statement.view_formaccount.bank.statement
-
+ form
diff --git a/account_statement_transactionid_import/__init__.py b/account_statement_transactionid_import/__init__.py
index 53424340..6ec31941 100644
--- a/account_statement_transactionid_import/__init__.py
+++ b/account_statement_transactionid_import/__init__.py
@@ -18,4 +18,5 @@
# along with this program. If not, see .
#
##############################################################################
-import parser
\ No newline at end of file
+import parser
+import statement
\ No newline at end of file
diff --git a/account_statement_transactionid_import/parser/transactionid_file_parser.py b/account_statement_transactionid_import/parser/transactionid_file_parser.py
index 084bb90d..e4da64c7 100644
--- a/account_statement_transactionid_import/parser/transactionid_file_parser.py
+++ b/account_statement_transactionid_import/parser/transactionid_file_parser.py
@@ -50,15 +50,15 @@ class TransactionIDFileParser(FileParser):
@classmethod
def parser_for(cls, parser_name):
- """
- Used by the new_bank_statement_parser class factory. Return true if
- the providen name is generic_csvxls_transaction
- """
+ """
+ Used by the new_bank_statement_parser class factory. Return true if
+ the providen name is generic_csvxls_transaction
+ """
return parser_name == 'generic_csvxls_transaction'
def get_st_line_vals(self, line, *args, **kwargs):
- """T
- his method must return a dict of vals that can be passed to create
+ """
+ This method must return a dict of vals that can be passed to create
method of statement line in order to record it. It is the responsibility
of every parser to give this dict of vals, so each one can implement his
own way of recording the lines.
@@ -90,13 +90,10 @@ class TransactionIDFileParser(FileParser):
"""
Compute the commission from value of each line
"""
- res = super(GenericFileParser, self)._post(*args, **kwargs)
+ res = super(TransactionIDFileParser, self)._post(*args, **kwargs)
val = 0.0
for row in self.result_row_list:
val += row.get('commission_amount',0.0)
self.commission_global_amount = val
return res
-
-
-
diff --git a/account_statement_transactionid_import/statement.py b/account_statement_transactionid_import/statement.py
new file mode 100644
index 00000000..5cfef3ca
--- /dev/null
+++ b/account_statement_transactionid_import/statement.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Joel Grand-Guillaume
+# Copyright 2011-2012 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from openerp.osv.orm import Model, fields
+from openerp.osv import fields, osv
+
+class AccountStatementProfil(Model):
+ _inherit = "account.statement.profil"
+
+
+ def get_import_type_selection(self, cr, uid, context=None):
+ """
+ Has to be inherited to add parser
+ """
+ res = super(AccountStatementProfil, self).get_import_type_selection(cr, uid, context=context)
+ res.append(('generic_csvxls_transaction','Generic .csv/.xls based on SO transaction ID'))
+ return res
+
+
+ _columns = {
+ 'import_type': fields.selection(get_import_type_selection, 'Type of import', required=True,
+ help = "Choose here the method by which you want to import bank statement for this profil."),
+
+ }
+