默认重量
This commit is contained in:
@@ -282,7 +282,7 @@ class PurchaseEditTest extends ProcurementTestCase
|
||||
$this->assertSame('50.00', (string) $order->total_amount);
|
||||
|
||||
$purchase = $purchase->fresh();
|
||||
$this->assertSame('4.500', (string) $purchase->total_weight);
|
||||
$this->assertSame('7.500', (string) $purchase->total_weight, '4.500 手动称重 + B 店参考重量 3.000');
|
||||
$this->assertSame('80.00', (string) $purchase->estimate_amount, '8 包 × 每包成本 10.00(称重仅参考,不参与金额)');
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ class PurchaseEditTest extends ProcurementTestCase
|
||||
$purchase = $purchase->fresh();
|
||||
$this->assertSame('9.00', (string) $purchase->total_quantity, '2+3+4');
|
||||
$this->assertSame('82.00', (string) $purchase->estimate_amount, '50+32(4 包 × 成本 8.00)');
|
||||
$this->assertSame('1.500', (string) $purchase->total_weight);
|
||||
$this->assertSame('6.500', (string) $purchase->total_weight, '原有参考重量 2+3 斤 + 新增 1.500');
|
||||
|
||||
// 重复添加同一商品 → 拒绝
|
||||
$this->postJson("/purchase/order/{$purchase->id}/store/{$stores[0]->id}/item", [
|
||||
@@ -402,6 +402,28 @@ class PurchaseEditTest extends ProcurementTestCase
|
||||
->assertJsonPath('msg', '该商品已在此门店采购明细中,请直接修改数量');
|
||||
}
|
||||
|
||||
/** 门店购买详情-新增单品未传称重:按订货量 × 规格预填参考重量并级联汇总 */
|
||||
public function test_store_item_add_defaults_reference_weight(): void
|
||||
{
|
||||
[$purchase, , $stores] = $this->buildPurchase();
|
||||
$extra = ProductModel::factory()->create([
|
||||
'status' => ProductModel::STATUS_ON,
|
||||
'cost_price' => 8,
|
||||
'spec' => '25斤/袋',
|
||||
'unit' => '袋',
|
||||
]);
|
||||
$this->actingAsSysUser();
|
||||
|
||||
$this->postJson("/purchase/order/{$purchase->id}/store/{$stores[0]->id}/item", [
|
||||
'product_id' => $extra->id,
|
||||
'quantity' => 2,
|
||||
])->assertOk()->assertJsonPath('success', true);
|
||||
|
||||
$item = StoreOrderItemModel::where('product_id', $extra->id)->first();
|
||||
$this->assertSame('50.000', (string) $item->weight, '2 袋 × 25斤/袋');
|
||||
$this->assertSame('55.000', (string) $purchase->fresh()->total_weight, '原有参考重量 5.000 + 新增 50.000');
|
||||
}
|
||||
|
||||
/** 门店购买详情-修改单品:同商品多笔订单明细合并到最早一条,涉及订单逐一重算 */
|
||||
public function test_store_item_update_merges_multi_order_rows(): void
|
||||
{
|
||||
|
||||
@@ -139,4 +139,30 @@ class PurchaseGenerateTest extends ProcurementTestCase
|
||||
|
||||
$this->assertSame(1, PurchaseOrderModel::count(), '第二次生成应被拒绝,不产生新采购单');
|
||||
}
|
||||
|
||||
/** 采购单总重量 = 订货明细参考重量合计(下单时已按订货量 × 规格预填) */
|
||||
public function test_generate_sums_reference_weight(): void
|
||||
{
|
||||
$level = CustomerLevelModel::factory()->create();
|
||||
$store = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$product = ProductModel::factory()->create([
|
||||
'status' => ProductModel::STATUS_ON,
|
||||
'cost_price' => '6.00',
|
||||
'spec' => '10斤/箱',
|
||||
'unit' => '箱',
|
||||
]);
|
||||
|
||||
$this->actingAsMiniStore($store);
|
||||
foreach ([3, 4] as $qty) {
|
||||
$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);
|
||||
|
||||
$this->assertSame('70.000', (string) PurchaseOrderModel::first()->total_weight, '(3+4) 箱 × 10斤/箱');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,40 @@ class StoreOrderTest extends ProcurementTestCase
|
||||
$this->assertSame('10.00', (string) $order->total_amount, '应按等级价 5.00×2 计算,忽略前端金额');
|
||||
}
|
||||
|
||||
/** 下单预填参考重量 = 订货量 × 规格折算(按重量计价的商品订货量即重量),订单总重量 = 明细合计 */
|
||||
public function test_place_order_prefills_reference_weight(): void
|
||||
{
|
||||
$level = CustomerLevelModel::factory()->create();
|
||||
$store = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$byBox = ProductModel::factory()->create([
|
||||
'status' => ProductModel::STATUS_ON,
|
||||
'cost_price' => '5.00',
|
||||
'spec' => '10斤/箱',
|
||||
'unit' => '箱',
|
||||
]);
|
||||
$byJin = ProductModel::factory()->create([
|
||||
'status' => ProductModel::STATUS_ON,
|
||||
'cost_price' => '5.00',
|
||||
'spec' => '散装',
|
||||
'unit' => '斤',
|
||||
]);
|
||||
|
||||
$this->actingAsMiniStore($store);
|
||||
$this->postJson('/mini/order', [
|
||||
'items' => [
|
||||
['product_id' => $byBox->id, 'quantity' => 3],
|
||||
['product_id' => $byJin->id, 'quantity' => 5],
|
||||
],
|
||||
])->assertOk()->assertJsonPath('success', true);
|
||||
|
||||
$order = StoreOrderModel::where('store_id', $store->id)->first();
|
||||
$boxItem = $order->items->firstWhere('product_id', $byBox->id);
|
||||
$jinItem = $order->items->firstWhere('product_id', $byJin->id);
|
||||
$this->assertSame('30.000', (string) $boxItem->weight, '3 箱 × 10斤/箱');
|
||||
$this->assertSame('5.000', (string) $jinItem->weight, '按斤计价:订货量即重量');
|
||||
$this->assertSame('35.000', (string) $order->total_weight, '订单总重量 = 明细参考重量合计');
|
||||
}
|
||||
|
||||
/** 门店绑定的客户等级被删除时拒绝下单 */
|
||||
public function test_store_level_missing_rejected(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user