prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  many transactions not regonized
  After importing a dutch bank statements file from the ING, I got the following screen:
  
  ![import_log](https://cloud.githubusercontent.com/assets/890128/3571378/ca510fa0-0b5c-11e4-9d32-3ee373c491e4.png)
  
  Many transactions are not processed because of not recognizing the correct bankaccount number. 
  
  The system is complaining about "Statements found for unknown account 68xxx" and "Statements found for account 06xxxxxx, but no default journal was defined.
  
  This is a little strange, because I have setup "Default Import Settings for Bank Accounts"
  in the settings of the accounting section.
  
  I also put a default journal in there.
  
  My information entered there is the IBAN number of my account, together with the national account (with leading zero). I also tried without the leading zero in the national account, but this doesn't make any difference at all.
  
  Why is openerp mixing up the number of the bankaccount. (with/without zero) and not matching the national number.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `account_banking/res_partner_bank.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 ##############################################################################
  3 #
  4 #    Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
  5 #              (C) 2011 - 2014 Therp BV (<http://therp.nl>).
  6 #
  7 #    This program is free software: you can redistribute it and/or modify
  8 #    it under the terms of the GNU Affero General Public License as
  9 #    published by the Free Software Foundation, either version 3 of the
  10 #    License, or (at your option) any later version.
  11 #
  12 #    This program is distributed in the hope that it will be useful,
  13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 #    GNU Affero General Public License for more details.
  16 #
  17 #    You should have received a copy of the GNU Affero General Public License
  18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19 #
  20 ##############################################################################
  21 from openerp.osv import orm
  22 from openerp.addons.account_banking import sepa
  23 
  24 
  25 class ResPartnerBank(orm.Model):
  26     _inherit = 'res.partner.bank'
  27 
  28     def online_account_info(
  29             self, cr, uid, country_code, acc_number, context=None):
  30         """
  31         API hook for legacy online lookup of account info,
  32         to be removed in OpenERP 8.0.
  33         """
  34         return False
  35 
  36     def search(self, cr, uid, args, *rest, **kwargs):
  37         """
  38         When a complete IBAN is searched, also search for its BBAN
  39         if we have the domestic column. Disregard spaces
  40         when comparing IBANs.
  41         """
  42 
  43         def is_term(arg):
  44             '''Flag an arg as term or otherwise'''
  45             return isinstance(arg, (list, tuple)) and len(arg) == 3
  46 
  47         def extended_filter_term(term):
  48             '''
  49             Extend the search criteria in term when appropriate.
  50             '''
  51             result = [term]
  52             extra_terms = []
  53             if term[0].lower() == 'acc_number' and term[1] in ('=', '=='):
  54                 iban = sepa.IBAN(term[2])
  55                 if iban.valid:
  56                     # Disregard spaces when comparing IBANs
  57                     cr.execute(
  58                         """
  59                         SELECT id FROM res_partner_bank
  60                         WHERE replace(acc_number, ' ', '') = %s
  61                         """, (term[2].replace(' ', ''),))
  62                     ids = [row[0] for row in cr.fetchall()]
  63                     result = [('id', 'in', ids)]
  64 
  65                     if 'acc_number_domestic' in self._columns:
  66                         bban = iban.localized_BBAN
  67                         # Prevent empty search filters
  68                         if bban:
  69                             extra_terms.append(
  70                                 ('acc_number_domestic', term[1], bban))
  71             for extra_term in extra_terms:
  72                 result = ['|'] + result + [extra_term]
  73             return result
  74 
  75         def extended_search_expression(args):
  76             '''
  77             Extend the search expression in args when appropriate.
  78             The expression itself is in reverse polish notation, so recursion
  79             is not needed.
  80             '''
  81             if not args:
  82                 return []
  83 
  84             result = []
  85             if is_term(args[0]) and len(args) > 1:
  86                 # Classic filter, implicit '&'
  87                 result += ['&']
  88 
  89             for arg in args:
  90                 if is_term(arg):
  91                     result += extended_filter_term(arg)
  92                 else:
  93                     result += arg
  94             return result
  95 
  96         # Extend search filter
  97         newargs = extended_search_expression(args)
  98 
  99         # Original search
  100         return super(ResPartnerBank, self).search(
  101             cr, uid, newargs, *rest, **kwargs)
  102
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/account_banking/res_partner_bank.py b/account_banking/res_partner_bank.py
  --- a/account_banking/res_partner_bank.py
  +++ b/account_banking/res_partner_bank.py
  @@ -44,6 +44,27 @@
               '''Flag an arg as term or otherwise'''
               return isinstance(arg, (list, tuple)) and len(arg) == 3
   
  +        def search_domestic(account):
  +            """
  +            Performing raw sql search for full account numbers,
  +            ignoring leading zeroes.
  +            """
  +            account = (account or '').lstrip('0')
  +            if not account:
  +                return ('id', '=', 0)
  +            query = """
  +                SELECT id FROM res_partner_bank
  +                WHERE (
  +                    STATE != 'iban'
  +                    AND TRIM(LEADING '0' FROM acc_number) = %(account)s)
  +                """
  +            if 'acc_number_domestic' in self._columns:
  +                query += """
  +                    OR TRIM(LEADING '0' FROM acc_number_domestic)
  +                        = %(account)s"""
  +            cr.execute(query, {'account': account})
  +            return ('id', 'in', [row[0] for row in cr.fetchall()])
  +
           def extended_filter_term(term):
               '''
               Extend the search criteria in term when appropriate.
  @@ -62,12 +83,11 @@
                       ids = [row[0] for row in cr.fetchall()]
                       result = [('id', 'in', ids)]
   
  -                    if 'acc_number_domestic' in self._columns:
  -                        bban = iban.localized_BBAN
  -                        # Prevent empty search filters
  -                        if bban:
  -                            extra_terms.append(
  -                                ('acc_number_domestic', term[1], bban))
  +                    bban = iban.localized_BBAN
  +                    if bban:
  +                        extra_terms.append(search_domestic(bban))
  +                else:
  +                    result = [search_domestic(term[2])]
               for extra_term in extra_terms:
                   result = ['|'] + result + [extra_term]
               return result
  
verification_info: {"golden_diff": "diff --git a/account_banking/res_partner_bank.py b/account_banking/res_partner_bank.py\n--- a/account_banking/res_partner_bank.py\n+++ b/account_banking/res_partner_bank.py\n@@ -44,6 +44,27 @@\n             '''Flag an arg as term or otherwise'''\n             return isinstance(arg, (list, tuple)) and len(arg) == 3\n \n+        def search_domestic(account):\n+            \"\"\"\n+            Performing raw sql search for full account numbers,\n+            ignoring leading zeroes.\n+            \"\"\"\n+            account = (account or '').lstrip('0')\n+            if not account:\n+                return ('id', '=', 0)\n+            query = \"\"\"\n+                SELECT id FROM res_partner_bank\n+                WHERE (\n+                    STATE != 'iban'\n+                    AND TRIM(LEADING '0' FROM acc_number) = %(account)s)\n+                \"\"\"\n+            if 'acc_number_domestic' in self._columns:\n+                query += \"\"\"\n+                    OR TRIM(LEADING '0' FROM acc_number_domestic)\n+                        = %(account)s\"\"\"\n+            cr.execute(query, {'account': account})\n+            return ('id', 'in', [row[0] for row in cr.fetchall()])\n+\n         def extended_filter_term(term):\n             '''\n             Extend the search criteria in term when appropriate.\n@@ -62,12 +83,11 @@\n                     ids = [row[0] for row in cr.fetchall()]\n                     result = [('id', 'in', ids)]\n \n-                    if 'acc_number_domestic' in self._columns:\n-                        bban = iban.localized_BBAN\n-                        # Prevent empty search filters\n-                        if bban:\n-                            extra_terms.append(\n-                                ('acc_number_domestic', term[1], bban))\n+                    bban = iban.localized_BBAN\n+                    if bban:\n+                        extra_terms.append(search_domestic(bban))\n+                else:\n+                    result = [search_domestic(term[2])]\n             for extra_term in extra_terms:\n                 result = ['|'] + result + [extra_term]\n             return result\n", "issue": "many transactions not regonized\nAfter importing a dutch bank statements file from the ING, I got the following screen:\n\n![import_log](https://cloud.githubusercontent.com/assets/890128/3571378/ca510fa0-0b5c-11e4-9d32-3ee373c491e4.png)\n\nMany transactions are not processed because of not recognizing the correct bankaccount number. \n\nThe system is complaining about \"Statements found for unknown account 68xxx\" and \"Statements found for account 06xxxxxx, but no default journal was defined.\n\nThis is a little strange, because I have setup \"Default Import Settings for Bank Accounts\"\nin the settings of the accounting section.\n\nI also put a default journal in there.\n\nMy information entered there is the IBAN number of my account, together with the national account (with leading zero). I also tried without the leading zero in the national account, but this doesn't make any difference at all.\n\nWhy is openerp mixing up the number of the bankaccount. (with/without zero) and not matching the national number.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n##############################################################################\n#\n#    Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).\n#              (C) 2011 - 2014 Therp BV (<http://therp.nl>).\n#\n#    This program is free software: you can redistribute it and/or modify\n#    it under the terms of the GNU Affero General Public License as\n#    published by the Free Software Foundation, either version 3 of the\n#    License, or (at your option) any later version.\n#\n#    This program is distributed in the hope that it will be useful,\n#    but WITHOUT ANY WARRANTY; without even the implied warranty of\n#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n#    GNU Affero General Public License for more details.\n#\n#    You should have received a copy of the GNU Affero General Public License\n#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n##############################################################################\nfrom openerp.osv import orm\nfrom openerp.addons.account_banking import sepa\n\n\nclass ResPartnerBank(orm.Model):\n    _inherit = 'res.partner.bank'\n\n    def online_account_info(\n            self, cr, uid, country_code, acc_number, context=None):\n        \"\"\"\n        API hook for legacy online lookup of account info,\n        to be removed in OpenERP 8.0.\n        \"\"\"\n        return False\n\n    def search(self, cr, uid, args, *rest, **kwargs):\n        \"\"\"\n        When a complete IBAN is searched, also search for its BBAN\n        if we have the domestic column. Disregard spaces\n        when comparing IBANs.\n        \"\"\"\n\n        def is_term(arg):\n            '''Flag an arg as term or otherwise'''\n            return isinstance(arg, (list, tuple)) and len(arg) == 3\n\n        def extended_filter_term(term):\n            '''\n            Extend the search criteria in term when appropriate.\n            '''\n            result = [term]\n            extra_terms = []\n            if term[0].lower() == 'acc_number' and term[1] in ('=', '=='):\n                iban = sepa.IBAN(term[2])\n                if iban.valid:\n                    # Disregard spaces when comparing IBANs\n                    cr.execute(\n                        \"\"\"\n                        SELECT id FROM res_partner_bank\n                        WHERE replace(acc_number, ' ', '') = %s\n                        \"\"\", (term[2].replace(' ', ''),))\n                    ids = [row[0] for row in cr.fetchall()]\n                    result = [('id', 'in', ids)]\n\n                    if 'acc_number_domestic' in self._columns:\n                        bban = iban.localized_BBAN\n                        # Prevent empty search filters\n                        if bban:\n                            extra_terms.append(\n                                ('acc_number_domestic', term[1], bban))\n            for extra_term in extra_terms:\n                result = ['|'] + result + [extra_term]\n            return result\n\n        def extended_search_expression(args):\n            '''\n            Extend the search expression in args when appropriate.\n            The expression itself is in reverse polish notation, so recursion\n            is not needed.\n            '''\n            if not args:\n                return []\n\n            result = []\n            if is_term(args[0]) and len(args) > 1:\n                # Classic filter, implicit '&'\n                result += ['&']\n\n            for arg in args:\n                if is_term(arg):\n                    result += extended_filter_term(arg)\n                else:\n                    result += arg\n            return result\n\n        # Extend search filter\n        newargs = extended_search_expression(args)\n\n        # Original search\n        return super(ResPartnerBank, self).search(\n            cr, uid, newargs, *rest, **kwargs)\n", "path": "account_banking/res_partner_bank.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n##############################################################################\n#\n#    Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).\n#              (C) 2011 - 2014 Therp BV (<http://therp.nl>).\n#\n#    This program is free software: you can redistribute it and/or modify\n#    it under the terms of the GNU Affero General Public License as\n#    published by the Free Software Foundation, either version 3 of the\n#    License, or (at your option) any later version.\n#\n#    This program is distributed in the hope that it will be useful,\n#    but WITHOUT ANY WARRANTY; without even the implied warranty of\n#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n#    GNU Affero General Public License for more details.\n#\n#    You should have received a copy of the GNU Affero General Public License\n#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n#\n##############################################################################\nfrom openerp.osv import orm\nfrom openerp.addons.account_banking import sepa\n\n\nclass ResPartnerBank(orm.Model):\n    _inherit = 'res.partner.bank'\n\n    def online_account_info(\n            self, cr, uid, country_code, acc_number, context=None):\n        \"\"\"\n        API hook for legacy online lookup of account info,\n        to be removed in OpenERP 8.0.\n        \"\"\"\n        return False\n\n    def search(self, cr, uid, args, *rest, **kwargs):\n        \"\"\"\n        When a complete IBAN is searched, also search for its BBAN\n        if we have the domestic column. Disregard spaces\n        when comparing IBANs.\n        \"\"\"\n\n        def is_term(arg):\n            '''Flag an arg as term or otherwise'''\n            return isinstance(arg, (list, tuple)) and len(arg) == 3\n\n        def search_domestic(account):\n            \"\"\"\n            Performing raw sql search for full account numbers,\n            ignoring leading zeroes.\n            \"\"\"\n            account = (account or '').lstrip('0')\n            if not account:\n                return ('id', '=', 0)\n            query = \"\"\"\n                SELECT id FROM res_partner_bank\n                WHERE (\n                    STATE != 'iban'\n                    AND TRIM(LEADING '0' FROM acc_number) = %(account)s)\n                \"\"\"\n            if 'acc_number_domestic' in self._columns:\n                query += \"\"\"\n                    OR TRIM(LEADING '0' FROM acc_number_domestic)\n                        = %(account)s\"\"\"\n            cr.execute(query, {'account': account})\n            return ('id', 'in', [row[0] for row in cr.fetchall()])\n\n        def extended_filter_term(term):\n            '''\n            Extend the search criteria in term when appropriate.\n            '''\n            result = [term]\n            extra_terms = []\n            if term[0].lower() == 'acc_number' and term[1] in ('=', '=='):\n                iban = sepa.IBAN(term[2])\n                if iban.valid:\n                    # Disregard spaces when comparing IBANs\n                    cr.execute(\n                        \"\"\"\n                        SELECT id FROM res_partner_bank\n                        WHERE replace(acc_number, ' ', '') = %s\n                        \"\"\", (term[2].replace(' ', ''),))\n                    ids = [row[0] for row in cr.fetchall()]\n                    result = [('id', 'in', ids)]\n\n                    bban = iban.localized_BBAN\n                    if bban:\n                        extra_terms.append(search_domestic(bban))\n                else:\n                    result = [search_domestic(term[2])]\n            for extra_term in extra_terms:\n                result = ['|'] + result + [extra_term]\n            return result\n\n        def extended_search_expression(args):\n            '''\n            Extend the search expression in args when appropriate.\n            The expression itself is in reverse polish notation, so recursion\n            is not needed.\n            '''\n            if not args:\n                return []\n\n            result = []\n            if is_term(args[0]) and len(args) > 1:\n                # Classic filter, implicit '&'\n                result += ['&']\n\n            for arg in args:\n                if is_term(arg):\n                    result += extended_filter_term(arg)\n                else:\n                    result += arg\n            return result\n\n        # Extend search filter\n        newargs = extended_search_expression(args)\n\n        # Original search\n        return super(ResPartnerBank, self).search(\n            cr, uid, newargs, *rest, **kwargs)\n", "path": "account_banking/res_partner_bank.py"}]}