From da8b17d99843337444994fb6a933218f16d44187 Mon Sep 17 00:00:00 2001 From: Severin Leonhardt Date: Wed, 9 Jun 2021 09:56:12 +0200 Subject: [PATCH 1/2] Create storage location when it doesn't exist The method `getorCreateLocation` was only looking for existing storage locations with a matching name but never created one. This leads to the following error if a storage location doesn't exist yet: Traceback (most recent call last): File "migratePKCategories.py", line 132, in 'location' : itloc.pk AttributeError: 'int' object has no attribute 'pk' With this change the storage location is created if it doesn't exist yet in InventTree. --- migratePKCategories.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migratePKCategories.py b/migratePKCategories.py index e246afb..6f0a94b 100644 --- a/migratePKCategories.py +++ b/migratePKCategories.py @@ -91,7 +91,10 @@ def getorCreateLocation(part): for loc in itloca: if (loc.name == part.storageLocation): return loc - return 0 + return StockLocation.create(api, { + 'name': part.storageLocation, + 'parent': "" + }) else: #create or return unknownloadtion From 0d8cba6e679044c64b387f08fe6dd4d733c1b094 Mon Sep 17 00:00:00 2001 From: Severin Leonhardt Date: Wed, 9 Jun 2021 09:59:58 +0200 Subject: [PATCH 2/2] Migrate comments The comment of a part in PartKeepr will become the notes of that part in InvenTree. --- migratePKCategories.py | 1 + partkeepr.py | 1 + 2 files changed, 2 insertions(+) diff --git a/migratePKCategories.py b/migratePKCategories.py index 6f0a94b..01e1014 100644 --- a/migratePKCategories.py +++ b/migratePKCategories.py @@ -110,6 +110,7 @@ def createITPart(part,ITCat): np = Part.create(api, { 'name' : part.name, 'description' : part.description, + 'notes' : part.comment, 'category' : ITCat.pk, 'active' : True, 'virtual' : False, diff --git a/partkeepr.py b/partkeepr.py index 107a0f4..043fb9a 100644 --- a/partkeepr.py +++ b/partkeepr.py @@ -15,6 +15,7 @@ def __init__(self,req): #print (req["name"]) self.name = req["name"] self.description = req["description"] + self.comment = req["comment"] self.id = req["@id"][req["@id"].rfind("/")+1:] try: self.footprint = req["footprint"]["name"]