Skip to content

Commit

Permalink
[MIG] stock_move_location: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yankinmax committed Jan 23, 2025
1 parent d341296 commit 6287135
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 121 deletions.
2 changes: 1 addition & 1 deletion stock_move_location/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "Move Stock Location",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"author": "Julius Network Solutions, "
"BCIM,"
"Camptocamp,"
Expand Down
1 change: 0 additions & 1 deletion stock_move_location/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from . import stock_move
from . import stock_move_line
from . import stock_picking_type
from . import stock_picking
20 changes: 0 additions & 20 deletions stock_move_location/models/stock_move_line.py

This file was deleted.

1 change: 0 additions & 1 deletion stock_move_location/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def button_fillwithstock(self):
}
)
)
move_wizard._onchange_destination_location_id()
move_wizard.action_move_location()
return True

Expand Down
24 changes: 12 additions & 12 deletions stock_move_location/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright (C) 2011 Julius Network Solutions SARL <[email protected]>
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo.tests import Form

from odoo.tests import Form, common
from odoo.addons.base.tests.common import BaseCommon


class TestsCommon(common.TransactionCase):
class TestsCommon(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.location_obj = cls.env["stock.location"]
product_obj = cls.env["product.product"]
cls.product_obj = cls.env["product.product"]
cls.wizard_obj = cls.env["wiz.stock.move.location"]
cls.quant_obj = cls.env["stock.quant"]
cls.company = cls.env.ref("base.main_company")
Expand Down Expand Up @@ -43,14 +43,14 @@ def setUpClass(cls):
}
)
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.product_no_lots = product_obj.create(
{"name": "Pineapple", "type": "product", "tracking": "none"}
cls.product_no_lots = cls.product_obj.create(
{"name": "Pineapple", "is_storable": True, "tracking": "none"}
)
cls.product_lots = product_obj.create(
{"name": "Apple", "type": "product", "tracking": "lot"}
cls.product_lots = cls.product_obj.create(
{"name": "Apple", "is_storable": True, "tracking": "lot"}
)
cls.product_package = product_obj.create(
{"name": "Orange", "type": "product", "tracking": "lot"}
cls.product_package = cls.product_obj.create(
{"name": "Orange", "is_storable": True, "tracking": "lot"}
)
cls.lot1 = cls.env["stock.lot"].create(
{
Expand All @@ -73,8 +73,8 @@ def setUpClass(cls):
"company_id": cls.company.id,
}
)
cls.product_package = product_obj.create(
{"name": "Orange", "type": "product", "tracking": "lot"}
cls.product_package = cls.product_obj.create(
{"name": "Orange", "is_storable": True, "tracking": "lot"}
)
cls.lot4 = cls.env["stock.lot"].create(
{
Expand Down
26 changes: 9 additions & 17 deletions stock_move_location/tests/test_move_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def test_wizard_clear_lines(self):
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.onchange_origin_location()
self.assertEqual(len(wizard.stock_move_location_line_ids), 7)
wizard._onchange_destination_location_id()
self.assertEqual(len(wizard.stock_move_location_line_ids), 7)
dest_location_line = wizard.stock_move_location_line_ids.mapped(
"destination_location_id"
)
Expand All @@ -97,7 +95,7 @@ def test_wizard_onchange_origin_location(self):
"""Test a product that have existing quants with undefined quantity."""

product_not_available = self.env["product.product"].create(
{"name": "Mango", "type": "product", "tracking": "none"}
{"name": "Mango", "is_storable": True, "tracking": "none"}
)
self.quant_obj.create(
{
Expand Down Expand Up @@ -154,7 +152,7 @@ def test_planned_transfer(self):

def test_planned_transfer_strict(self):
product = self.env["product.product"].create(
{"name": "Test", "type": "product", "tracking": "lot"}
{"name": "Test", "is_storable": True, "tracking": "lot"}
)
lot = self.env["stock.lot"].create(
{
Expand Down Expand Up @@ -193,14 +191,14 @@ def test_planned_transfer_strict(self):
location_line.move_quantity,
]
line = picking.move_line_ids
picking_lines = [line.product_id.id, line.lot_id.id, line.reserved_uom_qty]
picking_lines = [line.product_id.id, line.lot_id.id, line.quantity]
self.assertEqual(
wizard_lines,
picking_lines,
"Mismatch between move location lines and move lines",
)
self.assertEqual(
picking.move_line_ids.reserved_uom_qty,
picking.move_line_ids.quantity,
10.0,
)

Expand All @@ -214,14 +212,10 @@ def test_planned_transfer_strict(self):
location_lines.unlink()
wizard.action_move_location()
picking = wizard.picking_id
self.assertEqual(picking.state, "assigned")
self.assertEqual(
len(wizard.stock_move_location_line_ids), len(picking.move_line_ids)
)
self.assertEqual(
picking.move_line_ids.mapped("reserved_uom_qty"),
[0.0],
)
# Planned transfer state is "confirmed"
# move lines (quantity is zero) are removed
self.assertEqual(picking.state, "confirmed")
self.assertFalse(picking.move_line_ids)

def test_quant_transfer(self):
"""Test quants transfer."""
Expand All @@ -241,10 +235,8 @@ def test_quant_transfer(self):
wizard.onchange_origin_location()
self.assertEqual(len(lines), 3)
wizard.destination_location_id = self.internal_loc_1
wizard._onchange_destination_location_id()
self.assertEqual(lines.mapped("destination_location_id"), self.internal_loc_1)
wizard.origin_location_id = self.internal_loc_2
wizard._onchange_destination_location_id()
self.assertEqual(len(lines), 3)

def test_readonly_location_computation(self):
Expand Down Expand Up @@ -276,7 +268,7 @@ def test_wizard_with_putaway_strategy(self):
lambda p: p.product_id == self.product_no_lots
)[0]
self.assertEqual(
putaway_line.destination_location_id, self.internal_loc_2_shelf
putaway_line.destination_location_id, wizard.destination_location_id
)
picking_action = wizard.action_move_location()
picking = self.env["stock.picking"].browse(picking_action["res_id"])
Expand Down
51 changes: 23 additions & 28 deletions stock_move_location/tests/test_stock_fillwithstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,58 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


import odoo.tests.common as common
from odoo.addons.base.tests.common import BaseCommon


class TestFillwithStock(common.TransactionCase):
def setUp(self):
super().setUp()
self.env = self.env(
context=dict(
self.env.context,
tracking_disable=True,
)
)
class TestFillwithStock(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()

self.stock_location = self.env.ref("stock.stock_location_stock")
self.pack_location = self.env.ref("stock.location_pack_zone")
cls.stock_location = cls.env.ref("stock.stock_location_stock")
cls.pack_location = cls.env.ref("stock.location_pack_zone")

self.shelf1_location = self.env["stock.location"].create(
cls.shelf1_location = cls.env["stock.location"].create(
{
"name": "Test location",
"usage": "internal",
"location_id": self.stock_location.id,
"location_id": cls.stock_location.id,
}
)

self.product1 = self.env["product.product"].create(
cls.product1 = cls.env["product.product"].create(
{
"name": "Product A",
"type": "product",
"is_storable": True,
}
)
self.product2 = self.env["product.product"].create(
cls.product2 = cls.env["product.product"].create(
{
"name": "Product B",
"type": "product",
"is_storable": True,
}
)

self.env["stock.quant"].create(
cls.env["stock.quant"].create(
{
"product_id": self.product1.id,
"location_id": self.shelf1_location.id,
"product_id": cls.product1.id,
"location_id": cls.shelf1_location.id,
"quantity": 5.0,
"reserved_quantity": 0.0,
}
)
self.env["stock.quant"].create(
cls.env["stock.quant"].create(
{
"product_id": self.product1.id,
"location_id": self.shelf1_location.id,
"product_id": cls.product1.id,
"location_id": cls.shelf1_location.id,
"quantity": 10.0,
"reserved_quantity": 5.0,
}
)
self.env["stock.quant"].create(
cls.env["stock.quant"].create(
{
"product_id": self.product2.id,
"location_id": self.shelf1_location.id,
"product_id": cls.product2.id,
"location_id": cls.shelf1_location.id,
"quantity": 5.0,
"reserved_quantity": 0.0,
}
Expand All @@ -80,7 +75,7 @@ def test_fillwithstock(self):
picking_stock_pack.move_ids.filtered(
lambda m: m.product_id == self.product1
).product_uom_qty,
10.0,
15.0,
)
self.assertEqual(
picking_stock_pack.move_ids.filtered(
Expand Down
4 changes: 2 additions & 2 deletions stock_move_location/views/stock_picking_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<field name="code" position="after">
<field name="show_move_onhand" />
</field>
<xpath expr="//div[hasclass('o_kanban_primary_left')]" position="inside">
<button name="get_action_picking_tree_ready" position="after">
<div t-if="record.show_move_onhand.raw_value">
<button
name="action_move_location"
Expand All @@ -28,7 +28,7 @@
Move On Hand
</button>
</div>
</xpath>
</button>
</field>
</record>
</odoo>
24 changes: 5 additions & 19 deletions stock_move_location/wizard/stock_move_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)


from odoo import api, fields, models
from odoo import Command, api, fields, models
from odoo.fields import first
from odoo.osv import expression

Expand Down Expand Up @@ -162,11 +162,6 @@ def _prepare_wizard_move_lines(self, quants):
)
return res

@api.onchange("destination_location_id")
def _onchange_destination_location_id(self):
for line in self.stock_move_location_line_ids:
line.destination_location_id = self.destination_location_id

def _clear_lines(self):
self.stock_move_location_line_ids = False

Expand Down Expand Up @@ -227,19 +222,9 @@ def _create_move(self, picking, lines):
lines.create_move_lines(picking, move)
if self.env.context.get("planned"):
for line in lines:
quants = self.env["stock.quant"]._gather(
line.product_id,
line.origin_location_id,
lot_id=line.lot_id,
package_id=line.package_id,
owner_id=line.owner_id,
strict=False,
qty=line.move_quantity,
)
move._update_reserved_quantity(
line.move_quantity,
line.origin_location_id,
quant_ids=quants,
lot_id=line.lot_id,
package_id=line.package_id,
owner_id=line.owner_id,
Expand All @@ -248,6 +233,7 @@ def _create_move(self, picking, lines):
# Force the state to be assigned, instead of _action_assign,
# to avoid discarding the selected move_location_line.
move.state = "assigned"
move.move_line_ids.filtered(lambda ml: not ml.quantity).unlink()
move.move_line_ids.write({"state": "assigned"})
return move

Expand Down Expand Up @@ -320,7 +306,7 @@ def _get_group_quants(self):
"quantity:sum",
"reserved_quantity:sum",
],
groupby=["product_id", "lot_id", "package_id", "owner_id"],
groupby=["id", "product_id", "lot_id", "package_id", "owner_id"],
orderby="id",
lazy=False,
)
Expand Down Expand Up @@ -374,8 +360,8 @@ def onchange_origin_location(self):
not self.env.context.get("origin_location_disable")
and self.origin_location_id
):
lines = [[5, 0, 0]] + [
[0, 0, line_vals]
lines = [Command.clear()] + [
Command.create(line_vals)
for line_vals in self._get_stock_move_location_lines_values()
if line_vals.get("max_quantity", 0.0) > 0.0
]
Expand Down
Loading

0 comments on commit 6287135

Please sign in to comment.