Skip to content

Commit

Permalink
shopfloor: add checkout option ask leaf location dest
Browse files Browse the repository at this point in the history
Following this change on the checkout scenario

    #618

A check has been added to force the user to scan a child location
if the destination location is not a leaf in the locations tree.

To allow for flexibility this change adds the options to disable this
feature.
  • Loading branch information
TDu committed Nov 3, 2023
1 parent d775ba2 commit f254bc4
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 10 deletions.
2 changes: 1 addition & 1 deletion shopfloor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Shopfloor
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:afec8a80541366c8c8fe95511b5cc7b80edd184ffc7de6157bbb44163291ddda
!! source digest: sha256:2684ae035ed194d86f9939006ad2ea2fa26c91d5b6034bd4d0db9ad72c28e258
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion shopfloor/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"name": "Shopfloor",
"summary": "manage warehouse operations with barcode scanners",
"version": "14.0.4.2.4",
"version": "14.0.5.0.0",
"development_status": "Beta",
"category": "Inventory",
"website": "https://github.com/OCA/wms",
Expand Down
3 changes: 2 additions & 1 deletion shopfloor/data/shopfloor_scenario_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"no_prefill_qty": true,
"show_oneline_package_content": true,
"auto_post_line": true,
"scan_location_or_pack_first": true
"scan_location_or_pack_first": true,
"ask_for_leaf_destination_location" : true
}
</field>
</record>
Expand Down
41 changes: 41 additions & 0 deletions shopfloor/migrations/14.0.5.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 Camptocamp SA (http://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import json
import logging

from odoo import SUPERUSER_ID, api

_logger = logging.getLogger(__name__)


def migrate(cr, version):
if not version:
return
env = api.Environment(cr, SUPERUSER_ID, {})
checkout_scenario = env["shopfloor.scenario"].search([("key", "=", "checkout")])
_update_scenario_options(checkout_scenario)
checkout_menus = env["shopfloor.menu"].search(
[("scenario_id", "=", checkout_scenario.id)]
)
_enable_option_in_menus(checkout_menus)


def _update_scenario_options(scenario):
options = scenario.options
options["ask_for_leaf_destination_location"] = True
options_edit = json.dumps(options or {}, indent=4, sort_keys=True)
scenario.write({"options_edit": options_edit})
_logger.info(
"Option ask_for_leaf_destination_location added to the Checkout scenario"
)


def _enable_option_in_menus(menus):
for menu in menus:
menu.ask_for_leaf_destination_location = True
_logger.info(
"Option ask_for_leaf_destination_location enabled for menu {}".format(
menu.name
)
)
20 changes: 20 additions & 0 deletions shopfloor/models/shopfloor_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
to scan a destination package.
"""

ASK_FOR_LEAF_DESTINATION_LOCATION_HELP = """
When enabled, the destination location must be a leaf (location with no children)
location, if it is not, ask for scanning a child location of the destination.
"""


class ShopfloorMenu(models.Model):
_inherit = "shopfloor.menu"
Expand Down Expand Up @@ -226,6 +231,14 @@ class ShopfloorMenu(models.Model):
allow_alternative_destination_package_is_possible = fields.Boolean(
compute="_compute_allow_alternative_destination_package_is_possible"
)
ask_for_leaf_destination_location = fields.Boolean(
string="Ask for leaf destination location",
default=False,
help=ASK_FOR_LEAF_DESTINATION_LOCATION_HELP,
)
ask_for_leaf_destination_location_is_possible = fields.Boolean(
compute="_compute_ask_for_leaf_destination_location_is_possible"
)

@api.onchange("unload_package_at_destination")
def _onchange_unload_package_at_destination(self):
Expand Down Expand Up @@ -455,3 +468,10 @@ def _compute_allow_alternative_destination_package_is_possible(self):
menu.allow_alternative_destination_package_is_possible = (
menu.scenario_id.has_option("allow_alternative_destination_package")
)

@api.depends("scenario_id")
def _compute_ask_for_leaf_destination_location_is_possible(self):
for menu in self:
menu.ask_for_leaf_destination_location_is_possible = (

Check warning on line 475 in shopfloor/models/shopfloor_menu.py

View check run for this annotation

Codecov / codecov/patch

shopfloor/models/shopfloor_menu.py#L475

Added line #L475 was not covered by tests
menu.scenario_id.has_option("ask_for_leaf_destination_location")
)
13 changes: 7 additions & 6 deletions shopfloor/services/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,13 +1402,14 @@ def done(self, picking_id, confirmation=False):
)
lines_done = self._lines_checkout_done(picking)
dest_location = picking.location_dest_id
child_locations = self.env["stock.location"].search(
[("id", "child_of", dest_location.id), ("usage", "!=", "view")]
)
if len(child_locations) > 0 and child_locations != dest_location:
return self._response_for_select_child_location(
picking,
if self.work.menu.ask_for_leaf_destination_location:
child_locations = self.env["stock.location"].search(
[("id", "child_of", dest_location.id), ("usage", "!=", "view")]
)
if len(child_locations) > 0 and child_locations != dest_location:
return self._response_for_select_child_location(
picking,
)
stock = self._actions_for("stock")
stock.validate_moves(lines_done.move_id)
return self._response_for_select_document(
Expand Down
2 changes: 1 addition & 1 deletion shopfloor/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Shopfloor</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:afec8a80541366c8c8fe95511b5cc7b80edd184ffc7de6157bbb44163291ddda
!! source digest: sha256:2684ae035ed194d86f9939006ad2ea2fa26c91d5b6034bd4d0db9ad72c28e258
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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"><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"><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>
<p>Shopfloor is a barcode scanner application for internal warehouse operations.</p>
Expand Down
17 changes: 17 additions & 0 deletions shopfloor/tests/test_checkout_done.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,28 @@ def test_done_partial(self):
)

def test_done_partial_confirm(self):
"""Check confirm partially done no check for leaf location."""
# lines are done
response = self.service.dispatch(
"done", params={"picking_id": self.picking.id, "confirmation": True}
)

self.assertRecordValues(self.picking, [{"state": "done"}])

self.assert_response(
response,
next_state="select_document",
message=self.service.msg_store.transfer_done_success(self.picking),
data={"restrict_scan_first": False},
)

def test_done_partial_confirm_ask_leaf_location(self):
"""Check confirm partially done with force leaf location option on."""
self.menu.sudo().ask_for_leaf_destination_location = True
response = self.service.dispatch(
"done", params={"picking_id": self.picking.id, "confirmation": True}
)

self.assertRecordValues(self.picking, [{"state": "assigned"}])

self.assert_response(
Expand Down
10 changes: 10 additions & 0 deletions shopfloor/views/shopfloor_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@
/>
<field name="allow_alternative_destination_package" />
</group>
<group
name="ask_for_leaf_destination_location"
attrs="{'invisible': [('ask_for_leaf_destination_location_is_possible', '=', False)]}"
>
<field
name="ask_for_leaf_destination_location_is_possible"
invisible="1"
/>
<field name="ask_for_leaf_destination_location" />
</group>
</group>
</field>
</record>
Expand Down

0 comments on commit f254bc4

Please sign in to comment.