# ADR 0001 — Customers edit an order only before payment and before the seller answers

- Status: accepted
- Date: 2026-10-20
- Context: redesign of `/purchase_history` (grouped Combined Orders, one details page, customer editing)

## Context

Customers will be able to change the quantity and the variant of the lines of their
orders. A Combined Order is split into one Child Order per seller, and each Child Order
moves on its own: the seller confirms it (WhatsApp / panel / app), staff confirm it
(Confirm Orders), Kapitano Logistic picks it up, the accountant settles cash on delivery
per Child Order, and a Paymera payment covers the whole Combined Order at once.

An edit at the wrong moment either changes money already taken (a paid Paymera order
would need an extra charge or a partial refund on a payment shared by every seller) or
changes a basket somebody already acted on (the seller confirmed they have these items;
the captain is carrying them).

## Decision

A customer may edit a Child Order only while **all** of these hold:

1. `orders.delivery_status = 'pending'`;
2. `orders.payment_status = 'unpaid'`;
3. its seller has not answered: `seller_confirmed_at` and `seller_unavailable_at` are
   both empty (an in-house order has no seller step, so it needs only the other rules);
4. its `payment_type` is not `paymera`: an unpaid Paymera order may already have a
   payment link for the old amount, and `markCombinedOrderPaid` does not compare
   amounts, so paying the old link after an edit would mark it paid at the wrong total;
5. it was placed after `business_settings.stock_on_confirm_since`: older orders took
   their stock at placement, and an edit would have to move stock under the old rule.

After that the customer can only cancel (the existing pending + unpaid rule) or contact
customer service; staff keep their own edit screens.

Rejected: "pending **or** unpaid" (cash on delivery stays unpaid until delivered, so it
would allow edits while the captain is at the door, and would allow edits of paid
Paymera orders); editing after the seller confirmed with a reset and re-alert of the
seller (more moving parts, the seller has to answer twice).

## Consequences

- No edit ever touches money already paid: no extra charge, refund, store credit or
  Paymera adjustment exists in this feature.
- No edit invalidates a seller's or staff member's decision, so the seller-alert,
  follow-up and Logistic flows need no "re-confirm" path.
- The window is short (sellers often answer within minutes). Widening it later, e.g.
  to "until staff confirm", needs a seller re-confirmation flow, which is a new design,
  not a flag.
- One rule decides editability for the web page and, later, the app; it must live in
  one place (not copied into the views).
