fix(商品月加权平均单价): 排除配件仓

This commit is contained in:
chenxi 2026-11-21 11:57:25 +08:00
parent 2eadd534f9
commit fab0d4b8ed
2 changed files with 135 additions and 2 deletions

View File

@ -1550,7 +1550,9 @@ class Pages extends Controller
}
$query = DB::connection($connection)->table('product_monthly_weighted_average_rows')
->where('report_month', $month);
->where('report_month', $month)
// 配件仓不纳入商品月加权平均单价展示。
->where('warehouse_short_name', 'not like', '配件-%');
$productCode = trim((string) request('product_code', ''));
if ($productCode !== '') {
// 与进销存总表一致:商品编码按精确查询。
@ -4062,7 +4064,9 @@ class Pages extends Controller
}
$month = $requested !== '' ? $requested : ($months[0] ?? null);
$query = DB::connection($connection)->table('product_monthly_weighted_average_rows');
$query = DB::connection($connection)->table('product_monthly_weighted_average_rows')
// 与页面一致,配件仓不纳入商品月加权平均单价导出。
->where('warehouse_short_name', 'not like', '配件-%');
if ($month !== null) {
$query->where('report_month', $month);
}

View File

@ -0,0 +1,129 @@
<?php
namespace Tests\Feature\Business;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\Feature\FeatureTestCase;
class MonthlyWeightedAveragePriceWarehouseFilterTest extends FeatureTestCase
{
private string $connection = 'monthly_weighted_average_fixture';
protected function setUp(): void
{
parent::setUp();
config([
'database.connections.' . $this->connection => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
'foreign_key_constraints' => false,
],
'upstream_mirrors.connection' => $this->connection,
]);
DB::purge($this->connection);
Schema::connection($this->connection)->create(
'product_monthly_weighted_average_states',
function (Blueprint $table): void {
$table->date('report_month')->primary();
$table->string('status');
},
);
Schema::connection($this->connection)->create(
'product_monthly_weighted_average_rows',
function (Blueprint $table): void {
$table->date('report_month');
$table->char('row_key', 64);
$table->string('barcode_warehouse');
$table->string('warehouse_short_name');
$table->string('supplier')->nullable();
$table->string('product_code');
$table->string('product_name')->nullable();
$table->decimal('opening_quantity', 20, 4)->nullable();
$table->decimal('opening_unit_price', 20, 4)->nullable();
$table->decimal('opening_original_amount', 20, 4)->nullable();
$table->decimal('adjusted_unit_price', 20, 4)->nullable();
$table->decimal('opening_amount', 20, 4)->nullable();
$table->decimal('purchase_quantity', 20, 4)->nullable();
$table->decimal('purchase_unit_price', 20, 4)->nullable();
$table->decimal('purchase_amount', 20, 4)->nullable();
$table->decimal('weighted_average_unit_price', 20, 4)->nullable();
$table->string('pricing_status')->nullable();
},
);
DB::connection($this->connection)
->table('product_monthly_weighted_average_states')
->insert([
'report_month' => '2026-10-01',
'status' => 'computed',
]);
DB::connection($this->connection)
->table('product_monthly_weighted_average_rows')
->insert([
$this->row('normal', '销售主仓', 'SKU-NORMAL'),
$this->row('accessory', '配件-山东沂海配件单仓', 'SKU-ACCESSORY'),
]);
}
public function test_page_excludes_accessory_warehouses(): void
{
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'product-inventory',
'page' => 'monthly-weighted-average-price',
'month' => '2026-10',
]))
->assertOk()
->assertSeeText('销售主仓')
->assertSeeText('SKU-NORMAL')
->assertDontSeeText('配件-山东沂海配件单仓')
->assertDontSeeText('SKU-ACCESSORY');
}
public function test_export_excludes_accessory_warehouses(): void
{
$response = $this->loginAs()
->get(route('business.product-inventory.monthly-weighted-average-price.export', [
'month' => '2026-10',
]))
->assertOk()
->assertDownload('_2026-10-01.csv');
$content = $response->streamedContent();
$this->assertStringContainsString('销售主仓', $content);
$this->assertStringContainsString('SKU-NORMAL', $content);
$this->assertStringNotContainsString('配件-山东沂海配件单仓', $content);
$this->assertStringNotContainsString('SKU-ACCESSORY', $content);
}
/**
* @return array<string, mixed>
*/
private function row(string $key, string $warehouse, string $productCode): array
{
return [
'report_month' => '2026-10-01',
'row_key' => str_pad($key, 64, '0'),
'barcode_warehouse' => $productCode . $warehouse,
'warehouse_short_name' => $warehouse,
'supplier' => '测试供应商',
'product_code' => $productCode,
'product_name' => '测试商品',
'opening_quantity' => 1,
'opening_unit_price' => 10,
'opening_original_amount' => 10,
'adjusted_unit_price' => 10,
'opening_amount' => 10,
'purchase_quantity' => 1,
'purchase_unit_price' => 10,
'purchase_amount' => 10,
'weighted_average_unit_price' => 10,
'pricing_status' => '已定价',
];
}
}