采购金额
This commit is contained in:
@@ -200,7 +200,7 @@ class PurchaseEditTest extends ProcurementTestCase
|
||||
'cost_price' => 25,
|
||||
])->assertOk()
|
||||
->assertJsonPath('success', true)
|
||||
->assertJsonPath('msg', '已同步 2 条订货明细;商品已删除,档案未同步');
|
||||
->assertJsonPath('msg', '已同步 2 条订货明细;商品已删除,档案未同步;门店单价已按等级上浮比例重算');
|
||||
|
||||
$this->assertSame('已删商品新名', StoreOrderItemModel::first()->product_name, '订货明细照常更新');
|
||||
$this->assertNotSame('已删商品新名', $product->fresh()->name, '商品档案不同步');
|
||||
@@ -287,6 +287,84 @@ class PurchaseEditTest extends ProcurementTestCase
|
||||
$this->assertSame('80.00', (string) $purchase->estimate_amount, '8 包 × 每包成本 10.00(称重仅参考,不参与金额)');
|
||||
}
|
||||
|
||||
/** 行级成本修改 → 明细单价按各门店等级上浮比例重算,订单与采购单汇总级联 */
|
||||
public function test_update_row_cost_change_reprices_items_by_store_level(): void
|
||||
{
|
||||
// 门店A 上浮 0%(售价=成本),门店B 上浮 50%
|
||||
$levelA = CustomerLevelModel::factory()->create(['percent' => 0]);
|
||||
$levelB = CustomerLevelModel::factory()->create(['percent' => 50]);
|
||||
$storeA = StoreModel::factory()->create(['level_id' => $levelA->id]);
|
||||
$storeB = StoreModel::factory()->create(['level_id' => $levelB->id]);
|
||||
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => 10]);
|
||||
|
||||
foreach ([[$storeA, 2], [$storeB, 3]] as [$store, $qty]) {
|
||||
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
|
||||
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => $qty]]])
|
||||
->assertJsonPath('success', true);
|
||||
}
|
||||
StoreOrderModel::query()->update(['status' => StoreOrderModel::STATUS_SUMMARIZED]);
|
||||
|
||||
$this->actingAsSysUser();
|
||||
$this->postJson('/purchase/order/generate', ['purchase_date' => now()->toDateString()])
|
||||
->assertJsonPath('success', true);
|
||||
$purchase = PurchaseOrderModel::first();
|
||||
|
||||
// 下单时快照:A 店 10.00(10 上浮 0%),B 店 15.00(10 上浮 50%)
|
||||
$itemA = StoreOrderItemModel::where('store_id', $storeA->id)->first();
|
||||
$itemB = StoreOrderItemModel::where('store_id', $storeB->id)->first();
|
||||
$this->assertSame('10.00', (string) $itemA->price);
|
||||
$this->assertSame('15.00', (string) $itemB->price);
|
||||
|
||||
// 行修改成本 10 → 20:单价按各店等级上浮比例重算
|
||||
$this->putJson("/purchase/order/{$purchase->id}/row/{$product->id}", [
|
||||
'product_name' => $product->name,
|
||||
'supplier_id' => SupplierModel::factory()->create()->id,
|
||||
'product_spec' => $product->spec,
|
||||
'unit' => $product->unit,
|
||||
'cost_price' => 20,
|
||||
])->assertOk()
|
||||
->assertJsonPath('success', true)
|
||||
->assertJsonPath('msg', '已同步 2 条订货明细与商品档案;门店单价已按等级上浮比例重算');
|
||||
|
||||
$itemA->refresh();
|
||||
$this->assertSame('20.00', (string) $itemA->cost_price);
|
||||
$this->assertSame('20.00', (string) $itemA->price, 'A 店:20 上浮 0% = 20.00');
|
||||
$this->assertSame('40.00', (string) $itemA->amount, '20.00 × 2');
|
||||
|
||||
$itemB->refresh();
|
||||
$this->assertSame('30.00', (string) $itemB->price, 'B 店:20 上浮 50% = 30.00');
|
||||
$this->assertSame('90.00', (string) $itemB->amount, '30.00 × 3');
|
||||
|
||||
$this->assertSame('40.00', (string) StoreOrderModel::where('store_id', $storeA->id)->first()->total_amount);
|
||||
$this->assertSame('90.00', (string) StoreOrderModel::where('store_id', $storeB->id)->first()->total_amount);
|
||||
$this->assertSame('100.00', (string) $purchase->fresh()->estimate_amount, '5 包 × 新成本 20.00');
|
||||
}
|
||||
|
||||
/** 行修改未改成本 → 明细单价保持不变(不覆盖单元格的手工改价) */
|
||||
public function test_update_row_without_cost_change_keeps_item_price(): void
|
||||
{
|
||||
[$purchase, $product, $stores] = $this->buildPurchase();
|
||||
$this->actingAsSysUser();
|
||||
|
||||
// 先通过单元格手工改价 10 → 12
|
||||
$item = StoreOrderItemModel::where('store_id', $stores[0]->id)->first();
|
||||
$this->putJson("/purchase/order/cell/{$item->id}", ['quantity' => 2, 'price' => 12])
|
||||
->assertJsonPath('success', true);
|
||||
|
||||
// 行修改只改品名(成本不变)
|
||||
$this->putJson("/purchase/order/{$purchase->id}/row/{$product->id}", [
|
||||
'product_name' => '只改品名',
|
||||
'supplier_id' => SupplierModel::factory()->create()->id,
|
||||
'product_spec' => $product->spec,
|
||||
'unit' => $product->unit,
|
||||
'cost_price' => 10,
|
||||
])->assertOk()
|
||||
->assertJsonPath('success', true)
|
||||
->assertJsonPath('msg', '已同步 2 条订货明细与商品档案');
|
||||
|
||||
$this->assertSame('12.00', (string) $item->fresh()->price, '成本未变时保留手工改价');
|
||||
}
|
||||
|
||||
/** 门店购买详情-新增单品:挂靠最新一笔订单,汇总级联重算;重复添加拒绝 */
|
||||
public function test_store_item_add_creates_item_and_recalculates(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user