fix: 厂家退货净扣减不计预估金额 #856

Merged
renshen merged 1 commits from fix/supplier-return-net-amount into main 2026-11-04 13:50:13 +08:00
2 changed files with 37 additions and 2 deletions

View File

@ -35,8 +35,9 @@ class SupplierReturnAccounting
}
$qty = $this->number($row['qty'] ?? 0);
$unitPrice = $this->number($row['unit_price'] ?? $row['guess_unit_price'] ?? 0);
$amount = $this->number($row['amount'] ?? $row['guess_amount'] ?? 0);
// 厂家净扣减只按实际单价/金额计算,不能用预估单价或预估金额兜底。
$unitPrice = $this->number($row['unit_price'] ?? 0);
$amount = $this->number($row['amount'] ?? 0);
if ($amount === 0.0 && $qty !== 0.0) {
$amount = $qty * $unitPrice;
}

View File

@ -78,4 +78,38 @@ class SupplierReturnAccountingTest extends TestCase
$this->assertSame(3.0, $row['_supplier_qty']);
$this->assertSame(750.0, $row['_supplier_amount']);
}
public function test_supplier_net_amount_never_uses_estimated_price_or_amount(): void
{
$accounting = new SupplierReturnAccounting();
$rows = [
[
'qty' => '2',
'unit_price' => '50',
'amount' => '100',
'guess_unit_price' => '999',
'guess_amount' => '999',
],
[
'qty' => '5',
'unit_price' => '0',
'amount' => '0',
'guess_unit_price' => '30',
'guess_amount' => '150',
],
[
'qty' => '3',
'unit_price' => '20',
'amount' => '0',
'guess_amount' => '999',
],
];
$unpriced = $accounting->enrich($rows[1]);
$summary = $accounting->summarize($rows);
$this->assertSame(0.0, $unpriced['_supplier_amount']);
$this->assertSame(10.0, $summary['supplier_qty']);
$this->assertSame(160.0, $summary['supplier_amount']);
}
}