partsdb

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

commit fb44abb7ea0f08be4c7cfe0227cada9a70fb3a0c
parent ade9fb918b9093dfe6e6ac0abe00e4dab4067565
Author: Paco Esteban <paco@e1e0.net>
Date:   Sun, 14 Mar 2021 11:21:40 +0100

if part exists with the same mpn we update the stock

Diffstat:
Mdatabase.py | 6++++++
MmyChips.py | 10+++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/database.py b/database.py @@ -64,6 +64,7 @@ SEARCH_PARTS_QUERY = """ part_type LIKE '%'||?||'%' GROUP BY p.id """ +GET_PART_BY_MPN_QUERY = "SELECT id FROM parts WHERE mpn = ?" GET_HISTORY_QUERY = "SELECT * FROM parts_history WHERE part_id = ?" INSERT_HISTORY_EVENT = """ INSERT INTO parts_history @@ -116,6 +117,11 @@ class PartsDB(): c.execute(GET_PART_QUERY, (part_id,)) return c.fetchone() + def get_part_by_mpn(self, mpn): + c = self.conn.cursor() + c.execute(GET_PART_BY_MPN_QUERY, (mpn,)) + return c.fetchone() + def search_parts(self, term): c = self.conn.cursor() c.execute(SEARCH_PARTS_QUERY, (term, term, term, term, term)) diff --git a/myChips.py b/myChips.py @@ -30,6 +30,15 @@ def add_part(mpn): pick = int(input("Which one seems better ? ")) p = result[pick]['part'] + quantity = int(input("How many of them ? ")) + + # if this exists we increment stock + spart = db.get_part_by_mpn(p['mpn']) + if spart: + db.update_part_qty(spart['id'], quantity) + db.new_part_history_event(spart['id'], quantity, "new buy") + return + # list categories to choose from for c in db.get_categories(): print(f"{c[0]}) {c[1]}") @@ -40,7 +49,6 @@ def add_part(mpn): print(f"{s[0]}) {s[1]}") storage = int(input("Where will you store it ? ")) - quantity = int(input("How many of them ? ")) smd = input("Is this an SMD part (y/n, default yes) ? ") footprint = None