Repository navigation
[18.0][ADD] barcode_stock_unexpected_product - #23
antoniodavid wants to merge 1 commit into
Conversation
| move.unlink() | ||
| return {"deleted": True, "move_id": move_id} | ||
|
|
||
| @api.model |
There was a problem hiding this comment.
With this module installed, action_barcode_scanner_internal_transfer raises unless the warehouse internal type has allow_insert_new_line ticked, and the field defaults to False. So the internal transfer screen of barcode_stock stops working right after install (the client refuses the first addLine too), and test_storage_default_false_blocks asserts exactly that. In that screen every line is new by definition: there are no planned moves for a product to be unexpected against. Is this intended? If not, I'd drop this override and the InternalTransferScreen patch and keep the gate on PickingScreen. If it is, the readme needs to say so, because USAGE says the scanner works "exactly as before" when the setting is off.
| move.product_uom_qty = total | ||
| return res | ||
|
|
||
| @api.constrains("quantity", "product_id", "lot_id") |
There was a problem hiding this comment.
barcode_stock already defines _check_serial_quantity on stock.move.line with the same body (barcode_stock/models/stock_move_line.py), so this only replaces the parent method with a copy of itself. Can you drop it, together with the ValidationError import that becomes unused?
| } | ||
| }, | ||
|
|
||
| async loadProducts() { |
There was a problem hiding this comment.
In manual_line mode this replaces loadProducts with a copy that reads image_128 without bin_size and never sets image_url. The base template only renders product.image_url (barcode_stock_templates.xml), so the selector downloads the full base64 image of every storable product and shows none of them. On a catalogue with a few thousand products that is a heavy first load. Could you keep the base loading (bin_size: true plus recordImageUrl, as in product_selector_screen.esm.js:70-96) and only change what differs here, the domain and the barcode field?
| const source = payload?.source || "hardware"; | ||
| if (!normalized.candidates.length) { | ||
| // Ponytail: also match default_code (user scans internal reference) | ||
| const productDomain = barcodeMatchDomain(barcode); |
There was a problem hiding this comment.
The search uses the raw barcode, while the parsed code is found in normalized.product. In the case of barcode_gs1, if a GS1 tag for a product not included in the picking list is scanned, the entire string is passed here; since no match is found, the operator sees the message "not part of the current picking." The JS test does not detect this because searchRead is mocked.
| const productDomain = barcodeMatchDomain(barcode); | |
| const productDomain = barcodeMatchDomain(normalized.product); |
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| lines = super().create(vals_list) | ||
| for line in lines: |
There was a problem hiding this comment.
The loop in create and the one in write are the same code. Could you move it into a helper and call it from both?
| def write(self, vals): | ||
| res = super().write(vals) | ||
| if "quantity" in vals or "qty_picked" in vals: | ||
| for line in self: |
There was a problem hiding this comment.
The loop in create and the one in write are the same code. Could you move it into a helper and call it from both?
63db0e5 to
09b5bd1
Compare
|
Thanks for the PR! Before reviewing it, could you add a description? A short summary of what the addon does and why it's needed, plus how to use or test it |
|
Thanks @szalatyzuzanna, I added a full description covering what the addon does. |
rrebollo
left a comment
There was a problem hiding this comment.
Installed on 18.0 and ran add/delete as a stock user: the add works and the delete raises AccessError. The rest is read from the code, not run. Please consider my concers.
| try: | ||
| lot_id = int(lot_id) | ||
| except (TypeError, ValueError): | ||
| raise UserError(_("The selected lot is not valid.")) from None |
There was a problem hiding this comment.
Since 18.0, model code translates through self.env._ (migration guide, line 50), and the module-level _ import is the shape that goes away. Apply it to every _() in this file; the from odoo import _ then disappears. One suggestion as the pattern:
| raise UserError(_("The selected lot is not valid.")) from None | |
| raise UserError(self.env._("The selected lot is not valid.")) from None |
There was a problem hiding this comment.
Done: replaced every _() in models/stock_picking.py with self.env._() and dropped the module-level _ import. Thanks for the pointer.
| raise UserError(_("A completed move cannot be deleted.")) | ||
| if move.quantity: | ||
| move._do_unreserve() | ||
| move.unlink() |
There was a problem hiding this comment.
stock.move unlink is granted to stock.group_stock_manager, not stock.group_stock_user, so a barcode operator sees the trash icon but cannot complete the delete. Reproduced on 18.0 as a stock user: barcode_scanner_add_manual_line_to_picking succeeds, barcode_scanner_delete_manual_line raises AccessError: You are not allowed to delete 'Stock Move' (stock.move) records; as admin it deletes. Either sudo() after the existing checks, or gate the button.
There was a problem hiding this comment.
Fixed: the deletion now runs as move.sudo().unlink() after the existing existence/manual/picking-state/move-state checks. Added a regression test that deletes a manual line as a stock.group_stock_user; without the sudo() it reproduces exactly the AccessError you saw.
| return; | ||
| } | ||
| const message = _t( | ||
| "Adding a new product line from the scanner is not allowed for this operation type." |
There was a problem hiding this comment.
On an operation type with the flag off, a scan of a product that is not in the transfer reaches this branch, so it answers Adding a new product line from the scanner is not allowed for this operation type instead of not part of the current picking. The operator never asked to add anything, and the body says flag-off behaviour is unchanged. Guard the fallback with canAddManualLine and keep the original message otherwise.
There was a problem hiding this comment.
Fixed: the early guard now also checks canAddManualLine, so with the flag off the operator keeps the original Scanned barcode is not part of the current picking. message. Added a HOOT test for that flag-off path.
09b5bd1 to
06792a4
Compare
rrebollo
left a comment
There was a problem hiding this comment.
At 06792a4, on a throwaway 18.0 database: the module's suite is green, and the delete RPC was exercised in a shell as a stock.group_stock_user. The premise the module rests on is that is_manually is provenance such an operator cannot set.
| # write moves but cannot unlink them. The checks above already ensured | ||
| # this is a manual line on a changeable picking, so elevate only the | ||
| # deletion itself. | ||
| move.sudo().unlink() |
There was a problem hiding this comment.
Reproduced on 18.0 as a stock.group_stock_user: writing the flag succeeds (is_manually has no groups; stock.move is write-granted to that group), planned.with_user(user).unlink() raises AccessError, and this call then deletes the same planned move ({'deleted': True, 'move_id': 18}), flag on or off. So the unlink ACL is reachable through the flag. Is provenance meant to be something the caller can set?
| const source = payload?.source || "hardware"; | ||
| if (!normalized.candidates.length) { | ||
| // Ponytail: also match default_code (user scans internal reference) | ||
| const productDomain = barcodeMatchDomain(normalized.product); |
There was a problem hiding this comment.
normalized.product is productCodes[0], the EAN13 form of the GTIN. Reproduced the search, with the JS wiring read from the code, not run: a product stored as raw UPC-12 012345678905 is not found by [("barcode", "=ilike", "0012345678905")], and is by the variant list. So that scan answers "not part of the current picking", where barcodeMatchAnyDomain takes the whole list (internal_transfer_screen.esm.js:121).
| Enable it per operation type: | ||
|
|
||
| 1. Go to **Inventory ▸ Configuration ▸ Operations Types** and open the | ||
| type you want (receipts, internal transfers, …). |
There was a problem hiding this comment.
Reproduced: the add RPC refuses a receipt with "Adding a new product line from the scanner is not allowed for this operation type", the page renders invisible="code != 'internal'", and the field's own help says incoming and outgoing never allow new lines. (receipts, internal transfers, …) sends the reader to a checkbox they will not find. Regenerate README.rst with the change.
| type you want (receipts, internal transfers, …). | |
| internal transfer type you want. |
| @@ -0,0 +1,27 @@ | |||
| { | |||
| "name": "Barcode Stock Unexpected Product", | |||
| "version": "18.0.1.1.0", | |||
There was a problem hiding this comment.
The 18.0 guide starts a new module at 18.0.1.0.0, and barcode_stock_quality here does; 1.1.0 reads as a module that already shipped a minor.
| "version": "18.0.1.1.0", | |
| "version": "18.0.1.0.0", |
| "website": "https://github.com/OCA/barcode-interface", | ||
| "maintainers": ["antoniodavid"], | ||
| "license": "AGPL-3", | ||
| "depends": ["barcode_stock"], |
There was a problem hiding this comment.
stock.move.line.qty_picked belongs to stock_move_line_qty_picked (checked in the registry: _module on the field), which barcode_stock declares explicitly. Reaching it only through barcode_stock means this module keeps installing if that dependency ever goes, and then stock_picking.py:152 writes a field that is gone.
|
|
||
|
|
||
| class TestManualLineRegression(TransactionCase): | ||
| def test_manual_line_rpc_remains_available(self): |
There was a problem hiding this comment.
Ran the suite: green with these included, and they still cannot fail on behaviour, since asserting that a method exists is not a case. The field-type, field.store and SQL read-back assertions in test_stock_picking_type.py are the same kind. The guard, merge and availability tests are where the coverage is.
| t-on-click.stop="() => props.onDeleteManual(props.move.id)" | ||
| title="Delete manual line" | ||
| > | ||
| <i class="fa fa-trash" /> |
There was a problem hiding this comment.
Read from the template: this trash is a <span> with a click handler and an unlabelled <i> — no keyboard focus, no accessible name — where the card's own chevron carries role="img" aria-label. Same in the PickingDoneCard block, and the "Add a line" icon needs aria-hidden beside its text.
Summary
barcode_stock_unexpected_productextends the barcode scanner ofbarcode_stockso an operator can add a product that is not part of a transfer's planned lines, instead of being told that the barcode is not part of the operation.The feature is opt-in per operation type. When it is enabled, scanning an unlisted product on the barcode picking screen opens the product selector with the scanned product (and any GS1 quantity/lot) preselected. The operator confirms the demand quantity and the module creates or merges a manually added move, reserving the available stock. Manually added lines can also be deleted from the picking screen.
Why
With
barcode_stock, a scan is only accepted when the product belongs to the current transfer. Warehouse operators sometimes need to add an unexpected product on the spot (for example, a replacement or an extra unit found during picking). Sending them back to the back office breaks the barcode workflow. This module adds that capability without changing the default behaviour: where the setting is off, the scanner keeps rejecting unlisted products exactly as before.Reference: @BinhexTeam T26646
Configuration
The field (
allow_insert_new_line) is a stored boolean, defaults toFalse, and is only rendered forcode == "internal".Usage
Only products with enough available stock at the source location can be added; otherwise the operator gets an explicit error.
How to test
Manual:
barcode_stock_unexpected_product.