Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-interactive update should fallback on existing supplier part on multiple resuls #26

Open
sle118 opened this issue Mar 7, 2024 · 0 comments

Comments

@sle118
Copy link

sle118 commented Mar 7, 2024

In the case where we are updating existing products non-interactively and a search returns multiple possible choices, the system update existing entries from the match results. This could be done by getting a list of SKUs for the current supplier from InvenTree and then for each SKU having a match in the search results, update the data.

I have implemented a simple change in my instance that retrieves the first part from the current supplier and matches it against the results list. If no match is found (e.g. the SKU was filtered out upstream due to list truncation), then the process resumes as usual with a warning and skip the import.

            if len(results) == 1:
                api_part = results[0]
            elif self.interactive:
                prompt(f"found multiple parts at {supplier.name}, select which one to import")
                results = results[:get_config()["max_results"]]
                if result_count > len(results):
                    hint(f"found {result_count} results, only showing the first {len(results)}")
                if not (api_part := self.select_api_part(results)):
                    import_result |= ImportResult.INCOMPLETE
                    continue
            else:
                supplier_part = next(iter([mfg_part for mfg_part in existing_part.getSupplierParts() if existing_part and mfg_part.supplier == supplier.pk]),None)
                if supplier_part:
                    api_part = next(iter([p for p in results if p.SKU == supplier_part.SKU]))
                    warning(f"found {result_count} parts at {supplier.name}. Updating with existing SKU {supplier_part.SKU}: ")
                
                if not api_part:
                    warning(f"found {result_count} parts at {supplier_id.name}, skipping import")
                    import_result |= ImportResult.INCOMPLETE
                    continue

The ideal solution here would be to process process each result that has a match with the supplier parts from the InvenTree DB, but I can live with my current solution as I have at most 2 SKUs for a given part right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant