Commented out sendmail parts for testing. Added SentInvoice table that tracks when invoices were sent. Added InvoiceID and InvoiceSent columns to Invoice table. Now tracks which invoices haven't been sent and only sends those. Once hte invoice has been sent it marks it has having been sent in the database and adds the date to the SentInvoice table. Started adding parts to allow xlsx filent not to be hardcoded. Updated TableSetup using the PyCharm autogeneric SQL thing.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from openpyxl import load_workbook
|
||||
from sqlalchemy import create_engine, Column, Integer, String, REAL
|
||||
from sqlalchemy import create_engine, Column, Integer, String, REAL, Boolean
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
||||
engine = create_engine('sqlite:///cffInvoice.db')
|
||||
engine.connect()
|
||||
Base = declarative_base()
|
||||
@@ -10,7 +11,7 @@ Base = declarative_base()
|
||||
|
||||
class Invoice(Base):
|
||||
__tablename__ = 'Invoice'
|
||||
rowid = Column(Integer, primary_key=True, autoincrement=True)
|
||||
rowid = Column(Integer)
|
||||
OrderID = Column(String)
|
||||
InvoiceNumber = Column(String)
|
||||
DateCreated = Column(String)
|
||||
@@ -31,6 +32,8 @@ class Invoice(Base):
|
||||
ShippingCity = Column(String)
|
||||
ShippingState = Column(String)
|
||||
ShippingPostalCode = Column(String)
|
||||
InvoiceID = Column(Integer, primary_key=True, autoincrement=True)
|
||||
InvoiceSent = Column(Boolean)
|
||||
|
||||
|
||||
class ItemDetail(Base):
|
||||
@@ -44,17 +47,24 @@ class ItemDetail(Base):
|
||||
ItemPrice = Column(REAL)
|
||||
|
||||
|
||||
class SentInvoices(Base):
|
||||
__tablename__ = 'SentInvoices'
|
||||
rowid = Column(Integer, primary_key=True, autoincrement=True)
|
||||
InvoiceID = Column(Integer)
|
||||
SentDate = Column(String)
|
||||
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
|
||||
|
||||
def load_sheet(invoiceNumber):
|
||||
def load_sheet(invoiceNumber, fileName):
|
||||
|
||||
# starting invoice sub-number
|
||||
count = 2
|
||||
|
||||
#open the xlsx file from accounting and name the two sheets required
|
||||
wb = load_workbook('1.xlsx', data_only=True)
|
||||
wb = load_workbook(fileName, data_only=True)
|
||||
shtInvoice = wb.get_sheet_by_name('Invoice')
|
||||
shtItemDetail = wb.get_sheet_by_name('Item Detail')
|
||||
|
||||
@@ -81,7 +91,7 @@ def load_sheet(invoiceNumber):
|
||||
def just_work():
|
||||
#array of orderIDs
|
||||
orders = []
|
||||
for order in session.query(Invoice).all():
|
||||
for order in session.query(Invoice).filter(Invoice.InvoiceSent == 0).all():
|
||||
orders.append(order.OrderID)
|
||||
return orders
|
||||
|
||||
@@ -108,6 +118,7 @@ def record_lookup(record):
|
||||
result.append(lookup.ShippingPostalCode)
|
||||
result.append(lookup.ShippingCharges)
|
||||
result.append(lookup.DuePayment)
|
||||
result.append(lookup.InvoiceID)
|
||||
return result
|
||||
|
||||
|
||||
@@ -126,3 +137,10 @@ def item_lookup(item):
|
||||
result.append(lookup.ProductName)
|
||||
result.append(lookup.ItemPrice)
|
||||
return result
|
||||
|
||||
|
||||
def mark_sent(InvoiceID, InvoiceDate):
|
||||
session.add(SentInvoices(InvoiceID=InvoiceID, SentDate=InvoiceDate))
|
||||
session.query(Invoice).filter(Invoice.InvoiceID == InvoiceID).update({Invoice.InvoiceSent: 1})
|
||||
session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user