Repository: OCA/manufacture

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



Discussion:
You need to update your module and restart server.

I've already update the module and all dependency and restart server, but still error.
I try to uninstall, after that manufacturing can do produce, but when I install again there's same error when I push the button produce.

The log you have put proves that it wasn't updated and restarted, because the referenced line is not the same as the shown one. Has the error log changed?

I just had the same error, I've updated all my repositories this morning and the database aswell

**ValueError: "can't adapt type 'mrp.production'" while evaluating
u'action_production_end()'**

Do you have a module from odoomrp-wip called mrp_production_manual_close or similar?

I don't have that module installed

Then please give me an update error log. The first one is not correct

2016-05-16 09:40:36,433 3675 ERROR CursoEjercicios openerp.sql_db: Programming error: can't adapt type 'mrp.production', in query  SELECT "mrp_production"."write_uid","mrp_production"."std_cost","mrp_production"."percentage_difference","mrp_production"."partner","mrp_production"."project_id","mrp_production"."origin","mrp_production"."product_uos","mrp_production"."location_dest_id","mrp_production"."state","mrp_production"."product_qty","mrp_production"."bom_id","mrp_production"."user_id","mrp_production"."ready_production","mrp_production"."unit_avg_cost","mrp_production"."date_finished","mrp_production"."sale_order","mrp_production"."create_uid","mrp_production"."priority","mrp_production"."analytic_account_id","mrp_production"."total_hours","mrp_production"."product_uom","mrp_production"."date_planned","mrp_production"."unit_real_cost","mrp_production"."routing_id","mrp_production"."create_date","mrp_production"."hour_total","mrp_production"."active","mrp_production"."cycle_total","mrp_production"."real_cost","mrp_production"."company_id","mrp_production"."move_prod_id","mrp_production"."product_uos_qty","mrp_production"."product_id","mrp_production"."write_date","mrp_production"."message_last_post","mrp_production"."name","mrp_production"."date_start","mrp_production"."location_src_id","mrp_production"."avg_cost","mrp_production"."id","mrp_production"."allow_reorder","mrp_production"."unit_std_cost" FROM "mrp_production"
                        WHERE "mrp_production".id IN %s AND (("mrp_production"."company_id" in (%s))  OR  "mrp_production"."company_id" IS NULL )  ORDER BY "mrp_production"."priority" DESC,"mrp_production"."date_planned" ASC 

2016-05-16 09:40:36,434 3675 ERROR CursoEjercicios openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/opt/odoo/odoo-server/openerp/http.py", line 540, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo-server/openerp/http.py", line 577, in dispatch
    result = self._call_function(*_self.params)
  File "/opt/odoo/odoo-server/openerp/http.py", line 313, in _call_function
    return checked_call(self.db, *args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/service/model.py", line 118, in wrapper
    return f(dbname, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/http.py", line 310, in checked_call
    return self.endpoint(_a, *_kw)
  File "/opt/odoo/odoo-server/openerp/http.py", line 806, in __call__
    return self.method(_args, *_kw)
  File "/opt/odoo/odoo-server/openerp/http.py", line 406, in response_wrap
    response = f(_args, *_kw)
  File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 948, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/api.py", line 399, in old_api
    result = method(recs, _args, *_kwargs)
  File "/opt/odoo/odoomrp-wip/mrp_production_real_costs/wizard/mrp_product_produce.py", line 15, in do_produce
    res = super(MrpProductProduce, self).do_produce()
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/api.py", line 592, in new_api
    result = method(self._model, cr, uid, self.ids, _args, *_old_kwargs)
  File "/opt/odoo/odoo-server/addons/mrp/wizard/mrp_product_produce.py", line 126, in do_produce
    data.product_qty, data.mode, data, context=context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/addons/mrp/mrp.py", line 1028, in action_produce
    self.signal_workflow(cr, uid, [production_id], 'button_produce_done')
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/models.py", line 3571, in signal_workflow
    result[res_id] = workflow.trg_validate(uid, self._name, res_id, signal, cr)
  File "/opt/odoo/odoo-server/openerp/workflow/__init__.py", line 85, in trg_validate
    return WorkflowService.new(cr, uid, res_type, res_id).validate(signal)
  File "/opt/odoo/odoo-server/openerp/workflow/service.py", line 91, in validate
    res2 = wi.validate(signal)
  File "/opt/odoo/odoo-server/openerp/workflow/instance.py", line 80, in validate
    wi.process(signal=signal, force_running=force_running, stack=stack)
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 120, in process
    ok = self._split_test(activity['split_mode'], signal, stack)
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 248, in _split_test
    self._join_test(t[0], t[1], stack)
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 257, in _join_test
    WorkflowItem.create(self.session, self.record, activity, inst_id, stack=stack)
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 95, in create
    workflow_item.process(stack=stack)
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 116, in process
    if not self._execute(activity, stack):
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 162, in _execute
    returned_action = self.wkf_expr_execute(activity)
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 313, in wkf_expr_execute
    return self.wkf_expr_eval_expr(activity['action'])
  File "/opt/odoo/odoo-server/openerp/workflow/workitem.py", line 291, in wkf_expr_eval_expr
    result = eval(line, env, nocopy=True)
  File "/opt/odoo/odoo-server/openerp/tools/safe_eval.py", line 314, in safe_eval
    return eval(c, globals_dict, locals_dict)
  File "", line 1, in <module>
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/odoomrp-wip/mrp_production_real_costs/models/mrp_production.py", line 57, in action_production_end
    res = super(MrpProduction, self).action_production_end()
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/odoomrp-wip/product_last_mrp_info/models/mrp_production.py", line 14, in action_production_end
    result = super(MrpProduction, self).action_production_end()
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/manufacture/mrp_production_real_cost/models/mrp_production.py", line 33, in action_production_end
    res = super(MrpProduction, self).action_production_end()
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/api.py", line 592, in new_api
    result = method(self._model, cr, uid, self.ids, _args, *_old_kwargs)
  File "/opt/odoo/odoo-server/addons/mrp_operations/mrp_operations.py", line 220, in action_production_end
    return super(mrp_production,self).action_production_end(cr, uid, ids, context=context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/addons/mrp/mrp.py", line 817, in action_production_end
    proc_obj.check(cr, uid, procs, context=context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/addons/procurement/procurement.py", line 228, in check
    result = self._check(cr, uid, procurement, context=context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/addons/purchase/purchase.py", line 1342, in _check
    return super(procurement_order, self)._check(cr, uid, procurement, context=context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/addons/mrp/procurement.py", line 56, in _check
    if procurement.production_id and procurement.production_id.state == 'done':  # TOCHECK: no better method?
  File "/opt/odoo/odoo-server/openerp/fields.py", line 834, in __get__
    self.determine_value(record)
  File "/opt/odoo/odoo-server/openerp/fields.py", line 927, in determine_value
    record._prefetch_field(self)
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/models.py", line 3242, in _prefetch_field
    result = records.read(list(fnames), load='_classic_write')
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/models.py", line 3179, in read
    self._read_from_database(stored, inherited)
  File "/opt/odoo/odoo-server/openerp/api.py", line 266, in wrapper
    return new_api(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/models.py", line 3311, in _read_from_database
    cr.execute(query_str, [tuple(sub_ids)] + where_params)
  File "/opt/odoo/odoo-server/openerp/sql_db.py", line 158, in wrapper
    return f(self, _args, *_kwargs)
  File "/opt/odoo/odoo-server/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
  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()'

this my error log 

```
2016-05-16 12:05:35,475 14503 WARNING demo1 openerp.models: Comparing apples and oranges: mrp.production(683,) == 683 (/opt/odoo/server/openerp/models.py:5542)
2016-05-16 12:05:35,476 14503 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 

2016-05-16 12:05:35,476 14503 ERROR demo1 openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/opt/odoo/server/openerp/http.py", line 540, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/server/openerp/http.py", line 577, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/server/openerp/http.py", line 313, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/server/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/server/openerp/http.py", line 310, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoo/server/openerp/http.py", line 806, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/server/openerp/http.py", line 406, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/server/addons/web/controllers/main.py", line 948, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/server/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoo/server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/api.py", line 399, in old_api
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/server/addons/mrp_production_traceability/wizard/mrp_product_produce.py", line 37, in do_produce
    result = super(MrpProductProduce, self).do_produce()
  File "/opt/odoo/server/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/api.py", line 592, in new_api
    result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
  File "/opt/odoo/server/addons/mrp/wizard/mrp_product_produce.py", line 126, in do_produce
    data.product_qty, data.mode, data, context=context)
  File "/opt/odoo/server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/api.py", line 372, in old_api
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/server/addons/quality_control_mrp/models/mrp_production.py", line 28, in action_produce
    production_id, production_qty, production_mode, wiz=wiz)
  File "/opt/odoo/server/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/server/addons/mrp_final_product_lot/models/mrp_production.py", line 48, in action_produce
    production_id, production_qty, production_mode, wiz=wiz)
  File "/opt/odoo/server/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/api.py", line 508, in new_api
    result = method(self._model, cr, uid, *args, **old_kwargs)
  File "/opt/odoo/server/addons/mrp/mrp.py", line 1028, in action_produce
    self.signal_workflow(cr, uid, [production_id], 'button_produce_done')
  File "/opt/odoo/server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/models.py", line 3571, in signal_workflow
    result[res_id] = workflow.trg_validate(uid, self._name, res_id, signal, cr)
  File "/opt/odoo/server/openerp/workflow/__init__.py", line 85, in trg_validate
    return WorkflowService.new(cr, uid, res_type, res_id).validate(signal)
  File "/opt/odoo/server/openerp/workflow/service.py", line 91, in validate
    res2 = wi.validate(signal)
  File "/opt/odoo/server/openerp/workflow/instance.py", line 80, in validate
    wi.process(signal=signal, force_running=force_running, stack=stack)
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 120, in process
    ok = self._split_test(activity['split_mode'], signal, stack)
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 248, in _split_test
    self._join_test(t[0], t[1], stack)
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 257, in _join_test
    WorkflowItem.create(self.session, self.record, activity, inst_id, stack=stack)
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 95, in create
    workflow_item.process(stack=stack)
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 116, in process
    if not self._execute(activity, stack):
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 162, in _execute
    returned_action = self.wkf_expr_execute(activity)
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 313, in wkf_expr_execute
    return self.wkf_expr_eval_expr(activity['action'])
  File "/opt/odoo/server/openerp/workflow/workitem.py", line 291, in wkf_expr_eval_expr
    result = eval(line, env, nocopy=True)
  File "/opt/odoo/server/openerp/tools/safe_eval.py", line 314, in safe_eval
    return eval(c, globals_dict, locals_dict)
  File "", line 1, in <module>
  File "/opt/odoo/server/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  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 "/opt/odoo/server/openerp/models.py", line 5423, in mapped
    recs = recs._mapped_func(operator.itemgetter(name))
  File "/opt/odoo/server/openerp/models.py", line 5403, in _mapped_func
    vals = [func(rec) for rec in self]
  File "/opt/odoo/server/openerp/models.py", line 5641, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/opt/odoo/server/openerp/fields.py", line 834, in __get__
    self.determine_value(record)
  File "/opt/odoo/server/openerp/fields.py", line 927, in determine_value
    record._prefetch_field(self)
  File "/opt/odoo/server/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/models.py", line 3242, in _prefetch_field
    result = records.read(list(fnames), load='_classic_write')
  File "/opt/odoo/server/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/models.py", line 3179, in read
    self._read_from_database(stored, inherited)
  File "/opt/odoo/server/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/models.py", line 3311, in _read_from_database
    cr.execute(query_str, [tuple(sub_ids)] + where_params)
  File "/opt/odoo/server/openerp/sql_db.py", line 158, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
  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()'
2016-05-16 12:05:36,675 14503 INFO demo1 werkzeug: 10.10.10.1 - - [16/May/2016 12:05:36] "POST /web/dataset/call_button HTTP/1.1" 200 -
```

Hi Pedro,

Could you help me, which modules that should update? I've already update many modules but still cannot use produce button if mrp_production_real_cost installed.
Last week there's no problem with this module.

I noticed thats some Warning message log when I restart the server.

```
2016-05-16 15:38:30,911 14503 WARNING demo1 openerp.modules.loading: Model product.attribute.configurator is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)
2016-05-16 15:38:30,911 14503 WARNING demo1 openerp.modules.loading: Model product.product.attribute is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)
2016-05-16 15:38:30,912 14503 WARNING demo1 openerp.modules.loading: Model mrp.production.attribute is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)
2016-05-16 15:38:30,912 14503 WARNING demo1 openerp.modules.loading: Model mrp.production.product.line.attribute is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)
```

Is this warning has relation with the problems?

Thanks.

Sorry, but I'm not able to reproduce the problem, local nor on runbot. Have you tried to reproduce it on runbot?

I check the module at runbot, and I noticed that I have 2 module for MRP Project Link.
I tried to uninstall one from the odoomrp, and update all modules again, but the error still same :(

When I uninstall mrp_product_variant there's error for mrp.production.product.line.attribute'

```
  File "/opt/odoo/server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/server/openerp/addons/base/ir/ir_model.py", line 544, in _module_data_uninstall
    model_obj = self.pool[model]
  File "/opt/odoo/server/openerp/modules/registry.py", line 102, in __getitem__
    return self.models[model_name]
KeyError: u'mrp.production.product.line.attribute'
```

I think it's related with the "mrp.production.product.line.attribute", but I cannot find how to update this models.

I confirm that the error goes away when I uninstall mrp_production_real_cost

Yes, the error goes away for me too.

But I need this module.

On 18/05/16 14:26, Sandra Figueroa wrote:

> I confirm that the error goes away when I uninstall 
> mrp_production_real_cost

You can fix this temporally moving your OCB git proyect to this commit https://github.com/OCA/OCB/commit/e6016c6627d76a5d3f62d4812c0c4b3dba217725

```
git checkout e6016c6627d76a5d3f62d4812c0c4b3dba217725
```

Until this  bug is fixed you can not update OCB

I think that the suspicious commit is https://github.com/OCA/OCB/commit/3a32021122c503d64aee960124f0bc70222ce972, because this issue is related with the fact that the production is written (here: https://github.com/OCA/OCB/blob/8.0/addons/mrp/mrp.py#L813) and then browsed again. Error will raise only when reading 'state' and 'date_finished' (here: https://github.com/OCA/OCB/blob/8.0/addons/mrp/procurement.py#L56). If you read another production field, no problem.

I can't figure out why this weird behavior. `mrp_production_real_cost` does something that broke production?

The commit that causes the fail is https://github.com/OCA/OCB/commit/6f29bfc181d23d70d29776d96b4318e9ee2c93a9

Is just a line but if you add it to the last OCB it works fine.


Resolving patch:
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 @@ def _compute_real_cost(self):
     @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


Test patch: