InvenTree icon indicating copy to clipboard operation
InvenTree copied to clipboard

Cannot import BOM -- Invalid Type

Open galmiklos opened this issue 9 months ago • 6 comments

Please verify that this bug has NOT been raised before.

  • [x] I checked and didn't find a similar issue

Describe the bug*

Trying to import a BOM to an assembly part from a csv file. I have all the parts added to the inventory, with the manufacturer part number as "Part". All rows show "Incorrect type. Expected pk value, received str."

Steps to Reproduce

  1. Create a part, assembly type.

  2. Click the "Import BOM Data" icon.

  3. Select csv file (attached for reference) and Submit. SmartPrintCoreH7x_BOM.csv

  4. Map the "Manufacturer_Part_Number" column to Component, and the "Qty" column to Quantity. Image

  5. Click Accept Column Mapping

All entries in the Component column are marked incorrect.

Image

Expected behaviour

I expect the BOM import to work with this csv file.

Deployment Method

  • [ ] Docker
  • [ ] Package
  • [x] Bare metal
  • [ ] Other - added info in Steps to Reproduce

Version Information

InvenTree-Version: 0.18.0 dev Django Version: 4.2.19 Commit Hash: 06961c6 Commit Date: 2025-03-07 Commit Branch: master Database: mysql Debug-Mode: False Deployed using Docker: False Platform: Linux-6.8.0-52-generic-x86_64-with-glibc2.35 Installer: GIT Active plugins: [{"name":"InvenTreeBarcode","slug":"inventreebarcode","version":"2.1.0"},{"name":"InvenTreeCoreNotificationsPlugin","slug":"inventreecorenotificationsplugin","version":"1.0.0"},{"name":"InvenTreeCurrencyExchange","slug":"inventreecurrencyexchange","version":"1.0.0"},{"name":"InvenTreeLabel","slug":"inventreelabel","version":"1.1.0"},{"name":"InvenTreeLabelMachine","slug":"inventreelabelmachine","version":"1.0.0"},{"name":"InvenTreeLabelSheet","slug":"inventreelabelsheet","version":"1.0.0"},{"name":"DigiKeyPlugin","slug":"digikeyplugin","version":"1.0.0"},{"name":"LCSCPlugin","slug":"lcscplugin","version":"1.0.0"},{"name":"MouserPlugin","slug":"mouserplugin","version":"1.0.0"},{"name":"TMEPlugin","slug":"tmeplugin","version":"1.0.0"}]

Please verify if you can reproduce this bug on the demo site.

  • [ ] I can reproduce this bug on the demo site.

Relevant log output


galmiklos avatar Mar 25 '25 23:03 galmiklos

With the manufacturer part number as "Part"

You cannot import based on MPN - the only mapping to an internal part is the "PK" (primary key / unique ID) for the part instance.

There are some outstanding issues regarding adding support for import via "natural key lookup":

  • https://github.com/inventree/InvenTree/issues/7574
  • https://github.com/inventree/InvenTree/issues/9248
  • https://github.com/inventree/InvenTree/issues/7573

However none of these have received any developer attention.

SchrodingersGat avatar Mar 26 '25 02:03 SchrodingersGat

It works with 0.17.7, I can import the same BOM. I thought I could expect the same in the dev release, too.

Image

Image

Image

Most of the parts are not created in this instance of inventree, so there are only a few good hits, but those are marked "not matching part found". The existing parts are matched to the MPNs in the BOM.

galmiklos avatar Mar 26 '25 12:03 galmiklos

@galmiklos the importer in stable is a completely different workflow and we have not yet been able to get natural key support working in the new implementation. There are a number of large architectural differences, overall the new importer is a much better solution but not all the features are ported yet

SchrodingersGat avatar Mar 26 '25 21:03 SchrodingersGat

@galmiklos I have always used IPN for BoM import lookup why I'm in the same situation as you. As a workatound I have created a Python script using the Python Module where I add an Inventree pk column to each BoM csv file, then the import works as a charm.

If you are more familiar with excel the same can be achieved by exporting all your parts to an excel table and use vlookup to populate a pk column in your BoM.

As @SchrodingersGat mention the Inventree pk is currently the only implemented matching field why there is no way around than to add the same into your BoMs.

gunstr avatar Mar 27 '25 08:03 gunstr

Thank you for the advice, for now I went back to the stable release, and imported my BOM. I am not closing this issue, in case you want to keep it to keep track of this "feature request", but of course, I consider it solved from my point of view.

Thanks again!

galmiklos avatar Mar 30 '25 15:03 galmiklos

A workaround for those using the InvenTree Kicad plugin: assuming all schematic parts are InvenTree sourced (ie. the InvenTree property contains the part PK) you can use a cli oneliner to generate a CSV file compatible with the BOM importer:

kicad-cli sch export bom --labels 'PK,Qty' --fields 'InvenTree,${QUANTITY}' my_pcb.sch

ius avatar Apr 12 '25 21:04 ius

This issue seems stale. Please react to show this is still important.

github-actions[bot] avatar Jun 12 '25 11:06 github-actions[bot]

Yes, it is important, I would like to be able to import parts without having to know the PKs, just as it works now in the current stable release. I just kept this issue open, in case you needed it for tracking this "feature request", but of course, please feel free to close it, I don't have any immediate expectation.

Thank you!

galmiklos avatar Jun 15 '25 11:06 galmiklos