[FIX] stock: fix update of quantity in internal package transfer
Activate Delivery Packages option in the settings, and check "Move Entire Packages". Create a product, and update the quantity on hand (e.g. product X with 5 quantity in package Y in location shelf 1) Then,create an internal transfer (e.g. package Y from shelf 1 to shelf 2), check a first time the 'done' box and save. Finally, edit, uncheck and check again the 'done' box in the same operation and save. You will see (tracking message in the chatter) that the initial quantity is wrongly updated (doubled apparently). After saving, the 'done' box will be unchecked and the transfer cannot be validated with the following error message : "You cannot move the same package content more than once in the same transfer or split the same package into two location." This occur because on uncheck and recheck done checkbox the quantity is added again to the related move. opw-2350335 closes odoo/odoo#59494 X-original-commit: 2dbb8ef133bb49356ff1f7dacb2be8e7ed934697 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com> Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
from itertools import groupby
|
||||
from operator import itemgetter
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
@@ -51,10 +52,11 @@ class StockPackageLevel(models.Model):
|
||||
for package_level in self:
|
||||
if package_level.is_done:
|
||||
if not package_level.is_fresh_package:
|
||||
ml_update_dict = defaultdict(float)
|
||||
for quant in package_level.package_id.quant_ids:
|
||||
corresponding_ml = package_level.move_line_ids.filtered(lambda ml: ml.product_id == quant.product_id and ml.lot_id == quant.lot_id)
|
||||
if corresponding_ml:
|
||||
corresponding_ml[0].qty_done = corresponding_ml[0].qty_done + quant.quantity
|
||||
ml_update_dict[corresponding_ml[0]] += quant.quantity
|
||||
else:
|
||||
corresponding_move = package_level.move_ids.filtered(lambda m: m.product_id == quant.product_id)[:1]
|
||||
self.env['stock.move.line'].create({
|
||||
@@ -70,6 +72,8 @@ class StockPackageLevel(models.Model):
|
||||
'package_level_id': package_level.id,
|
||||
'move_id': corresponding_move.id,
|
||||
})
|
||||
for rec, quant in ml_update_dict.items():
|
||||
rec.qty_done = quant
|
||||
else:
|
||||
package_level.move_line_ids.filtered(lambda ml: ml.product_qty == 0).unlink()
|
||||
package_level.move_line_ids.filtered(lambda ml: ml.product_qty != 0).write({'qty_done': 0})
|
||||
|
||||
Reference in New Issue
Block a user