We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
is:issue is:open [8.0][mrp_production_real_cost] Error when produce product
Hi,

there's new error from mrp_production_real_cost, after I do git pull from the last commit 

```

ERROR demo1 openerp.sql_db: Programming error: can't adapt type 'mrp.production', in query  SELECT "mrp_production"."id" FROM "mrp_production"
                        WHERE "mrp_production".id IN %s  ORDER BY "mrp_production"."priority" DESC,"mrp_production"."date_planned" ASC         

  File "/opt/odoo/server/addons/mrp_production_real_cost/models/mrp_production.py", line 34, in action_production_end
    self.mapped('move_created_ids2').filtered(


  File "/usr/lib/python2.7/dist-packages/psycopg2/extensions.py", line 129, in getquoted
    pobjs = [adapt(o) for o in self._seq]
ValueError: "can't adapt type 'mrp.production'" while evaluating
u'action_production_end()'
```

regards


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mrp_production_real_cost/models/mrp_production.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # © 2014-2015 Avanzosc
3 # © 2014-2015 Pedro M. Baeza
4 # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
5 
6 from openerp import api, fields, models
7 
8 
9 class MrpProduction(models.Model):
10     _inherit = 'mrp.production'
11 
12     @api.multi
13     @api.depends('analytic_line_ids', 'analytic_line_ids.amount',
14                  'product_qty')
15     def _compute_real_cost(self):
16         for production in self:
17             cost_lines = production.analytic_line_ids.filtered(
18                 lambda l: l.amount < 0)
19             production.real_cost = -sum(cost_lines.mapped('amount'))
20             production.unit_real_cost = (
21                 production.real_cost / production.product_qty)
22 
23     analytic_line_ids = fields.One2many(
24         comodel_name="account.analytic.line", inverse_name="mrp_production_id",
25         string="Cost Lines")
26     real_cost = fields.Float(
27         "Total Real Cost", compute="_compute_real_cost", store=True)
28     unit_real_cost = fields.Float(
29         "Unit Real Cost", compute="_compute_real_cost", store=True)
30 
31     @api.multi
32     def action_production_end(self):
33         res = super(MrpProduction, self).action_production_end()
34         self.mapped('move_created_ids2').filtered(
35             lambda l: l.state == 'done').product_price_update_production_done()
36         return res
37 
38     @api.model
39     def _prepare_real_cost_analytic_line(
40             self, journal, name, production, product, general_account=None,
41             workorder=None, qty=1, amount=0):
42         """
43         Prepare the vals for creating an analytic entry for real cost
44         :param journal: Journal of the entry
45         :param name: Name of the entry
46         :param production: Origin product
47         :param product: Product for the entry
48         :param general_account: General account for the entry
49         :param workorder: Origin workorder
50         :param qty: Quantity for the entry. This quantity will multiply both
51         standard and average costs for the entry costs.
52         :param amount: Cost for calculating real cost.
53         :return: Dictionary with the analytic entry vals.
54         """
55         analytic_line_obj = self.env['account.analytic.line']
56         property_obj = self.env['ir.property']
57         general_account = (
58             general_account or product.property_account_expense or
59             product.categ_id.property_account_expense_categ or
60             property_obj.get('property_account_expense_categ',
61                              'product.category'))
62         return {
63             'name': name,
64             'mrp_production_id': production.id,
65             'workorder': workorder and workorder.id or False,
66             'account_id': self.analytic_account_id.id,
67             'journal_id': journal.id,
68             'user_id': self.env.uid,
69             'date': analytic_line_obj._get_default_date(),
70             'product_id': product and product.id or False,
71             'unit_amount': qty,
72             'amount': amount,
73             'product_uom_id': product.uom_id.id,
74             'general_account_id': general_account.id,
75         }
76 
77     @api.multi
78     def _costs_generate(self):
79         """
80         As we are generating the account_analytic_lines for MO in the
81         current module, we override this method in order to avoid
82         duplicates created in the parent class. Any other module
83         inheriting this method should take this into account!
84         """
85         return
86
```
--- 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/mrp_production_real_cost/models/mrp_production.py b/mrp_production_real_cost/models/mrp_production.py
--- a/mrp_production_real_cost/models/mrp_production.py
+++ b/mrp_production_real_cost/models/mrp_production.py
@@ -31,8 +31,15 @@
     @api.multi
     def action_production_end(self):
         res = super(MrpProduction, self).action_production_end()
-        self.mapped('move_created_ids2').filtered(
-            lambda l: l.state == 'done').product_price_update_production_done()
+        for production in self:
+            # This is needed because commit
+            # https://github.com/odoo/odoo/commit/
+            # 6f29bfc181d23d70d29776d96b4318e9ee2c93a9
+            # introduces a weird behavior on the next call, provoking an error.
+            production.sudo().refresh()
+            production.mapped('move_created_ids2').filtered(
+                lambda l: l.state == 'done'
+                ).product_price_update_production_done()
         return res
 
     @api.model

{"golden_diff": "diff --git a/mrp_production_real_cost/models/mrp_production.py b/mrp_production_real_cost/models/mrp_production.py\n--- a/mrp_production_real_cost/models/mrp_production.py\n+++ b/mrp_production_real_cost/models/mrp_production.py\n@@ -31,8 +31,15 @@\n     @api.multi\n     def action_production_end(self):\n         res = super(MrpProduction, self).action_production_end()\n-        self.mapped('move_created_ids2').filtered(\n-            lambda l: l.state == 'done').product_price_update_production_done()\n+        for production in self:\n+            # This is needed because commit\n+            # https://github.com/odoo/odoo/commit/\n+            # 6f29bfc181d23d70d29776d96b4318e9ee2c93a9\n+            # introduces a weird behavior on the next call, provoking an error.\n+            production.sudo().refresh()\n+            production.mapped('move_created_ids2').filtered(\n+                lambda l: l.state == 'done'\n+                ).product_price_update_production_done()\n         return res\n \n     @api.model\n", "issue": "is:issue is:open [8.0][mrp_production_real_cost] Error when produce product\nHi,\n\nthere's new error from mrp_production_real_cost, after I do git pull from the last commit \n\n```\n\nERROR demo1 openerp.sql_db: Programming error: can't adapt type 'mrp.production', in query  SELECT \"mrp_production\".\"id\" FROM \"mrp_production\"\n                        WHERE \"mrp_production\".id IN %s  ORDER BY \"mrp_production\".\"priority\" DESC,\"mrp_production\".\"date_planned\" ASC         \n\n  File \"/opt/odoo/server/addons/mrp_production_real_cost/models/mrp_production.py\", line 34, in action_production_end\n    self.mapped('move_created_ids2').filtered(\n\n\n  File \"/usr/lib/python2.7/dist-packages/psycopg2/extensions.py\", line 129, in getquoted\n    pobjs = [adapt(o) for o in self._seq]\nValueError: \"can't adapt type 'mrp.production'\" while evaluating\nu'action_production_end()'\n```\n\nregards\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# \u00a9 2014-2015 Avanzosc\n# \u00a9 2014-2015 Pedro M. Baeza\n# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html\n\nfrom openerp import api, fields, models\n\n\nclass MrpProduction(models.Model):\n    _inherit = 'mrp.production'\n\n    @api.multi\n    @api.depends('analytic_line_ids', 'analytic_line_ids.amount',\n                 'product_qty')\n    def _compute_real_cost(self):\n        for production in self:\n            cost_lines = production.analytic_line_ids.filtered(\n                lambda l: l.amount < 0)\n            production.real_cost = -sum(cost_lines.mapped('amount'))\n            production.unit_real_cost = (\n                production.real_cost / production.product_qty)\n\n    analytic_line_ids = fields.One2many(\n        comodel_name=\"account.analytic.line\", inverse_name=\"mrp_production_id\",\n        string=\"Cost Lines\")\n    real_cost = fields.Float(\n        \"Total Real Cost\", compute=\"_compute_real_cost\", store=True)\n    unit_real_cost = fields.Float(\n        \"Unit Real Cost\", compute=\"_compute_real_cost\", store=True)\n\n    @api.multi\n    def action_production_end(self):\n        res = super(MrpProduction, self).action_production_end()\n        self.mapped('move_created_ids2').filtered(\n            lambda l: l.state == 'done').product_price_update_production_done()\n        return res\n\n    @api.model\n    def _prepare_real_cost_analytic_line(\n            self, journal, name, production, product, general_account=None,\n            workorder=None, qty=1, amount=0):\n        \"\"\"\n        Prepare the vals for creating an analytic entry for real cost\n        :param journal: Journal of the entry\n        :param name: Name of the entry\n        :param production: Origin product\n        :param product: Product for the entry\n        :param general_account: General account for the entry\n        :param workorder: Origin workorder\n        :param qty: Quantity for the entry. This quantity will multiply both\n        standard and average costs for the entry costs.\n        :param amount: Cost for calculating real cost.\n        :return: Dictionary with the analytic entry vals.\n        \"\"\"\n        analytic_line_obj = self.env['account.analytic.line']\n        property_obj = self.env['ir.property']\n        general_account = (\n            general_account or product.property_account_expense or\n            product.categ_id.property_account_expense_categ or\n            property_obj.get('property_account_expense_categ',\n                             'product.category'))\n        return {\n            'name': name,\n            'mrp_production_id': production.id,\n            'workorder': workorder and workorder.id or False,\n            'account_id': self.analytic_account_id.id,\n            'journal_id': journal.id,\n            'user_id': self.env.uid,\n            'date': analytic_line_obj._get_default_date(),\n            'product_id': product and product.id or False,\n            'unit_amount': qty,\n            'amount': amount,\n            'product_uom_id': product.uom_id.id,\n            'general_account_id': general_account.id,\n        }\n\n    @api.multi\n    def _costs_generate(self):\n        \"\"\"\n        As we are generating the account_analytic_lines for MO in the\n        current module, we override this method in order to avoid\n        duplicates created in the parent class. Any other module\n        inheriting this method should take this into account!\n        \"\"\"\n        return\n", "path": "mrp_production_real_cost/models/mrp_production.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# \u00a9 2014-2015 Avanzosc\n# \u00a9 2014-2015 Pedro M. Baeza\n# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html\n\nfrom openerp import api, fields, models\n\n\nclass MrpProduction(models.Model):\n    _inherit = 'mrp.production'\n\n    @api.multi\n    @api.depends('analytic_line_ids', 'analytic_line_ids.amount',\n                 'product_qty')\n    def _compute_real_cost(self):\n        for production in self:\n            cost_lines = production.analytic_line_ids.filtered(\n                lambda l: l.amount < 0)\n            production.real_cost = -sum(cost_lines.mapped('amount'))\n            production.unit_real_cost = (\n                production.real_cost / production.product_qty)\n\n    analytic_line_ids = fields.One2many(\n        comodel_name=\"account.analytic.line\", inverse_name=\"mrp_production_id\",\n        string=\"Cost Lines\")\n    real_cost = fields.Float(\n        \"Total Real Cost\", compute=\"_compute_real_cost\", store=True)\n    unit_real_cost = fields.Float(\n        \"Unit Real Cost\", compute=\"_compute_real_cost\", store=True)\n\n    @api.multi\n    def action_production_end(self):\n        res = super(MrpProduction, self).action_production_end()\n        for production in self:\n            # This is needed because commit\n            # https://github.com/odoo/odoo/commit/\n            # 6f29bfc181d23d70d29776d96b4318e9ee2c93a9\n            # introduces a weird behavior on the next call, provoking an error.\n            production.sudo().refresh()\n            production.mapped('move_created_ids2').filtered(\n                lambda l: l.state == 'done'\n                ).product_price_update_production_done()\n        return res\n\n    @api.model\n    def _prepare_real_cost_analytic_line(\n            self, journal, name, production, product, general_account=None,\n            workorder=None, qty=1, amount=0):\n        \"\"\"\n        Prepare the vals for creating an analytic entry for real cost\n        :param journal: Journal of the entry\n        :param name: Name of the entry\n        :param production: Origin product\n        :param product: Product for the entry\n        :param general_account: General account for the entry\n        :param workorder: Origin workorder\n        :param qty: Quantity for the entry. This quantity will multiply both\n        standard and average costs for the entry costs.\n        :param amount: Cost for calculating real cost.\n        :return: Dictionary with the analytic entry vals.\n        \"\"\"\n        analytic_line_obj = self.env['account.analytic.line']\n        property_obj = self.env['ir.property']\n        general_account = (\n            general_account or product.property_account_expense or\n            product.categ_id.property_account_expense_categ or\n            property_obj.get('property_account_expense_categ',\n                             'product.category'))\n        return {\n            'name': name,\n            'mrp_production_id': production.id,\n            'workorder': workorder and workorder.id or False,\n            'account_id': self.analytic_account_id.id,\n            'journal_id': journal.id,\n            'user_id': self.env.uid,\n            'date': analytic_line_obj._get_default_date(),\n            'product_id': product and product.id or False,\n            'unit_amount': qty,\n            'amount': amount,\n            'product_uom_id': product.uom_id.id,\n            'general_account_id': general_account.id,\n        }\n\n    @api.multi\n    def _costs_generate(self):\n        \"\"\"\n        As we are generating the account_analytic_lines for MO in the\n        current module, we override this method in order to avoid\n        duplicates created in the parent class. Any other module\n        inheriting this method should take this into account!\n        \"\"\"\n        return\n", "path": "mrp_production_real_cost/models/mrp_production.py"}]}