mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[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:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "Move Stock Location",
|
"name": "Move Stock Location",
|
||||||
"version": "11.0.1.0.0",
|
"version": "11.0.1.0.1",
|
||||||
"author": "Julius Network Solutions, "
|
"author": "Julius Network Solutions, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
"summary": "This module allows to move all stock "
|
"summary": "This module allows to move all stock "
|
||||||
|
|||||||
BIN
stock_move_location/static/description/icon.png
Normal file
BIN
stock_move_location/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
@@ -30,10 +30,10 @@ class TestMoveLocation(TestsCommon):
|
|||||||
self.product_lots, self.internal_loc_1, 0, self.lot1,
|
self.product_lots, self.internal_loc_1, 0, self.lot1,
|
||||||
)
|
)
|
||||||
self.check_product_amount(
|
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.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.check_product_amount(
|
||||||
self.product_no_lots, self.internal_loc_2, 123,
|
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.product_lots, self.internal_loc_2, 1, self.lot1,
|
||||||
)
|
)
|
||||||
self.check_product_amount(
|
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.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):
|
def test_move_location_wizard_amount(self):
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
# Copyright 2018 Camptocamp SA
|
# Copyright 2018 Camptocamp SA
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
from itertools import groupby
|
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
@@ -58,22 +56,21 @@ class StockMoveLocationWizard(models.TransientModel):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def group_lines(self):
|
def group_lines(self):
|
||||||
sorted_lines = sorted(
|
lines_grouped = {}
|
||||||
self.stock_move_location_line_ids,
|
for line in self.stock_move_location_line_ids:
|
||||||
key=lambda x: x.product_id,
|
lines_grouped.setdefault(
|
||||||
)
|
line.product_id.id,
|
||||||
groups = groupby(sorted_lines, key=lambda x: x.product_id)
|
self.env["wiz.stock.move.location.line"].browse(),
|
||||||
groups_dict = {}
|
)
|
||||||
for prod, lines in groups:
|
lines_grouped[line.product_id.id] |= line
|
||||||
groups_dict[prod.id] = list(lines)
|
return lines_grouped
|
||||||
return groups_dict
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _create_moves(self, picking):
|
def _create_moves(self, picking):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
groups = self.group_lines()
|
groups = self.group_lines()
|
||||||
moves = self.env["stock.move"]
|
moves = self.env["stock.move"]
|
||||||
for group, lines in groups.items():
|
for lines in groups.values():
|
||||||
move = self._create_move(picking, lines)
|
move = self._create_move(picking, lines)
|
||||||
moves |= move
|
moves |= move
|
||||||
return moves
|
return moves
|
||||||
@@ -82,14 +79,14 @@ class StockMoveLocationWizard(models.TransientModel):
|
|||||||
# locations are same for the products
|
# locations are same for the products
|
||||||
location_from_id = lines[0].origin_location_id.id
|
location_from_id = lines[0].origin_location_id.id
|
||||||
location_to_id = lines[0].destination_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
|
product_uom_id = lines[0].product_uom_id.id
|
||||||
qty = sum([x.move_quantity for x in lines])
|
qty = sum([x.move_quantity for x in lines])
|
||||||
return {
|
return {
|
||||||
"name": "test",
|
"name": product.display_name,
|
||||||
"location_id": location_from_id,
|
"location_id": location_from_id,
|
||||||
"location_dest_id": location_to_id,
|
"location_dest_id": location_to_id,
|
||||||
"product_id": product_id,
|
"product_id": product.id,
|
||||||
"product_uom": product_uom_id,
|
"product_uom": product_uom_id,
|
||||||
"product_uom_qty": qty,
|
"product_uom_qty": qty,
|
||||||
"picking_id": picking.id,
|
"picking_id": picking.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user