Warenwirtschaft: AP-13 — Stichtags-Schutz für vor Einführung versendete Bestellungen
Erneutes Speichern des Versandstatus einer Alt-Bestellung (shipped_at vor 16.07.2026) hätte rückwirkend vom heutigen Bestand abgezogen. syncSaleStock() überspringt historische Bestellungen jetzt per Stichtag SALE_STOCK_SINCE. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
f51da96354
commit
c0476ebe24
4 changed files with 33 additions and 0 deletions
|
|
@ -6,10 +6,18 @@ 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).
|
||||
*
|
||||
|
|
@ -182,6 +190,12 @@ class ProductStockService
|
|||
*/
|
||||
public function syncSaleStock(ShoppingOrder $order, ?int $userId = null): void
|
||||
{
|
||||
// Historische Bestellungen (vor dem 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))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target = [];
|
||||
if (in_array($order->getAPIShippedType(), ['sent', 'close'], true)) {
|
||||
$order->loadMissing('shopping_order_items');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue