Skip to content

Commit

Permalink
Filter out non storable products(services) for InventoryItem
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliouzbett committed Dec 3, 2024
1 parent 9f8d7b1 commit 5549f3a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public class OdooConstants {
public static final String MODEL_PRODUCT = "product.product";

public static final String MODEL_CURRENCY = "res.currency";

public static final String PRODUCT_TYPE_STORABLE = "product";
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ public class Product extends BaseOdooModel {

@JsonProperty("currency_id")
private Integer currencyId;

@JsonProperty("type")
private String type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected Product mapRowToResource(Row row) {
product.setPublicPrice((Double) row.get("lst_price"));
product.setStandardPrice((Double) row.get("standard_price"));

var type = row.get("type");
if (type != null) {
product.setType((String) row.get("type"));
}

var active = row.get("active");
if (active != null) {
product.setActive((boolean) row.get("active"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public Optional<InventoryItem> getById(@Nonnull String id) {
log.warn("Inventory Item with ID {} missing a Product", id);
return Optional.empty();
}

// Only return stockable products
if (product.get().getType() == null || !product.get().getType().equals(OdooConstants.PRODUCT_TYPE_STORABLE)) {
return Optional.empty();
}

Map<String, OdooResource> resourceMap = Map.of(
OdooConstants.MODEL_PRODUCT, product.get(),
OdooConstants.MODEL_EXTERNAL_IDENTIFIER, externalIdentifier.get());
Expand All @@ -78,7 +84,9 @@ public Bundle searchForInventoryItems(TokenAndListParam code) {
Collection<ExtId> extIds = extIdService.getResIdsByNameAndModel(codes, OdooConstants.MODEL_PRODUCT);
extIds.forEach(externalIdentifier -> {
Optional<Product> product = productService.getById(String.valueOf(externalIdentifier.getResId()));
if (product.isPresent() && product.get().isActive()) {
if (product.isPresent()
&& product.get().isActive()
&& product.get().getType().equals(OdooConstants.PRODUCT_TYPE_STORABLE)) {
Map<String, OdooResource> resourceMap = Map.of(
OdooConstants.MODEL_PRODUCT,
product.get(),
Expand Down

0 comments on commit 5549f3a

Please sign in to comment.