Skip to content

[18.0][ADD] barcode_stock_unexpected_product - #23

Open
antoniodavid wants to merge 1 commit into
OCA:18.0from
BinhexTeam:18.0-add-barcode_stock_unexpected_product
Open

antoniodavid wants to merge 1 commit into
OCA:18.0from
BinhexTeam:18.0-add-barcode_stock_unexpected_product

Conversation

@antoniodavid

@antoniodavid antoniodavid commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

barcode_stock_unexpected_product extends the barcode scanner of barcode_stock so 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

  1. Go to Inventory ▸ Configuration ▸ Operation Types and open an internal operation type.
  2. On the Barcode tab, tick Allow Adding New Product Lines from the Scanner.

The field (allow_insert_new_line) is a stored boolean, defaults to False, and is only rendered for code == "internal".

Usage

  1. Open a planned internal transfer in the barcode app.
  2. Scan a product that is not in the transfer's move lines.
  3. The product selector opens with the product preselected; set the quantity and, for tracked products, the lot/serial number.
  4. Confirm: the move is added as pending demand and the available stock is reserved. Scanning the same product again merges into the same manual move.
  5. Use the delete action on a manually added line to remove it and release its reservation.

Only products with enough available stock at the source location can be added; otherwise the operator gets an explicit error.

How to test

Manual:

  1. Install barcode_stock_unexpected_product.
  2. Enable Allow Adding New Product Lines from the Scanner on an internal operation type.
  3. Create and confirm an internal transfer with at least one planned line.
  4. Scan an unlisted product, confirm the selector, and check that a manual line is created and reserved.
  5. Repeat the scan and check that the quantity is merged.
  6. Delete the manual line and check that the reservation is released.
  7. Disable the setting and check that the unlisted scan is rejected again; also check that creating an internal transfer from scratch still works.

@OCA-git-bot OCA-git-bot added series:18.0 mod:barcode_stock_unexpected_product Module barcode_stock_unexpected_product labels Nov 6, 2026
move.unlink()
return {"deleted": True, "move_id": move_id}

@api.model

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@antoniodavid
antoniodavid force-pushed the 18.0-add-barcode_stock_unexpected_product branch 2 times, most recently from 63db0e5 to 09b5bd1 Compare November 12, 2026 04:23
@antoniodavid

Copy link
Copy Markdown
Author

ping @szalatyzuzanna @edescalona

@szalatyzuzanna

Copy link
Copy Markdown

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

@antoniodavid

antoniodavid commented Nov 12, 2026 •

Copy link
Copy Markdown
Author

Thanks @szalatyzuzanna, I added a full description covering what the addon does.

@rrebollo rrebollo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
raise UserError(_("The selected lot is not valid.")) from None
raise UserError(self.env._("The selected lot is not valid.")) from None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@antoniodavid
antoniodavid force-pushed the 18.0-add-barcode_stock_unexpected_product branch from 09b5bd1 to 06792a4 Compare November 17, 2026 16:04
@antoniodavid

Copy link
Copy Markdown
Author

@rrebollo rrebollo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, …).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested 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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:barcode_stock_unexpected_product Module barcode_stock_unexpected_product series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants