We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Test fails with Odoo, not OCB
https://travis-ci.org/OCA/bank-payment/builds/47806067

File "/home/travis/build/OCA/bank-payment/account_direct_debit/models/account_invoice.py", line 140, in  __ init __
invoice_obj._columns['state'].selection.append(
KeyError: 'state'


--- 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_direct_debit/models/account_invoice.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    Copyright (C) 2011 - 2013 Therp BV (<http://therp.nl>).
5 #
6 #    All other contributions are (C) by their respective contributors
7 #
8 #    All Rights Reserved
9 #
10 #    This program is free software: you can redistribute it and/or modify
11 #    it under the terms of the GNU Affero General Public License as
12 #    published by the Free Software Foundation, either version 3 of the
13 #    License, or (at your option) any later version.
14 #
15 #    This program is distributed in the hope that it will be useful,
16 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #    GNU Affero General Public License for more details.
19 #
20 #    You should have received a copy of the GNU Affero General Public License
21 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23 ##############################################################################
24 
25 """
26 This module adds support for Direct debit orders as applicable
27 in the Netherlands. Debit orders are advanced in total by the bank.
28 Amounts that cannot be debited or are canceled by account owners are
29 credited afterwards. Such a creditation is called a storno.
30 
31 Invoice workflow:
32 
33 1 the sale leads to
34    1300 Debtors 100
35    8000 Sales       100
36 
37 Balance:
38   Debtors  2000 |
39   Sales        | 2000
40 
41 2 an external booking takes place
42    1100 Bank    100
43    1300 Debtors     100
44    This booking is reconciled with [1]
45    The invoice gets set to state 'paid', and 'reconciled' = True
46 
47 Balance:
48    Debtors 1900 |
49    Bank     100 |
50    Sales        | 2000
51 
52 This module implements the following diversion:
53 
54 2a the invoice is included in a direct debit order. When the order is
55    confirmed, a move is created per invoice:
56 
57    2000 Transfer account 100 |
58    1300 Debtors              | 100
59    Reconciliation takes place between 1 and 2a.
60    The invoice gets set to state 'paid', and 'reconciled' = True
61 
62 Balance:
63    Debtors             0 |
64    Transfer account 2000 |
65    Bank                0 |
66    Sales                 | 2000
67 
68 3a the direct debit order is booked on the bank account
69 
70 Balance:
71   1100 Bank             2000 |
72   2000 Transfer account      | 2000
73   Reconciliation takes place between 3a and 2a
74 
75 Balance:
76    Debtors             0 |
77    Transfer account    0 |
78    Bank             2000 |
79    Sales                 | 2000
80 
81 4 a storno from invoice [1] triggers a new booking on the bank account
82   1300 Debtors 100 |
83   1100 Bank        | 100
84 
85 Balance:
86    Debtors           100 |
87    Transfer account    0 |
88    Bank             1900 |
89    Sales                 | 2000
90 
91    The reconciliation of 2a is undone. The booking of 2a is reconciled
92    with the booking of 4 instead.
93    The payment line attribute 'storno' is set to True and the invoice
94    state is no longer 'paid'.
95 
96 Two cases need to be distinguisted:
97    1) If the storno is a manual storno from the partner, the invoice is set to
98       state 'debit_denied', with 'reconciled' = False
99       This module implements this option by allowing the bank module to call
100 
101           netsvc.LocalService("workflow").trg_validate(
102               uid, 'account.invoice', ids, 'debit_denied', cr)
103 
104    2) If the storno is an error generated by the bank (assumingly non-fatal),
105       the invoice is reopened for the next debit run. This is a call to
106       existing
107 
108          netsvc.LocalService("workflow").trg_validate(
109              uid, 'account.invoice', ids, 'open_test', cr)
110 
111       Should also be adding a log entry on the invoice for tracing purposes
112 
113          self._log_event(cr, uid, ids, -1.0, 'Debit denied')
114 
115       If not for that funny comment
116       "#TODO: implement messages system"  in account/invoice.py
117 
118    Repeating non-fatal fatal errors need to be dealt with manually by checking
119    open invoices with a matured invoice- or due date.
120 """
121 
122 from openerp.osv import orm
123 from openerp.tools.translate import _
124 
125 
126 class AccountInvoice(orm.Model):
127     _inherit = "account.invoice"
128 
129     def __init__(self, pool, cr):
130         """
131         Adding a state to the hardcoded state list of the inherited
132         model. The alternative is duplicating the field definition
133         in columns but only one module can do that!
134 
135         Maybe apply a similar trick when overriding the buttons' 'states'
136         attributes in the form view, manipulating the xml in fields_view_get().
137         """
138         super(AccountInvoice, self).__init__(pool, cr)
139         invoice_obj = pool.get('account.invoice')
140         invoice_obj._columns['state'].selection.append(
141             ('debit_denied', 'Debit denied'))
142 
143     def action_debit_denied(self, cr, uid, ids, context=None):
144         for invoice_id in ids:
145             if self.test_paid(cr, uid, [invoice_id], context):
146                 number = self.read(
147                     cr, uid, invoice_id, ['number'], context=context)['number']
148                 raise orm.except_orm(
149                     _('Error !'),
150                     _("You cannot set invoice '%s' to state 'debit "
151                       "denied', as it is still reconciled.") % number)
152         self.write(cr, uid, ids, {'state': 'debit_denied'}, context=context)
153         for inv_id, name in self.name_get(cr, uid, ids, context=context):
154             message = _("Invoice '%s': direct debit is denied.") % name
155             self.log(cr, uid, inv_id, message)
156         return True
157 
158     def test_undo_debit_denied(self, cr, uid, ids, context=None):
159         """
160         Called from the workflow. Used to unset paid state on
161         invoices that were paid with bank transfers which are being cancelled
162         """
163         for invoice in self.read(cr, uid, ids, ['reconciled'], context):
164             if not invoice['reconciled']:
165                 return False
166         return True
167
```
--- 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()

```

diff --git a/account_direct_debit/models/account_invoice.py b/account_direct_debit/models/account_invoice.py
--- a/account_direct_debit/models/account_invoice.py
+++ b/account_direct_debit/models/account_invoice.py
@@ -126,7 +126,7 @@
 class AccountInvoice(orm.Model):
     _inherit = "account.invoice"
 
-    def __init__(self, pool, cr):
+    def _register_hook(self, cr):
         """
         Adding a state to the hardcoded state list of the inherited
         model. The alternative is duplicating the field definition
@@ -135,9 +135,7 @@
         Maybe apply a similar trick when overriding the buttons' 'states'
         attributes in the form view, manipulating the xml in fields_view_get().
         """
-        super(AccountInvoice, self).__init__(pool, cr)
-        invoice_obj = pool.get('account.invoice')
-        invoice_obj._columns['state'].selection.append(
+        self._columns['state'].selection.append(
             ('debit_denied', 'Debit denied'))
 
     def action_debit_denied(self, cr, uid, ids, context=None):

{"golden_diff": "diff --git a/account_direct_debit/models/account_invoice.py b/account_direct_debit/models/account_invoice.py\n--- a/account_direct_debit/models/account_invoice.py\n+++ b/account_direct_debit/models/account_invoice.py\n@@ -126,7 +126,7 @@\n class AccountInvoice(orm.Model):\n     _inherit = \"account.invoice\"\n \n-    def __init__(self, pool, cr):\n+    def _register_hook(self, cr):\n         \"\"\"\n         Adding a state to the hardcoded state list of the inherited\n         model. The alternative is duplicating the field definition\n@@ -135,9 +135,7 @@\n         Maybe apply a similar trick when overriding the buttons' 'states'\n         attributes in the form view, manipulating the xml in fields_view_get().\n         \"\"\"\n-        super(AccountInvoice, self).__init__(pool, cr)\n-        invoice_obj = pool.get('account.invoice')\n-        invoice_obj._columns['state'].selection.append(\n+        self._columns['state'].selection.append(\n             ('debit_denied', 'Debit denied'))\n \n     def action_debit_denied(self, cr, uid, ids, context=None):\n", "issue": "Test fails with Odoo, not OCB\nhttps://travis-ci.org/OCA/bank-payment/builds/47806067\n\nFile \"/home/travis/build/OCA/bank-payment/account_direct_debit/models/account_invoice.py\", line 140, in  __ init __\ninvoice_obj._columns['state'].selection.append(\nKeyError: 'state'\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n##############################################################################\n#\n#    Copyright (C) 2011 - 2013 Therp BV (<http://therp.nl>).\n#\n#    All other contributions are (C) by their respective contributors\n#\n#    All Rights Reserved\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##############################################################################\n\n\"\"\"\nThis module adds support for Direct debit orders as applicable\nin the Netherlands. Debit orders are advanced in total by the bank.\nAmounts that cannot be debited or are canceled by account owners are\ncredited afterwards. Such a creditation is called a storno.\n\nInvoice workflow:\n\n1 the sale leads to\n   1300 Debtors 100\n   8000 Sales       100\n\nBalance:\n  Debtors  2000 |\n  Sales        | 2000\n\n2 an external booking takes place\n   1100 Bank    100\n   1300 Debtors     100\n   This booking is reconciled with [1]\n   The invoice gets set to state 'paid', and 'reconciled' = True\n\nBalance:\n   Debtors 1900 |\n   Bank     100 |\n   Sales        | 2000\n\nThis module implements the following diversion:\n\n2a the invoice is included in a direct debit order. When the order is\n   confirmed, a move is created per invoice:\n\n   2000 Transfer account 100 |\n   1300 Debtors              | 100\n   Reconciliation takes place between 1 and 2a.\n   The invoice gets set to state 'paid', and 'reconciled' = True\n\nBalance:\n   Debtors             0 |\n   Transfer account 2000 |\n   Bank                0 |\n   Sales                 | 2000\n\n3a the direct debit order is booked on the bank account\n\nBalance:\n  1100 Bank             2000 |\n  2000 Transfer account      | 2000\n  Reconciliation takes place between 3a and 2a\n\nBalance:\n   Debtors             0 |\n   Transfer account    0 |\n   Bank             2000 |\n   Sales                 | 2000\n\n4 a storno from invoice [1] triggers a new booking on the bank account\n  1300 Debtors 100 |\n  1100 Bank        | 100\n\nBalance:\n   Debtors           100 |\n   Transfer account    0 |\n   Bank             1900 |\n   Sales                 | 2000\n\n   The reconciliation of 2a is undone. The booking of 2a is reconciled\n   with the booking of 4 instead.\n   The payment line attribute 'storno' is set to True and the invoice\n   state is no longer 'paid'.\n\nTwo cases need to be distinguisted:\n   1) If the storno is a manual storno from the partner, the invoice is set to\n      state 'debit_denied', with 'reconciled' = False\n      This module implements this option by allowing the bank module to call\n\n          netsvc.LocalService(\"workflow\").trg_validate(\n              uid, 'account.invoice', ids, 'debit_denied', cr)\n\n   2) If the storno is an error generated by the bank (assumingly non-fatal),\n      the invoice is reopened for the next debit run. This is a call to\n      existing\n\n         netsvc.LocalService(\"workflow\").trg_validate(\n             uid, 'account.invoice', ids, 'open_test', cr)\n\n      Should also be adding a log entry on the invoice for tracing purposes\n\n         self._log_event(cr, uid, ids, -1.0, 'Debit denied')\n\n      If not for that funny comment\n      \"#TODO: implement messages system\"  in account/invoice.py\n\n   Repeating non-fatal fatal errors need to be dealt with manually by checking\n   open invoices with a matured invoice- or due date.\n\"\"\"\n\nfrom openerp.osv import orm\nfrom openerp.tools.translate import _\n\n\nclass AccountInvoice(orm.Model):\n    _inherit = \"account.invoice\"\n\n    def __init__(self, pool, cr):\n        \"\"\"\n        Adding a state to the hardcoded state list of the inherited\n        model. The alternative is duplicating the field definition\n        in columns but only one module can do that!\n\n        Maybe apply a similar trick when overriding the buttons' 'states'\n        attributes in the form view, manipulating the xml in fields_view_get().\n        \"\"\"\n        super(AccountInvoice, self).__init__(pool, cr)\n        invoice_obj = pool.get('account.invoice')\n        invoice_obj._columns['state'].selection.append(\n            ('debit_denied', 'Debit denied'))\n\n    def action_debit_denied(self, cr, uid, ids, context=None):\n        for invoice_id in ids:\n            if self.test_paid(cr, uid, [invoice_id], context):\n                number = self.read(\n                    cr, uid, invoice_id, ['number'], context=context)['number']\n                raise orm.except_orm(\n                    _('Error !'),\n                    _(\"You cannot set invoice '%s' to state 'debit \"\n                      \"denied', as it is still reconciled.\") % number)\n        self.write(cr, uid, ids, {'state': 'debit_denied'}, context=context)\n        for inv_id, name in self.name_get(cr, uid, ids, context=context):\n            message = _(\"Invoice '%s': direct debit is denied.\") % name\n            self.log(cr, uid, inv_id, message)\n        return True\n\n    def test_undo_debit_denied(self, cr, uid, ids, context=None):\n        \"\"\"\n        Called from the workflow. Used to unset paid state on\n        invoices that were paid with bank transfers which are being cancelled\n        \"\"\"\n        for invoice in self.read(cr, uid, ids, ['reconciled'], context):\n            if not invoice['reconciled']:\n                return False\n        return True\n", "path": "account_direct_debit/models/account_invoice.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n##############################################################################\n#\n#    Copyright (C) 2011 - 2013 Therp BV (<http://therp.nl>).\n#\n#    All other contributions are (C) by their respective contributors\n#\n#    All Rights Reserved\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##############################################################################\n\n\"\"\"\nThis module adds support for Direct debit orders as applicable\nin the Netherlands. Debit orders are advanced in total by the bank.\nAmounts that cannot be debited or are canceled by account owners are\ncredited afterwards. Such a creditation is called a storno.\n\nInvoice workflow:\n\n1 the sale leads to\n   1300 Debtors 100\n   8000 Sales       100\n\nBalance:\n  Debtors  2000 |\n  Sales        | 2000\n\n2 an external booking takes place\n   1100 Bank    100\n   1300 Debtors     100\n   This booking is reconciled with [1]\n   The invoice gets set to state 'paid', and 'reconciled' = True\n\nBalance:\n   Debtors 1900 |\n   Bank     100 |\n   Sales        | 2000\n\nThis module implements the following diversion:\n\n2a the invoice is included in a direct debit order. When the order is\n   confirmed, a move is created per invoice:\n\n   2000 Transfer account 100 |\n   1300 Debtors              | 100\n   Reconciliation takes place between 1 and 2a.\n   The invoice gets set to state 'paid', and 'reconciled' = True\n\nBalance:\n   Debtors             0 |\n   Transfer account 2000 |\n   Bank                0 |\n   Sales                 | 2000\n\n3a the direct debit order is booked on the bank account\n\nBalance:\n  1100 Bank             2000 |\n  2000 Transfer account      | 2000\n  Reconciliation takes place between 3a and 2a\n\nBalance:\n   Debtors             0 |\n   Transfer account    0 |\n   Bank             2000 |\n   Sales                 | 2000\n\n4 a storno from invoice [1] triggers a new booking on the bank account\n  1300 Debtors 100 |\n  1100 Bank        | 100\n\nBalance:\n   Debtors           100 |\n   Transfer account    0 |\n   Bank             1900 |\n   Sales                 | 2000\n\n   The reconciliation of 2a is undone. The booking of 2a is reconciled\n   with the booking of 4 instead.\n   The payment line attribute 'storno' is set to True and the invoice\n   state is no longer 'paid'.\n\nTwo cases need to be distinguisted:\n   1) If the storno is a manual storno from the partner, the invoice is set to\n      state 'debit_denied', with 'reconciled' = False\n      This module implements this option by allowing the bank module to call\n\n          netsvc.LocalService(\"workflow\").trg_validate(\n              uid, 'account.invoice', ids, 'debit_denied', cr)\n\n   2) If the storno is an error generated by the bank (assumingly non-fatal),\n      the invoice is reopened for the next debit run. This is a call to\n      existing\n\n         netsvc.LocalService(\"workflow\").trg_validate(\n             uid, 'account.invoice', ids, 'open_test', cr)\n\n      Should also be adding a log entry on the invoice for tracing purposes\n\n         self._log_event(cr, uid, ids, -1.0, 'Debit denied')\n\n      If not for that funny comment\n      \"#TODO: implement messages system\"  in account/invoice.py\n\n   Repeating non-fatal fatal errors need to be dealt with manually by checking\n   open invoices with a matured invoice- or due date.\n\"\"\"\n\nfrom openerp.osv import orm\nfrom openerp.tools.translate import _\n\n\nclass AccountInvoice(orm.Model):\n    _inherit = \"account.invoice\"\n\n    def _register_hook(self, cr):\n        \"\"\"\n        Adding a state to the hardcoded state list of the inherited\n        model. The alternative is duplicating the field definition\n        in columns but only one module can do that!\n\n        Maybe apply a similar trick when overriding the buttons' 'states'\n        attributes in the form view, manipulating the xml in fields_view_get().\n        \"\"\"\n        self._columns['state'].selection.append(\n            ('debit_denied', 'Debit denied'))\n\n    def action_debit_denied(self, cr, uid, ids, context=None):\n        for invoice_id in ids:\n            if self.test_paid(cr, uid, [invoice_id], context):\n                number = self.read(\n                    cr, uid, invoice_id, ['number'], context=context)['number']\n                raise orm.except_orm(\n                    _('Error !'),\n                    _(\"You cannot set invoice '%s' to state 'debit \"\n                      \"denied', as it is still reconciled.\") % number)\n        self.write(cr, uid, ids, {'state': 'debit_denied'}, context=context)\n        for inv_id, name in self.name_get(cr, uid, ids, context=context):\n            message = _(\"Invoice '%s': direct debit is denied.\") % name\n            self.log(cr, uid, inv_id, message)\n        return True\n\n    def test_undo_debit_denied(self, cr, uid, ids, context=None):\n        \"\"\"\n        Called from the workflow. Used to unset paid state on\n        invoices that were paid with bank transfers which are being cancelled\n        \"\"\"\n        for invoice in self.read(cr, uid, ids, ['reconciled'], context):\n            if not invoice['reconciled']:\n                return False\n        return True\n", "path": "account_direct_debit/models/account_invoice.py"}]}