Skip to content

Commit a6e8dfe

Browse files
[FIX] shopfloor_single_product_transfer: Package scan
Do not remove result_package_id in call of _set_quantity__by_location when it was previously set by scanning a package
1 parent d775ba2 commit a6e8dfe

File tree

17 files changed

+75
-33
lines changed

17 files changed

+75
-33
lines changed

Diff for: shopfloor_single_product_transfer/README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Shopfloor Single Product Transfer
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:0c02f49273316c190e1d17d298f97dbb41f4bf80e1c5341091bb90fff4c0404f
10+
!! source digest: sha256:6c68d48d21b7dec7174f3018b1d89dac0781c150792d1c3f70adfc7d39052b3a
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -86,6 +86,7 @@ Contributors
8686
~~~~~~~~~~~~
8787

8888
* Matthieu Méquignon <[email protected]>
89+
* Michael Tietz (MT Software) <[email protected]>
8990

9091
Maintainers
9192
~~~~~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* Matthieu Méquignon <[email protected]>
2+
* Michael Tietz (MT Software) <[email protected]>

Diff for: shopfloor_single_product_transfer/services/single_product_transfer.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2022 Camptocamp SA
2+
# Copyright 2023 Michael Tietz (MT Software) <[email protected]>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
34

45
import logging
@@ -578,7 +579,9 @@ def _valid_dest_location_for_menu(self):
578579
domain = self._valid_dest_location_for_menu_domain()
579580
return self.env["stock.location"].search(domain)
580581

581-
def _set_quantity__check_location(self, move_line, location, confirmation=False):
582+
def _set_quantity__check_location(
583+
self, move_line, location, package=None, confirmation=False
584+
):
582585
valid_locations_for_move_line = (
583586
self._set_quantity__valid_dest_location_for_move_line(move_line)
584587
)
@@ -693,14 +696,26 @@ def _set_quantity__by_location_handlers(self):
693696
self._set_quantity__check_location,
694697
]
695698

696-
def _set_quantity__by_location(self, move_line, location, confirmation=False):
699+
def _set_quantity__by_location(
700+
self, move_line, location, package=None, confirmation=False
701+
):
697702
# We're about to leave the `set_quantity` screen.
698703
# First ensure that quantity is valid.
699704
invalid_qty_response = self._set_quantity__check_quantity_done(move_line)
700705
if invalid_qty_response:
701706
return invalid_qty_response
702-
move_line.result_package_id = False
707+
# Do not remove the result_package_id
708+
# when it was previously set by _set_quantity__by_package
709+
# because _set_quantity__by_location will be then called
710+
# with the scanned empty package
711+
if not package:
712+
move_line.result_package_id = False
703713
handlers = self._set_quantity__by_location_handlers()
714+
# At this point the result_package_id is already
715+
# set by _set_quantity__by_package to scanned package
716+
# or set to False by this method
717+
# Because of this call the handlers without the package
718+
# to ensure the move_line's result_package_id gets checked
704719
response = self._use_handlers(
705720
handlers, move_line, location, confirmation=confirmation
706721
)
@@ -721,7 +736,11 @@ def _set_quantity__by_package(self, move_line, package, confirmation=False):
721736
location = package.location_id
722737
handlers = self._set_quantity__by_location_handlers()
723738
response = self._use_handlers(
724-
handlers, move_line, location, confirmation=confirmation
739+
handlers,
740+
move_line,
741+
location,
742+
package=package,
743+
confirmation=confirmation,
725744
)
726745
if response:
727746
return response
@@ -889,10 +908,10 @@ def set_location(self, selected_line_id, package_id, barcode):
889908
}
890909
search = self._actions_for("search")
891910
search_result = search.find(barcode, types=handlers_by_type.keys())
911+
package = self.env["stock.quant.package"].browse(package_id)
892912
handler = handlers_by_type.get(search_result.type)
893913
if handler:
894-
return handler(move_line, search_result.record)
895-
package = self.env["stock.quant.package"].browse(package_id)
914+
return handler(move_line, search_result.record, package=package)
896915
message = self.msg_store.barcode_not_found()
897916
return self._response_for_set_location(move_line, package, message=message)
898917

Diff for: shopfloor_single_product_transfer/static/description/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ <h1 class="title">Shopfloor Single Product Transfer</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:0c02f49273316c190e1d17d298f97dbb41f4bf80e1c5341091bb90fff4c0404f
370+
!! source digest: sha256:6c68d48d21b7dec7174f3018b1d89dac0781c150792d1c3f70adfc7d39052b3a
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/wms/tree/14.0/shopfloor_single_product_transfer"><img alt="OCA/wms" src="https://img.shields.io/badge/github-OCA%2Fwms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/wms-14-0/wms-14-0-shopfloor_single_product_transfer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/wms&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>Allow to move a single product from a location to another one.</p>
@@ -435,6 +435,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
435435
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
436436
<ul class="simple">
437437
<li>Matthieu Méquignon &lt;<a class="reference external" href="mailto:matthieu.mequignon&#64;camptocamp.com">matthieu.mequignon&#64;camptocamp.com</a>&gt;</li>
438+
<li>Michael Tietz (MT Software) &lt;<a class="reference external" href="mailto:mtietz&#64;mt-software.de">mtietz&#64;mt-software.de</a>&gt;</li>
438439
</ul>
439440
</div>
440441
<div class="section" id="maintainers">

Diff for: shopfloor_single_product_transfer/tests/common.py

+5
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,8 @@ def get_new_picking(cls):
140140
@classmethod
141141
def get_new_move(cls):
142142
return cls.env["stock.move"].search([("id", "not in", cls.existing_move_ids)])
143+
144+
@classmethod
145+
def _create_empty_package(cls, name=None):
146+
name = name or "test-package"
147+
return cls.env["stock.quant.package"].sudo().create({"name": name})

Diff for: shopfloor_single_product_transfer/tests/test_scan_location_or_package.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_scan_location_ok(self):
6767

6868
def test_scan_location_stock_packages(self):
6969
location = self.location_src
70-
package = self.env["stock.quant.package"].sudo().create({})
70+
package = self._create_empty_package()
7171
for quant in location.quant_ids:
7272
quant.sudo().package_id = package
7373

@@ -87,7 +87,7 @@ def test_scan_location_stock_packages(self):
8787

8888
def test_scan_location_only_lines_with_package(self):
8989
location = self.location_src
90-
package = self.env["stock.quant.package"].sudo().create({})
90+
package = self._create_empty_package()
9191
for line in location.source_move_line_ids:
9292
# There are no lines without a package in this location.
9393
line.package_id = package

Diff for: shopfloor_single_product_transfer/tests/test_set_location.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ def _setup_picking(cls):
2121
return cls._create_picking(lines=[(cls.product, 10)])
2222

2323
def test_set_location_ok(self):
24-
package = (
25-
self.env["stock.quant.package"].sudo().create({"name": "test-package"})
26-
)
24+
package = self._create_empty_package()
2725
picking = self._setup_picking()
2826
move_line = picking.move_line_ids
27+
# _set_quantity__by_package sets the result_package_id
28+
# ensure that the package is still set after set_location
29+
move_line.result_package_id = package
2930
location = self.dispatch_location
3031
response = self.service.dispatch(
3132
"set_location",
@@ -35,6 +36,7 @@ def test_set_location_ok(self):
3536
"barcode": location.name,
3637
},
3738
)
39+
self.assertEqual(move_line.result_package_id, package)
3840
expected_message = self.msg_store.transfer_done_success(move_line.picking_id)
3941
completion_info = self.service._actions_for("completion.info")
4042
expected_popup = completion_info.popup(move_line)
@@ -48,9 +50,7 @@ def test_set_location_ok(self):
4850
)
4951

5052
def test_set_location_barcode_not_found(self):
51-
package = (
52-
self.env["stock.quant.package"].sudo().create({"name": "test-package"})
53-
)
53+
package = self._create_empty_package()
5454
picking = self._setup_picking()
5555
move_line = picking.move_line_ids
5656
response = self.service.dispatch(

Diff for: shopfloor_single_product_transfer/tests/test_set_quantity.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ def test_set_quantity_scan_location(self):
720720
self.assertEqual(picking.move_line_ids.product_uom_qty, 4.0)
721721
self.assertEqual(picking.move_line_ids.qty_done, 0.0)
722722
self.assertEqual(picking.move_line_ids.state, "assigned")
723+
self.assertFalse(picking.move_line_ids.result_package_id)
723724

724725
def test_set_quantity_scan_location_allow_move_create(self):
725726
self.menu.sudo().allow_move_create = True
@@ -732,6 +733,7 @@ def test_set_quantity_scan_location_allow_move_create(self):
732733
)
733734
# Change the destination on the move_line and take less than the total amount required.
734735
move_line = picking.move_line_ids
736+
735737
self.service.dispatch(
736738
"set_quantity",
737739
params={
@@ -752,9 +754,7 @@ def test_set_quantity_scan_location_allow_move_create(self):
752754
def test_set_quantity_scan_package_not_empty(self):
753755
# We scan a package that's not empty
754756
# and its location is selected.
755-
package = (
756-
self.env["stock.quant.package"].sudo().create({"name": "test-package"})
757-
)
757+
package = self._create_empty_package()
758758
self.env["stock.quant"].sudo().create(
759759
{
760760
"package_id": package.id,
@@ -793,9 +793,7 @@ def test_set_quantity_scan_package_not_empty(self):
793793
def test_set_quantity_scan_package_empty(self):
794794
# We scan an empty package
795795
# and are redirected to set_location.
796-
package = (
797-
self.env["stock.quant.package"].sudo().create({"name": "test-package"})
798-
)
796+
package = self._create_empty_package()
799797
picking = self._setup_picking()
800798
move_line = picking.move_line_ids
801799
response = self.service.dispatch(

Diff for: shopfloor_single_product_transfer_force_package/README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Shopfloor Single Product Transfer Force Select Package
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:5c5fcdf15f9d541770a2f5b6662b44e8d9b213a07ddf924f8030465ffb46aa8f
10+
!! source digest: sha256:e82edcbccff746daa3c4eb6aa9014931e7b70cc699598b4ab2752ee137708ec8
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -57,6 +57,7 @@ Contributors
5757
~~~~~~~~~~~~
5858

5959
* Juan Miguel Sánchez Arce <[email protected]>
60+
* Michael Tietz (MT Software) <[email protected]>
6061

6162
Maintainers
6263
~~~~~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* Juan Miguel Sánchez Arce <[email protected]>
2+
* Michael Tietz (MT Software) <[email protected]>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2023 Camptocamp SA
2+
# Copyright 2023 Michael Tietz (MT Software) <[email protected]>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
34

45

@@ -8,12 +9,20 @@
89
class ShopfloorSingleProductTransfer(Component):
910
_inherit = "shopfloor.single.product.transfer"
1011

11-
def _set_quantity__check_location(self, move_line, location, confirmation=False):
12+
def _set_quantity__check_location(
13+
self, move_line, location, package=None, confirmation=False
14+
):
1215
# We add an additional check to verify if the location requires packages
1316
# and return a message to the user accordingly.
14-
if location.package_restriction and not move_line.result_package_id:
17+
if (
18+
location.package_restriction
19+
and not package
20+
and not move_line.result_package_id
21+
):
1522
message = self.msg_store.location_requires_package()
1623
return self._response_for_set_quantity(
1724
move_line, message=message, asking_confirmation=None
1825
)
19-
return super()._set_quantity__check_location(move_line, location, confirmation)
26+
return super()._set_quantity__check_location(
27+
move_line, location, package=package, confirmation=confirmation
28+
)

Diff for: shopfloor_single_product_transfer_force_package/static/description/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ <h1 class="title">Shopfloor Single Product Transfer Force Select Package</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:5c5fcdf15f9d541770a2f5b6662b44e8d9b213a07ddf924f8030465ffb46aa8f
370+
!! source digest: sha256:e82edcbccff746daa3c4eb6aa9014931e7b70cc699598b4ab2752ee137708ec8
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/wms/tree/14.0/shopfloor_single_product_transfer_force_package"><img alt="OCA/wms" src="https://img.shields.io/badge/github-OCA%2Fwms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/wms-14-0/wms-14-0-shopfloor_single_product_transfer_force_package"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/wms&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>Force the user to select a package if they scan a location which already contains packages.</p>
@@ -403,6 +403,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
403403
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
404404
<ul class="simple">
405405
<li>Juan Miguel Sánchez Arce &lt;<a class="reference external" href="mailto:juan.sanchez&#64;camptocamp.com">juan.sanchez&#64;camptocamp.com</a>&gt;</li>
406+
<li>Michael Tietz (MT Software) &lt;<a class="reference external" href="mailto:mtietz&#64;mt-software.de">mtietz&#64;mt-software.de</a>&gt;</li>
406407
</ul>
407408
</div>
408409
<div class="section" id="maintainers">

Diff for: shopfloor_single_product_transfer_force_package/tests/test_force_package.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def test_force_package_mandatory_no_package(self):
4040
def test_force_package_mandatory_with_package(self):
4141
picking = self._setup_picking()
4242
move_line = picking.move_line_ids
43-
package = self.env["stock.quant.package"].sudo().create({})
44-
move_line.result_package_id = package
43+
package = self._create_empty_package()
4544
self.dispatch_location.sudo().package_restriction = "singlepackage"
4645
response = self.service.dispatch(
4746
"set_quantity",

Diff for: shopfloor_single_product_transfer_unique_order_at_location/README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Shopfloor Single Product Transfer Unique Order Per Location
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:293d3465d5bee7cc00f12378573974df153d01784247d13d8f80373cdcb7121d
10+
!! source digest: sha256:6009aa6960e9ba8bda6b2942b50f38fb7dd25cf7c0e1c9820f643c838e0ec0e9
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -60,6 +60,7 @@ Contributors
6060
~~~~~~~~~~~~
6161

6262
* Thierry Ducrest <[email protected]>
63+
* Michael Tietz (MT Software) <[email protected]>
6364

6465
Maintainers
6566
~~~~~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* Thierry Ducrest <[email protected]>
2+
* Michael Tietz (MT Software) <[email protected]>

Diff for: shopfloor_single_product_transfer_unique_order_at_location/services/single_product_transfer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2023 Camptocamp SA
2+
# Copyright 2023 Michael Tietz (MT Software) <[email protected]>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
34

45
from odoo.exceptions import UserError
@@ -10,9 +11,11 @@ class ShopfloorSingleProductTransfer(Component):
1011
_inherit = "shopfloor.single.product.transfer"
1112

1213
def _set_quantity__check_location(
13-
self, move_line, location=False, confirmation=False
14+
self, move_line, location=False, package=False, confirmation=False
1415
):
15-
res = super()._set_quantity__check_location(move_line, location, confirmation)
16+
res = super()._set_quantity__check_location(
17+
move_line, location, package=package, confirmation=confirmation
18+
)
1619
# Could also be asking for confirmation with a warning
1720
if res and res.get("message", {}).get("message_type", "") == "error":
1821
return res

Diff for: shopfloor_single_product_transfer_unique_order_at_location/static/description/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ <h1 class="title">Shopfloor Single Product Transfer Unique Order Per Location</h
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:293d3465d5bee7cc00f12378573974df153d01784247d13d8f80373cdcb7121d
370+
!! source digest: sha256:6009aa6960e9ba8bda6b2942b50f38fb7dd25cf7c0e1c9820f643c838e0ec0e9
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/wms/tree/14.0/shopfloor_single_product_transfer_unique_order_at_location"><img alt="OCA/wms" src="https://img.shields.io/badge/github-OCA%2Fwms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/wms-14-0/wms-14-0-shopfloor_single_product_transfer_unique_order_at_location"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/wms&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>When installed, this module restricts transfer to some non empty location
@@ -406,6 +406,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
406406
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
407407
<ul class="simple">
408408
<li>Thierry Ducrest &lt;<a class="reference external" href="mailto:thierry.ducrest&#64;camptocamp.com">thierry.ducrest&#64;camptocamp.com</a>&gt;</li>
409+
<li>Michael Tietz (MT Software) &lt;<a class="reference external" href="mailto:mtietz&#64;mt-software.de">mtietz&#64;mt-software.de</a>&gt;</li>
409410
</ul>
410411
</div>
411412
<div class="section" id="maintainers">

0 commit comments

Comments
 (0)