[FIX] stock,sale_mrp: Inventory adjustment not possible
1) Create a stockable product > Add some quantities on hand 2) Edit this product > set it as a consumable or service 3) Create an inventory adjustment on all products Error will raise "Something went wrong! You can only adjust storable products. This occur because when switching product type the available quantity was not cleared, so it will get in the next inventory, but only storable products can have inventory. So the product should to have no quantity left before switching type opw-2300478 closes odoo/odoo#55062 X-original-commit: be17e31307070498ba9ac7dc594443730caa7404 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
This commit is contained in:
@@ -784,6 +784,12 @@ msgstr ""
|
||||
msgid "Available Quantity"
|
||||
msgstr ""
|
||||
|
||||
#. module: stock
|
||||
#: code:addons/stock/models/product.py:581
|
||||
#, python-format
|
||||
msgid "Available quantity should be set to zero before changing type"
|
||||
msgstr ""
|
||||
|
||||
#. module: stock
|
||||
#: model:ir.model.fields,field_description:stock.field_stock_move__backorder_id
|
||||
#: model:ir.model.fields,field_description:stock.field_stock_picking__backorder_id
|
||||
|
||||
@@ -8,6 +8,7 @@ from collections import defaultdict
|
||||
from odoo import _, api, fields, models, SUPERUSER_ID
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import pycompat,float_is_zero
|
||||
from odoo.tools.float_utils import float_round
|
||||
|
||||
OPERATORS = {
|
||||
@@ -733,6 +734,8 @@ class ProductTemplate(models.Model):
|
||||
])
|
||||
if existing_move_lines:
|
||||
raise UserError(_("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."))
|
||||
if 'type' in vals and vals['type'] != 'product' and any(p.type == 'product' and not float_is_zero(p.qty_available, precision_rounding=p.uom_id.rounding) for p in self):
|
||||
raise UserError(_("Available quantity should be set to zero before changing type"))
|
||||
return super(ProductTemplate, self).write(vals)
|
||||
|
||||
# Be aware that the exact same function exists in product.product
|
||||
|
||||
@@ -4270,8 +4270,9 @@ class StockMove(SavepointCase):
|
||||
self.assertEqual(move1.state, 'assigned')
|
||||
|
||||
def test_change_product_type(self):
|
||||
""" Changing type of an existing product will raise a user error if some move
|
||||
are reserved.
|
||||
""" Changing type of an existing product will raise a user error if
|
||||
- some move are reserved
|
||||
- switching from a stockable product when qty_available is not zero
|
||||
"""
|
||||
self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 10)
|
||||
move1 = self.env['stock.move'].create({
|
||||
@@ -4289,6 +4290,11 @@ class StockMove(SavepointCase):
|
||||
with self.assertRaises(UserError):
|
||||
self.product.type = 'consu'
|
||||
move1._action_cancel()
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
self.product.type = 'consu'
|
||||
|
||||
self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, -self.product.qty_available)
|
||||
self.product.type = 'consu'
|
||||
|
||||
move2 = self.env['stock.move'].create({
|
||||
|
||||
Reference in New Issue
Block a user