1
1
# Copyright 2022 Camptocamp SA
2
+ # Copyright 2023 Michael Tietz (MT Software) <[email protected] >
2
3
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3
4
4
5
import logging
@@ -578,7 +579,9 @@ def _valid_dest_location_for_menu(self):
578
579
domain = self ._valid_dest_location_for_menu_domain ()
579
580
return self .env ["stock.location" ].search (domain )
580
581
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
+ ):
582
585
valid_locations_for_move_line = (
583
586
self ._set_quantity__valid_dest_location_for_move_line (move_line )
584
587
)
@@ -693,14 +696,26 @@ def _set_quantity__by_location_handlers(self):
693
696
self ._set_quantity__check_location ,
694
697
]
695
698
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
+ ):
697
702
# We're about to leave the `set_quantity` screen.
698
703
# First ensure that quantity is valid.
699
704
invalid_qty_response = self ._set_quantity__check_quantity_done (move_line )
700
705
if invalid_qty_response :
701
706
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
703
713
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
704
719
response = self ._use_handlers (
705
720
handlers , move_line , location , confirmation = confirmation
706
721
)
@@ -721,7 +736,11 @@ def _set_quantity__by_package(self, move_line, package, confirmation=False):
721
736
location = package .location_id
722
737
handlers = self ._set_quantity__by_location_handlers ()
723
738
response = self ._use_handlers (
724
- handlers , move_line , location , confirmation = confirmation
739
+ handlers ,
740
+ move_line ,
741
+ location ,
742
+ package = package ,
743
+ confirmation = confirmation ,
725
744
)
726
745
if response :
727
746
return response
@@ -889,10 +908,10 @@ def set_location(self, selected_line_id, package_id, barcode):
889
908
}
890
909
search = self ._actions_for ("search" )
891
910
search_result = search .find (barcode , types = handlers_by_type .keys ())
911
+ package = self .env ["stock.quant.package" ].browse (package_id )
892
912
handler = handlers_by_type .get (search_result .type )
893
913
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 )
896
915
message = self .msg_store .barcode_not_found ()
897
916
return self ._response_for_set_location (move_line , package , message = message )
898
917
0 commit comments