Warenwirtschaft: Review-Fix — Stichtags-Schutz als unveränderliches Flag (sale_stock_exempt)
Der Schutz historischer Bestellungen hing an shipped_at, das der OrderStatusService beim Status-Toggle nullt und neu stempelt — Storno + erneutes Versenden einer Alt-Bestellung hätte rückwirkend vom heutigen Bestand abgezogen. Migration mit einmaligem Backfill (shipped_at vor 16.07.2026), Guard prüft nur noch das Flag. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
e6af987237
commit
3eb14762e7
6 changed files with 70 additions and 11 deletions
|
|
@ -6,18 +6,10 @@ use App\Models\Product;
|
|||
use App\Models\Production;
|
||||
use App\Models\ProductStockMovement;
|
||||
use App\Models\ShoppingOrder;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductStockService
|
||||
{
|
||||
/**
|
||||
* AP-13-Stichtag: Bestellungen, die vor Einführung des Verkaufs-Abzugs versendet
|
||||
* wurden, sind historisch — ein erneutes Speichern ihres Versandstatus darf nicht
|
||||
* rückwirkend vom heutigen Bestand abziehen.
|
||||
*/
|
||||
public const SALE_STOCK_SINCE = '2026-07-16';
|
||||
|
||||
/**
|
||||
* Aktueller Bestand je Produkt (Summe Eingänge − Summe Ausgänge).
|
||||
*
|
||||
|
|
@ -190,9 +182,11 @@ class ProductStockService
|
|||
*/
|
||||
public function syncSaleStock(ShoppingOrder $order, ?int $userId = null): void
|
||||
{
|
||||
// Historische Bestellungen (vor dem Stichtag versendet) nicht anfassen:
|
||||
// Historische Bestellungen (vor dem AP-13-Stichtag versendet) nicht anfassen:
|
||||
// vor dem Stichtag wurde nichts gebucht, also gibt es auch nichts abzugleichen.
|
||||
if ($order->shipped_at && $order->shipped_at->lt(Carbon::parse(self::SALE_STOCK_SINCE))) {
|
||||
// Das Flag wird per Migration einmalig gesetzt und ist bewusst unveränderlich —
|
||||
// es überlebt damit auch Status-Toggles, die shipped_at nullen und neu stempeln.
|
||||
if ($order->sale_stock_exempt) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue