From fab0d4b8ed54eb63cc6cddafefe1acec2b0efd34 Mon Sep 17 00:00:00 2001 From: chenxi Date: Sat, 21 Nov 2026 11:57:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=95=86=E5=93=81=E6=9C=88=E5=8A=A0?= =?UTF-8?q?=E6=9D=83=E5=B9=B3=E5=9D=87=E5=8D=95=E4=BB=B7):=20=E6=8E=92?= =?UTF-8?q?=E9=99=A4=E9=85=8D=E4=BB=B6=E4=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Business/Pages.php | 8 +- ...eightedAveragePriceWarehouseFilterTest.php | 129 ++++++++++++++++++ 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/Business/MonthlyWeightedAveragePriceWarehouseFilterTest.php diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 1f801e0b..ffc026ac 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -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); } diff --git a/tests/Feature/Business/MonthlyWeightedAveragePriceWarehouseFilterTest.php b/tests/Feature/Business/MonthlyWeightedAveragePriceWarehouseFilterTest.php new file mode 100644 index 00000000..6f561c36 --- /dev/null +++ b/tests/Feature/Business/MonthlyWeightedAveragePriceWarehouseFilterTest.php @@ -0,0 +1,129 @@ +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 + */ + 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' => '已定价', + ]; + } +}