Skip to content

Conversation

@mkoeck
Copy link

@mkoeck mkoeck commented Aug 25, 2025

When scanning a lot/serial barcode that resolves to exactly one stock.lot, _getProductByLotBarcode fetches the related product.product via:

product = await this.pos.data.searchRead("product.product", ...);

searchRead always returns an array. The current code only collapses the result when length > 1, so when length === 1 the variable product remains an Array and is returned as such.

Upstream, _barcodeLotAction checks:

if (product instanceof Array) {
    // treat as multiple lots, build a names string
    const productNamesString = product
        .map(
            (lot) => this.pos.models["product.product"].get(lot.product_id).name
        )
        .join(", ");
    ...
}

This branch assumes an array of lots (with product_id), but it actually receives an array of products. That mismatch raises an exception while accessing lot.product_id and then .name on an undefined lookup.

Current behavior before PR

  • Scanning a lot barcode that maps to one lot whose product isn’t yet cached in the POS frontend:
    • The function returns a one-item product array.
    • _barcodeLotAction treats it as multiple lots and executes the mapping above.
    • An exception is raised while building productNamesString instead of adding the product line because a product object does not have a product_id attribute, therefore this.pos.models["product.product"].get fails to look up the product

Desired behavior after PR is merged

  • Single-item results from searchRead("product.product", ...) are collapsed to a record (product = product[0]).
  • _barcodeLotAction receives a product record (not an array) and proceeds to add the product to the order.
  • If the search returns no records (length === 0), _getProductByLotBarcode correctly returns false (“not available in POS”).

@mkoeck mkoeck changed the title [FIX] pos_lot_barcode: Collapse product array when length > 0 [18.0][FIX] pos_lot_barcode: Collapse product array when length > 0 Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant