mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 04:49:36 +00:00
Support dynamic supplier SPNs in BOM import comments
Replace hardcoded LCSC SPN handling with dynamic supplier lookup to support all configured suppliers in BOM import. This allows any supplier defined in Part-DB to have their SPN fields recognized and included in the BOM entry comments during BOM import.
This commit is contained in:
parent
1255534a94
commit
e9bc1be60e
2 changed files with 17 additions and 2 deletions
|
|
@ -400,9 +400,17 @@ class BOMImporter
|
|||
if (isset($mapped_entry['Manufacturer'])) {
|
||||
$comment_parts[] = 'Manf: ' . $mapped_entry['Manufacturer'];
|
||||
}
|
||||
if (isset($mapped_entry['LCSC SPN'])) {
|
||||
$comment_parts[] = 'LCSC: ' . $mapped_entry['LCSC SPN'];
|
||||
|
||||
// Add supplier part numbers dynamically
|
||||
$suppliers = $this->entityManager->getRepository(\App\Entity\Parts\Supplier::class)->findAll();
|
||||
foreach ($suppliers as $supplier) {
|
||||
$supplierName = $supplier->getName();
|
||||
$spnKey = $supplierName . ' SPN';
|
||||
if (isset($mapped_entry[$spnKey]) && !empty($mapped_entry[$spnKey])) {
|
||||
$comment_parts[] = $spnKey . ': ' . $mapped_entry[$spnKey];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($mapped_entry['Supplier and ref'])) {
|
||||
$comment_parts[] = $mapped_entry['Supplier and ref'];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -356,8 +356,11 @@ class BOMImporterTest extends WebTestCase
|
|||
// Create test suppliers for this test
|
||||
$lcscSupplier = new Supplier();
|
||||
$lcscSupplier->setName('LCSC');
|
||||
$mouserSupplier = new Supplier();
|
||||
$mouserSupplier->setName('Mouser');
|
||||
|
||||
$this->entityManager->persist($lcscSupplier);
|
||||
$this->entityManager->persist($mouserSupplier);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$input = <<<CSV
|
||||
|
|
@ -394,14 +397,18 @@ class BOMImporterTest extends WebTestCase
|
|||
$this->assertStringContainsString('MPN: CRCW080510K0FKEA', $bom_entries[0]->getComment());
|
||||
$this->assertStringContainsString('Manf: Vishay', $bom_entries[0]->getComment());
|
||||
$this->assertStringContainsString('LCSC SPN: C123456', $bom_entries[0]->getComment());
|
||||
$this->assertStringContainsString('Mouser SPN: 123-M10K', $bom_entries[0]->getComment());
|
||||
|
||||
|
||||
// Check second entry
|
||||
$this->assertEquals('C1', $bom_entries[1]->getMountnames());
|
||||
$this->assertEquals(1.0, $bom_entries[1]->getQuantity());
|
||||
$this->assertStringContainsString('LCSC SPN: C789012', $bom_entries[1]->getComment());
|
||||
$this->assertStringContainsString('Mouser SPN: 80-CL21A104KOCLRNC', $bom_entries[1]->getComment());
|
||||
|
||||
// Clean up
|
||||
$this->entityManager->remove($lcscSupplier);
|
||||
$this->entityManager->remove($mouserSupplier);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue