Skip to Content
Menu
This question has been flagged

A warehouse user received products that were accidentally setup as CONSUMABLE instead of STOCKABLE.

We need the product changed, how can we do this without triggering the error?

Error: You can not change the type of a product that is currently reserved on a  stock move. If you need to change the type, you should first unreserve the stock move.

The stock move is completed, and I can't edit it.

Avatar
Discard
Best Answer

This Server Action can resolve this for you.  

Note: Please understand that you are deleting stock moves that are already in the system and you should be fully aware of the implications of this before you use this in a production system.   This process will leave the Receipt Transfers in DRAFT state so you will also need to delete them to clean up everything.


Code:

for record in records:
moves = env['stock.move'].sudo().search([('product_id','=',record.id)])
for move in moves:
move.sudo().write({'state' : 'draft' })
move.sudo().unlink()
record['type'] = 'product'
Avatar
Discard

hi there, i created this server action but nothing happened. how to run it? thanks

Click "Create Contextual Action" and find a new option in the ACTION Menu when you open a single product in Form View or select multiple products from the List View.

This code was working from me on V17 Thank you
recently we upgrade to V17.4 and now getting error as below
RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/src/odoo/saas-17.4/odoo/tools/safe_eval.py", line 391, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "ir.actions.server(1080,)", line 6, in <module>
File "/home/odoo/src/odoo/saas-17.4/odoo/models.py", line 6751, in __setitem__
return self._fields[key].__set__(self, value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/fields.py", line 1378, in __set__
records.write({self.name: write_value})
File "/home/odoo/src/odoo/saas-17.4/addons/sale_project/models/product_template.py", line 137, in write
return super().write(vals)
^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/website_sale/models/product_template.py", line 186, in write
return super().write(vals)
^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/rating/models/rating_mixin.py", line 100, in write
result = super(RatingMixin, self).write(values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/stock_landed_costs/models/product.py", line 23, in write
return super().write(vals)
^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/stock_account/models/product.py", line 55, in write
res = super(ProductTemplate, self).write(vals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/stock/models/product.py", line 932, in write
return super().write(vals)
^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/product/models/product_template.py", line 481, in write
res = super(ProductTemplate, self).write(vals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/mail/models/mail_thread.py", line 331, in write
result = super(MailThread, self).write(values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/mail/models/mail_activity_mixin.py", line 249, in write
return super(MailActivityMixin, self).write(vals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/website/models/mixins.py", line 219, in write
return super(WebsitePublishedMixin, self).write(values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/models.py", line 4561, in write
field.write(self, value)
File "/home/odoo/src/odoo/saas-17.4/odoo/fields.py", line 1177, in write
cache_value = self.convert_to_cache(value, records)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/fields.py", line 2907, in convert_to_cache
raise ValueError("Wrong value for %s: %r" % (self, value))
ValueError: Wrong value for product.template.type: 'product'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/odoo/src/odoo/saas-17.4/odoo/http.py", line 1987, in _transactioning
return service_model.retrying(func, env=self.env)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/service/model.py", line 134, in retrying
result = func()
^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/http.py", line 1954, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/http.py", line 2198, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/addons/base/models/ir_http.py", line 226, in _dispatch
result = endpoint(**request.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/http.py", line 756, in route_wrapper
result = endpoint(self, *args, **params_ok)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/web/controllers/action.py", line 58, in run
result = action.run()
^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/addons/base/models/ir_actions.py", line 989, in run
res = runner(run_self, eval_context=eval_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/addons/website/models/ir_actions_server.py", line 61, in _run_action_code_multi
res = super(ServerAction, self)._run_action_code_multi(eval_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/addons/base/models/ir_actions.py", line 821, in _run_action_code_multi
safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True, filename=str(self)) # nocopy allows to return 'action'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/odoo/src/odoo/saas-17.4/odoo/tools/safe_eval.py", line 405, in safe_eval
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
ValueError: <class 'ValueError'>: "Wrong value for product.template.type: 'product'" while evaluating
"for record in records:\r\n moves = env['stock.move'].sudo().search([('product_id','=',record.id)])\r\n for move in moves:\r\n move.sudo().write({'state' : 'draft' })\r\n move.sudo().unlink()\r\n record['type'] = 'product'"

I appreciate your advice

Best Answer

Hi Ray, 

Do you have any tips when the product has already been sold ? 

The script run well but it gave an error with such product. 

Thank you 

Romain 

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 22
2589
1
Jan 19
5138
2
Mar 19
3982
4
Jan 25
1428
2
Mar 22
9118