Repository navigation
Fix Picnic mapping and mode switch dropping quantities - #453
Merged
Merged
Conversation
Order.cart/1 keyed everything by supermarket_product_id, so an ingredient without a supermarket product silently dropped out of the computed list — in picnic mode those items vanished from the shopping list instead of staying as checklist rows (Avocado bio, Eieren, Basilicum). The cart is now keyed by ingredient and falls back to the ingredient id as item key when there is no product. picnic_line/1 only fell back ingredients with no Picnic mapping. A mapped ingredient whose product never made it into the cart — the push failed or never ran — disappeared the same way. Any wanted item the cart does not hold now shows as a checklist row. manual_ingredients/1 and Recipe.item_quantities/1 could hand nil keys to the supermarket sync; both now filter them. ordered_item_quantities/1 added 2 instead of the item's quantity when an id repeated. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Mapping a checklist ingredient to a Picnic product used to drop its quantity to 0: edit_ingredient wrote the mapping but never synced, so the item left the checklist fallback and never entered the cart (Gist, Baksoda, Optimel went 1 -> 0). And when the Picnic cart already held the product, the cart's quantity silently stood in for the list's (Melk: 2 on the list plus 1 in the cart ended at 1). Merge rule, now documented in the map_ingredient_picnic tool description: the quantity the list wants and the quantity the cart holds add up. Ingredients.edit_ingredient/1, on a changed mapping in picnic mode, hands the cart's quantity of the new product to Order.adopt_picnic_quantity/2, which records list + cart as the ingredient's manual quantity and syncs — mapping can never lower what either side asked for. A manual row pinning the ingredient at 0 wins over adoption. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
get_shopping_list reported the Picnic cart's stored total_price and total_count, which can disagree with the items the cart holds — the cached cart keeps a stale total (the list showed 15 items priced above the reported EUR 18.55). LineFromPicnic now sums both totals over the articles it lists, so the reply is always consistent with its own items. The get_shopping_list tool description now says what counts: in picnic mode only the Picnic cart rows carry a price; checklist items add to total_count but not total_price. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
A Picnic cart article the store cannot sell carries an UNAVAILABLE decorator. Picape never read it, so picnic items always reported is_orderable true and the replacement fallback only ran in ah mode. LineFromPicnic now maps the decorator to is_orderable and the sync and substitution code generalizes over the product id field, so a mapped product Picnic cannot sell falls back to the replacement ingredient's Picnic product, flagged substituted_for. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sync substituted the two maps separately and let Sync.changes merge them, so a manual row on an unavailable product overwrote the plan's quantity on its replacement instead of adding to it. Manual 2 on an unavailable product plus planned 1 on the replacement pushed 2, not 3; manual 0 removed the planned replacement outright. Merge by original product id first (manual still wins per product) and substitute once, on both the supermarket and the Picnic path. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Mapping adopted `wanted + cart_quantity` as a manual row whenever the sum was positive, so a product absent from the cart still got its wanted quantity pinned as manual. Unplanning the recipe then left the item on the list forever. Only a cart quantity above zero is worth adopting; without one the sync keeps the plan's quantity on its own. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
`picnic_cart_quantity` read the ConCache cart, which can be five hours old, so mapping adopted whatever the cache remembered rather than what the cart really holds. Invalidate before reading so the adopted sum uses the live cart. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
An ORDER_ARTICLE's price is per unit, so multiplying by quantity stays. But an article carrying the UNAVAILABLE decorator cannot be sold and should not add to what the order would cost. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
adri
marked this pull request as ready for review
October 18, 2026 18:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes four quantity bugs from #452 that Greg Grocery hit on production:
map_ingredient_picnicwrote the mapping but never synced, so the item left the checklist fallback without entering the Picnic cart. Gist, Baksoda and Optimel went 1 → 0.Ingredients.edit_ingredient/1hands the cart's quantity of the new product toOrder.adopt_picnic_quantity/2, which records the sum as the ingredient's manual quantity and syncs. Mapping can never lower what either side asked for. A manual row pinning the ingredient at 0 wins over adoption.set_mode("picnic")dropped unmapped ingredients.Order.cart/1keyed everything bysupermarket_product_id, so ingredients without a product (Basilicum) or without a Picnic line fell out of the list. The cart is now keyed by ingredient, and any wanted item the Picnic cart does not hold stays visible as a checklist row — including mapped ones whose push never landed.get_shopping_listtotal disagreed with its items.LineFromPicnictrusted the cart's storedtotal_price/total_count, which the cache can return stale. Both totals are now summed over the listed articles. The tool description now states the scope: only Picnic cart rows carry a price; checklist items count towardstotal_countbut nottotal_price.is_orderable.LineFromPicnicleft the field at its default true, so a mapped product Picnic cannot sell (Bio avocados, s1015273) never flagged and the replacement fallback never ran. The api/15 ORDER_ARTICLE carries anUNAVAILABLEdecorator;LineFromPicnicnow maps it tois_orderableandavailability_label, and the sync runs the same substitutionOrderalready did for AH: the wanted id swaps for the replacement ingredient'spicnic_product_id, the unavailable product stays in the cart flagged, andsubstituted_fornames what it stands in for.Also fixed along the way:
ordered_item_quantities/1added 2 instead of the item's quantity on a repeated id, andmanual_ingredients/1/Recipe.item_quantities/1could handnilproduct keys to the supermarket sync.Review round 2
lib/picape/order.ex:222(ah) andlib/picape/order.ex:561(picnic).adopt_picnic_quantitywrotewanted + cart_quantitywhenever the sum was positive, so unplanning the recipe later left the item on the list forever. Only a cart quantity above 0 is adopted now.lib/picape/order.ex:328.picnic_cart_quantitynow invalidates the cache first, so the adopted sum uses the live cart.lib/picape/ingredients.ex:178.ORDER_ARTICLE.priceis per unit (verified against the api/15 shape), so the multiply stays — but articles with anUNAVAILABLEdecorator are now skipped intotal_price.lib/picape/order/line_from_picnic.ex:22.Test plan
mix checkgreen (format, credo strict, warnings-as-errors compile, 190 tests, sobelow)cd frontend && npm run checkgreenbin/e2egreen (95 passed, 10 skipped, WebKit)total_priceconsistency, anah → picnic → checklist → ahround trip keeping every quantity, and an unavailable mapped product falling back to its replacementtotal_priceat quantity 2 and its exclusion of unavailable itemsNo checkout, payment or delivery-slot calls are made anywhere. AH product ids and replacement mappings are untouched. No migrations.
Impact
cc @adri
Generated with Devin