30350n / inventree_part_import

CLI to import parts from suppliers like DigiKey, LCSC, Mouser, etc. to InvenTree
MIT License
24 stars 8 forks source link

Feature Request: Allow the part column name to be specified on cli/config to avoid prompting during multi-column file import #41

Closed cmidgley closed 2 months ago

cmidgley commented 2 months ago

Background and use case

I am working on automating the workflow from my electronics design software to Inventree, including importing new parts. I currently export a single multi-column file which is used for part creation with inventree_part_import and for BOM import into Inventree. When using inventree_part_import -i false somefile.csv the user is required to manually select which column to use for the import, halting the automated process.

This feature request is to be able to specify the column name in advance of import to avoid the prompt.

User experience options

1) Add a CLI option that specifies the column name, such as --import-column my-column-name.
2) Add a config.yaml option that specifies the column name.
This may be too rigid, as importing a file using a different column name would require editing the config file. 3) A combination, where the config file specifies the default, but the CLI can override it including some syntax such as --import-column false or --import-column default to ignore it. While the most flexible approach, it feels like overkill for a low-use feature.

My recommendation is option 1. I'm willing to do a pull-request if approved.

30350n commented 2 months ago

Currently columns named "Manufacturer Part Number" or "MPN" will already be picked up automatically: https://github.com/30350n/inventree_part_import/blob/2686113ea643e6ba14b68f758dfbb52ed9e6587b/inventree_part_import/cli.py#L257

What do you use in your BOM files? If it seems reasonable enough, we could simply add it to that list. Otherwise I think I'd prefer exposing this as a config option (2.).

This may be too rigid, as importing a file using a different column name would require editing the config file.

This wouldn't be a problem in this case, as you could add multiple column names.

cmidgley commented 2 months ago

Didn't know about that capability with multiple pre-named header columns - very helpful.

I use the same column headers as InvenTree BOM, which include part_id and part_ipn. In the current implementation, it might make sense to add part_id to that list for compatibility, but that wouldn't address my issue.

As we've been discussing (#38), I use IPN which means the field I care about is part_ipn (mapping to the standard BOM fields). This is working well with my patched version of inventree_part_import, but it would be inappropriate for it to be in the default list.

Changing MPN_HEADERS to optionally read from config.yaml and default as before sounds like a simple, consistent, and non-disruptive approach. What do you think? Is it worth adding, or too limited a use case to be worth the code maintenance?

30350n commented 2 months ago

Optional config parameters are super simple to add, that's why I generally prefer them to extra CLI options ^^

There's a new auto_detect_columns configuration option now (standard yaml list).

cmidgley commented 2 months ago

Wonderful. Confirmed working with both the new default with part_id as well as the ability to override it with config.yaml.

30350n commented 2 months ago

Perfect, thanks for confirming ^^