[FIX] stock_move_location: fix the 'group_lines()' method

A recordset object is not reliable enough to use as a key for the
built-in 'sorted' and 'itertools.groupby' functions (sometimes it works,
sometimes not).
Using the ID of the record (here the product ID) can fix the problem, but the
'group_lines()' has been totally rewritten for a simpler implementation without
any use of 'sorted' or 'itertools.groupby' functions to group the wizard lines
by product: an iteration on lines to fill a dictionary does the job.
This commit is contained in:
sebalix
2019-02-07 17:19:32 +01:00
committed by João Marques
parent a05acd418c
commit 9bbd18b4b4
4 changed files with 17 additions and 20 deletions

View File

@@ -4,7 +4,7 @@
{
"name": "Move Stock Location",
"version": "11.0.1.0.0",
"version": "11.0.1.0.1",
"author": "Julius Network Solutions, "
"Odoo Community Association (OCA)",
"summary": "This module allows to move all stock "

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -30,10 +30,10 @@ class TestMoveLocation(TestsCommon):
self.product_lots, self.internal_loc_1, 0, self.lot1,
)
self.check_product_amount(
self.product_lots, self.internal_loc_1, 0, self.lot1,
self.product_lots, self.internal_loc_1, 0, self.lot2,
)
self.check_product_amount(
self.product_lots, self.internal_loc_1, 0, self.lot1,
self.product_lots, self.internal_loc_1, 0, self.lot3,
)
self.check_product_amount(
self.product_no_lots, self.internal_loc_2, 123,
@@ -42,10 +42,10 @@ class TestMoveLocation(TestsCommon):
self.product_lots, self.internal_loc_2, 1, self.lot1,
)
self.check_product_amount(
self.product_lots, self.internal_loc_2, 1, self.lot1,
self.product_lots, self.internal_loc_2, 1, self.lot2,
)
self.check_product_amount(
self.product_lots, self.internal_loc_2, 1, self.lot1,
self.product_lots, self.internal_loc_2, 1, self.lot3,
)
def test_move_location_wizard_amount(self):

View File

@@ -2,8 +2,6 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from itertools import groupby
from odoo import api, fields, models
@@ -58,22 +56,21 @@ class StockMoveLocationWizard(models.TransientModel):
@api.multi
def group_lines(self):
sorted_lines = sorted(
self.stock_move_location_line_ids,
key=lambda x: x.product_id,
lines_grouped = {}
for line in self.stock_move_location_line_ids:
lines_grouped.setdefault(
line.product_id.id,
self.env["wiz.stock.move.location.line"].browse(),
)
groups = groupby(sorted_lines, key=lambda x: x.product_id)
groups_dict = {}
for prod, lines in groups:
groups_dict[prod.id] = list(lines)
return groups_dict
lines_grouped[line.product_id.id] |= line
return lines_grouped
@api.multi
def _create_moves(self, picking):
self.ensure_one()
groups = self.group_lines()
moves = self.env["stock.move"]
for group, lines in groups.items():
for lines in groups.values():
move = self._create_move(picking, lines)
moves |= move
return moves
@@ -82,14 +79,14 @@ class StockMoveLocationWizard(models.TransientModel):
# locations are same for the products
location_from_id = lines[0].origin_location_id.id
location_to_id = lines[0].destination_location_id.id
product_id = lines[0].product_id.id
product = lines[0].product_id
product_uom_id = lines[0].product_uom_id.id
qty = sum([x.move_quantity for x in lines])
return {
"name": "test",
"name": product.display_name,
"location_id": location_from_id,
"location_dest_id": location_to_id,
"product_id": product_id,
"product_id": product.id,
"product_uom": product_uom_id,
"product_uom_qty": qty,
"picking_id": picking.id,