Skip to content

Commit

Permalink
[IMP] shopfloor: Sync src location on single_pack_transer and single_…
Browse files Browse the repository at this point in the history
…product_transfer
  • Loading branch information
mt-software-de committed Jan 15, 2025
1 parent f9be0e8 commit 9dc0af0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
9 changes: 8 additions & 1 deletion shopfloor/actions/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,15 @@ def _set_destination_on_lines(
def _unload_package(self, lines):
lines.result_package_id = False

def set_locations_and_unload_lines(self, lines, location_dest, unload=False):
def _sync_src_location(self, lines):
lines.move_id.location_id = lines.location_id

def set_locations_and_unload_lines(
self, lines, location_dest, unload=False, sync_src_location=False
):
self._lock_lines(lines)
self._set_destination_on_lines(lines, location_dest)
if unload:
self._unload_package(lines)
if sync_src_location:
self._sync_src_location(lines)
2 changes: 1 addition & 1 deletion shopfloor/services/single_pack_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def _set_destination_and_done(self, package_level, scanned_location):
# on the move lines
stock = self._actions_for("stock")
stock.set_locations_and_unload_lines(
package_level.move_line_ids, scanned_location
package_level.move_line_ids, scanned_location, sync_src_location=True
)
stock.put_package_level_in_move(package_level)
stock.validate_moves(package_level.move_line_ids.move_id)
Expand Down
18 changes: 16 additions & 2 deletions shopfloor/tests/test_single_pack_transfer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2020 Akretion (http://www.akretion.com)
# Copyright 2025 Michael Tietz (MT Software) <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import Form
Expand Down Expand Up @@ -449,11 +450,24 @@ def test_validate(self):

self.assertRecordValues(
package_level.move_line_ids,
[{"qty_done": 1.0, "location_dest_id": self.shelf2.id, "state": "done"}],
[
{
"qty_done": 1.0,
"location_dest_id": self.shelf2.id,
"location_id": self.shelf1.id,
"state": "done",
}
],
)
self.assertRecordValues(
package_level.move_line_ids.move_id,
[{"location_dest_id": self.shelf2.id, "state": "done"}],
[
{
"location_dest_id": self.shelf2.id,
"location_id": self.shelf1.id,
"state": "done",
}
],
)

def test_validate_completion_info(self):
Expand Down
8 changes: 6 additions & 2 deletions shopfloor_checkout_sync/actions/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def _set_destination_on_lines(self, lines, location_dest):
checkout_sync._sync_checkout(lines, location_dest)
super()._set_destination_on_lines(lines, location_dest)

def set_locations_and_unload_lines(self, lines, location_dest, unload=False):
def set_locations_and_unload_lines(
self, lines, location_dest, unload=False, sync_src_location=False
):
checkout_sync = self._actions_for("checkout.sync")
checkout_sync._all_lines_to_lock(lines)
super().set_locations_and_unload_lines(lines, location_dest, unload)
super().set_locations_and_unload_lines(
lines, location_dest, unload, sync_src_location
)
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ def _set_quantity__check_location(

def _write_destination_on_lines(self, lines, location):
stock = self._actions_for("stock")
stock.set_locations_and_unload_lines(lines, location)
stock.set_locations_and_unload_lines(lines, location, sync_src_location=True)
# lines.move_id.location_dest_id = location
# lines.move_id.location_id = lines.location_id

def _set_quantity__post_move(self, move_line, location, confirmation=None):
# TODO qty_done = 0: transfer_no_qty_done
Expand Down
15 changes: 14 additions & 1 deletion shopfloor_single_product_transfer/tests/test_set_quantity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 Camptocamp SA
# Copyright 2025 Michael Tietz (MT Software) <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from .common import CommonCase
Expand All @@ -8,7 +9,7 @@ class TestSetQuantity(CommonCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.location = cls.location_src
cls.location = cls.env.ref("stock.stock_location_components")
cls.product = cls.product_a
cls.packaging = cls.product_a_packaging
cls.packaging.qty = 5
Expand Down Expand Up @@ -725,6 +726,12 @@ def test_set_quantity_scan_location(self):
self.assertFalse(picking.move_line_ids.result_package_id)
self.assertEqual(picking.user_id.id, False)
self.assertEqual(picking.move_line_ids.shopfloor_user_id.id, False)
self.assertEqual(picking.move_line_ids.location_dest_id, self.dispatch_location)
self.assertEqual(picking.move_line_ids.location_id, self.location)
self.assertEqual(
picking.move_line_ids.move_id.location_dest_id, self.dispatch_location
)
self.assertEqual(picking.move_line_ids.move_id.location_id, self.location)

def test_set_quantity_scan_location_allow_move_create(self):
self.menu.sudo().allow_move_create = True
Expand Down Expand Up @@ -754,6 +761,12 @@ def test_set_quantity_scan_location_allow_move_create(self):
self.assertFalse(backorder)
self.assertEqual(picking.move_line_ids.qty_done, 6.0)
self.assertEqual(picking.move_line_ids.state, "done")
self.assertEqual(picking.move_line_ids.location_dest_id, self.dispatch_location)
self.assertEqual(picking.move_line_ids.location_id, self.location)
self.assertEqual(
picking.move_line_ids.move_id.location_dest_id, self.dispatch_location
)
self.assertEqual(picking.move_line_ids.move_id.location_id, self.location)

def test_set_quantity_scan_package_not_empty(self):
# We scan a package that's not empty
Expand Down

0 comments on commit 9dc0af0

Please sign in to comment.