Skip to content

Commit 17babd6

Browse files
committedFeb 28, 2022
Fixes product, customer inserting
1 parent af088e7 commit 17babd6

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed
 

‎sql/db.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE unit (unit_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, abbreviation TEXT UNIQUE NOT NULL)
22

3-
CREATE TABLE product (product_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, description TEXT, price REAL NOT NULL, cost REAL NOT NULL, quantity REAL NOT NULL, barcode TEXT UNIQUE, unit_id INTEGER NOT NULL, FOREIGN KEY (unit_id) REFERENCES unit(unit_id)) ON DELETE RESTRICT
3+
CREATE TABLE product (product_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, description TEXT, price REAL NOT NULL, cost REAL NOT NULL, quantity REAL NOT NULL, barcode TEXT UNIQUE, unit_id INTEGER NOT NULL, FOREIGN KEY (unit_id) REFERENCES unit(unit_id) ON DELETE RESTRICT)
44

55
CREATE TABLE country (country_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, code TEXT NOT NULL);
66

@@ -34,4 +34,4 @@ CREATE TRIGGER update_product_quantity_after_insert_purchase_product_tg AFTER IN
3434

3535
CREATE TRIGGER update_product_purchase_before_update_sale_product_tg BEFORE UPDATE ON purchase_product WHEN old.quantity <> new.quantity BEGIN UPDATE product SET quantity = quantity + (new.quantity - old.quantity) WHERE product_id = new.product_id; END;
3636

37-
CREATE TRIGGER update_product_quantity_after_delete_purchase_product_tg AFTER DELETE ON purchase_product BEGIN UPDATE product SET quantity = quantity - old.quantity WHERE product_id = old.product_id; END;
37+
CREATE TRIGGER update_product_quantity_after_delete_purchase_product_tg AFTER DELETE ON purchase_product BEGIN UPDATE product SET quantity = quantity - old.quantity WHERE product_id = old.product_id; END;

‎src/countrywidget.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def save(self):
2727
else:
2828
dao.update(Country(self.countryId,
2929
self.nameLineEdit.text()),
30-
self.codeLineEdit.text())
30+
self.codeLineEdit.text())
3131

3232
self.countryUpserted.emit()
33+
self.close()

‎src/dao/productdao.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def select(self, productId):
3434
def insert(self, product):
3535
query = QSqlQuery()
3636
query.prepare("INSERT INTO product (name, description, price,"
37-
"cost, quantity, barcode, unit_id) VALUES (:name,"
38-
":description, :price, :cost, :quantity, :barcode,"
37+
"cost, quantity, barcode, unit_id) VALUES (:name, "
38+
":description, :price, :cost, :quantity, :barcode, "
3939
":unitId)")
4040
query.bindValue(":name", product.name)
4141
query.bindValue(":description", product.description)

‎src/mainwindow.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from PyQt5.QtWidgets import QMainWindow, QMenu, QHeaderView, QMessageBox
44
from PyQt5 import uic, QtCore
5-
from PyQt5.QtCore import QDate, pyqtSlot
5+
from PyQt5.QtCore import QDate
66
from PyQt5.QtSql import QSqlTableModel
77
from src.productwidget import ProductWidget
88
from src.sqlconnection import SqlConnection
@@ -34,10 +34,12 @@ def __init__(self):
3434

3535
def newCustomer(self):
3636
self.customerWidget = CustomerWidget()
37+
self.customerWidget.customerUpserted.connect(self.setUpTableView)
3738
self.customerWidget.show()
3839

3940
def newProduct(self):
4041
self.productWidget = ProductWidget()
42+
self.productWidget.productUpserted.connect(self.setUpTableView)
4143
self.productWidget.show()
4244

4345
def newSale(self):
@@ -133,7 +135,6 @@ def customContextMenuRequestedTableView(self, pos):
133135
def doubleClickedTableView(self, modelIndex):
134136
self.editItem(modelIndex.row())
135137

136-
@pyqtSlot()
137138
def setUpTableView(self):
138139
scrollValue = self.tableView.verticalScrollBar().value()
139140
self.tableModel = QSqlTableModel()

0 commit comments

Comments
 (0)
Please sign in to comment.