partsdb

electronic parts inventory
git clone https://git.e1e0.net/partsdb.git
Log | Files | Refs | README | LICENSE

commit 5ea47951ce51a03f2753167bfbfc71e4280b1efe
parent d9774f60bdf5db9b0ef676758237e2f36f0393c9
Author: Paco Esteban <paco@e1e0.net>
Date:   Tue, 10 Oct 2023 16:19:48 +0200

PN is now ID in hex

The part numbers of the manufacturers and the ones I invented are hard
to read and difficult to find when looking at dozens of labels in a box.

As I already have a unique identifier (ID), make my PN that.  In order
to not be so boring I put it in hex fixed to 2 bytes, so 4 characters.

I will probably print only that and the datamatrix on the labels from
now on.

Diffstat:
Mpartsdb/database.py | 16++++++----------
Mpartsdb/exports/__init__.py | 2+-
Mpartsdb/exports/templates/cat.html | 2+-
Mpartsdb/exports/templates/part.html | 4++--
Mpartsdb/helpers.py | 15++++++++-------
Mpartsdb/partsdb.py | 1-
Mschema.sql | 1-
7 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/partsdb/database.py b/partsdb/database.py @@ -8,7 +8,7 @@ from sqlite3 import Error GET_CATEGORIES_QUERY = "SELECT id, name FROM categories" GET_STORAGES_QUERY = "SELECT id, name FROM storages" LIST_PARTS_QUERY = """ - SELECT p.id, p.pn, p.manufacturer, p.description, + SELECT p.id, p.mpn, p.manufacturer, p.description, p.footprint, p.quantity, p.part_type, c.name as cname FROM parts as p, categories as c INNER JOIN categories @@ -16,7 +16,7 @@ LIST_PARTS_QUERY = """ GROUP BY p.id """ LIST_PARTS_CATEGORY_QUERY = """ - SELECT p.id, p.pn, p.mpn, p.manufacturer, p.description, + SELECT p.id, p.mpn, p.manufacturer, p.description, p.footprint, p.quantity, p.part_type, c.name as cname FROM parts as p, categories as c INNER JOIN categories @@ -25,7 +25,7 @@ LIST_PARTS_CATEGORY_QUERY = """ GROUP BY p.id """ LIST_PARTS_STORAGE_QUERY = """ - SELECT p.id, p.pn, p.mpn, p.manufacturer, p.description, + SELECT p.id, p.mpn, p.manufacturer, p.description, p.footprint, p.quantity, p.part_type, s.name as sname FROM parts as p, storages as s INNER JOIN categories @@ -36,7 +36,6 @@ LIST_PARTS_STORAGE_QUERY = """ INSERT_PART_QUERY = """ INSERT INTO parts ( - pn, mpn, manufacturer, description, @@ -49,12 +48,11 @@ INSERT_PART_QUERY = """ image, part_type ) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?) + VALUES (?,?,?,?,?,?,?,?,?,?,?) """ UPDATE_PART_QUERY = """ UPDATE parts SET - pn = ?, mpn = ?, manufacturer = ?, description = ?, @@ -95,13 +93,12 @@ GET_PART_QUERY = """ GROUP BY p.id """ SEARCH_PARTS_QUERY = """ - SELECT p.id, p.pn, p.manufacturer, p.description, + SELECT p.id, p.mpn, p.manufacturer, p.description, p.footprint, p.quantity, p.part_type, c.name as cname FROM parts as p, categories as c INNER JOIN categories ON p.category_id = c.id WHERE - pn LIKE '%'||?||'%' OR mpn LIKE '%'||?||'%' OR manufacturer LIKE '%'||?||'%' OR footprint LIKE '%'||?||'%' OR @@ -187,7 +184,7 @@ class PartsDB: def search_parts(self, term): c = self.conn.cursor() - c.execute(SEARCH_PARTS_QUERY, (term, term, term, term, term)) + c.execute(SEARCH_PARTS_QUERY, (term, term, term, term)) return c.fetchall() def get_part_history(self, part_id): @@ -220,7 +217,6 @@ class PartsDB: sto_id = self.get_storage_by_name(part["storage"])["id"] c = self.conn.cursor() update_tuple = ( - part["pn"], part["mpn"], part["manufacturer"], part["description"], diff --git a/partsdb/exports/__init__.py b/partsdb/exports/__init__.py @@ -51,7 +51,7 @@ def _create_excel(data, data_type, filename): workbook = Workbook() sheet = workbook.active - sheet["A1"] = "ID" + sheet["A1"] = "PN/ID" sheet["B1"] = "Name" sheet["C1"] = "URL" a = 2 diff --git a/partsdb/exports/templates/cat.html b/partsdb/exports/templates/cat.html @@ -29,7 +29,7 @@ {% for p in parts %} <tr> <td>{{ p.id }}</td> - <td><a href="part_{{ p.id }}.html">{{ p.pn }}</a></td> + <td><a href="part_{{ p.id }}.html">{{ '%04X' % p.id }}</a></td> <td><a href="part_{{ p.id }}.html">{{ p.mpn }}</a></td> <td>{{ p.manufacturer }}</td> <td>{{ p.description }}</td> diff --git a/partsdb/exports/templates/part.html b/partsdb/exports/templates/part.html @@ -18,8 +18,8 @@ <table> <tbody> <tr> - <td><span class="field">Id:</span> {{ part.id }} ({{ '%04X' % part.id }})</td> - <td><span class="field">PN:</span> {{ part.pn }} / <span class="field">MPN:</span> {{ part.mpn }}</td> + <td><span class="field">Id:</span> {{ part.id }} </td> + <td><span class="field">PN:</span> {{ '%04X' % part.id }} / <span class="field">MPN:</span> {{ part.mpn }}</td> <td><span class="field">Manufacturer:</span> {{ part.manufacturer }}</td> </tr> <tr> diff --git a/partsdb/helpers.py b/partsdb/helpers.py @@ -27,7 +27,7 @@ def _list_ascii(parts): # passed and comparison performed, so we look at the longest desc to # get the lenght of the field. We also check if the header is longer, # the result is whatever is longer - l_pn = len(max(parts, key=lambda k: len(k["pn"]))["pn"]) + l_mpn = len(max(parts, key=lambda k: len(k["mpn"]))["mpn"]) l_cat = len(max(parts, key=lambda k: len(k["cname"]))["cname"]) l_man = len(max(parts, key=lambda k: len(k["manufacturer"]))["manufacturer"]) l_desc = len(max(parts, key=lambda k: len(k["description"]))["description"]) @@ -36,7 +36,8 @@ def _list_ascii(parts): l_desc = l_desc if l_desc > len("Description") else len("Description") header = ( - f"| {'ID':11} | {'PN':{l_pn}} | " + f"| {'ID':5} | {'PN':4} | " + f"{'MPN':{l_mpn}} | " f"{'Category':{l_cat}} | " f"{'Manufacturer':{l_man}} | " f"{'Description':{l_desc}} | " @@ -50,7 +51,8 @@ def _list_ascii(parts): print(header) print("-" * len(header)) print( - f"| {p['id']:<4} ({p['id']:04X}) | {p['pn']:{l_pn}} | " + f"| {p['id']:<5} | {p['id']:04X} | " + f"{p['mpn']:{l_mpn}} | " f"{p['cname']:{l_cat}} | " f"{_sanitize_value(p['manufacturer']):{l_man}} | " f"{_sanitize_value(p['description']):{l_desc}} | " @@ -64,7 +66,7 @@ def _list_ascii_short(parts): header = ( f"| {'ID':4} | " f"{'Category':8} | " - f"{'PN':10} | " + f"{'MPN':10} | " f"{'Manufacturer':16} | " f"{'Description':25} |" ) @@ -76,7 +78,7 @@ def _list_ascii_short(parts): print( f"| {p['id']:<4} | " f"{p['cname'][0:7]:8} | " - f"{_sanitize_value(p['pn'])[0:9]:10} | " + f"{_sanitize_value(p['mpn'])[0:9]:10} | " f"{_sanitize_value(p['manufacturer'])[0:15]:16} | " f"{_sanitize_value(p['description'])[0:24]:25} |" ) @@ -95,8 +97,7 @@ def print_part(p, history, output="full"): def _part_ascii(p, history): - print(f"Part id: {p['id']} ({p['id']:04X})") - print(f"PN: {p['pn']}\tManufacturer: {p['manufacturer']}\tMPN: {p['mpn']}") + print(f"PN: {p['id']:04X}\tMPN: {p['mpn']}\tManufacturer: {p['manufacturer']}") print( f"Category: {p['cat']}\tType: {p['part_type']}" f"\tFootprint: {p['footprint']}" ) diff --git a/partsdb/partsdb.py b/partsdb/partsdb.py @@ -108,7 +108,6 @@ def add_part(mpn, quantity, category, storage, part_type): part = [ p["mpn"], - p["mpn"], p["manufacturer"]["name"], p["short_description"], specs, diff --git a/schema.sql b/schema.sql @@ -13,7 +13,6 @@ CREATE TABLE IF NOT EXISTS storages ( -- parts table CREATE TABLE IF NOT EXISTS parts ( id integer PRIMARY KEY, - pn text NOT NULL, mpn text, manufacturer text, description text,