2

How I developed a fully functional Purchasing Application using Python

 2 years ago
source link: https://towardsdatascience.com/how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How I developed a fully functional Purchasing Application using Python

Purchase Order entry, send it to your supplier, and receive the product in your warehouse

Photo by Christiann Koepke on Unsplash

Python is the most famous language when it comes to data: right from data integration to analysis to prediction. Considering it is open source, there are developers developing new libraries, bringing in new capabilities. One such capability is developing new applications.

In this article, I will explain how I developed a fully functional purchasing application using Python.

Before we delve into application development components, let’s understand the overall flow of purchasing process.

  1. Your company enters the purchase order
  2. It sends the purchase order to the company’s supplier. A copy of the same purchase order is sent to your company’s warehouse.
  3. The supplier ships the goods to the company’s warehouse. The warehouse receives the goods against the purchase order they got in the above step.
1*ph7O7fWQv3-1G8OBlWHyNw.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a
Image: Purchasing process flow

At the minimum, the purchasing application needs the below components:

  • Purchasing application for entering new purchase orders and inquiring about existing purchase orders.
  • Purchase order report that is sent to supplier and warehouse

Application Development

When it comes to developing python applications, there are numerous libraries and frameworks available. The below image shows the list of python frameworks available based on the kind of applications.

1*iPvfc_yeRKgPZkPgtGs12A.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a
Python Libraries and Framework for application development

If you are new to Python, I suggest using the Tkinter framework. It’s easy to use and just what you need to develop a desktop application. I have used it for developing the purchasing application.

My purchasing application has a screen with three tabs

  1. PO Enquiry: Enquire existing purchase orders in this tab. Enter any of these below field values and get matching PO details on the same screen.
  • Purchase Order Number (PO#)
  • Supplier Number (Supplier#)
  • PO Date
  • Supplier Name
1*md7GYkCIpswNiifM9nSNqg.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a
PO Enquire Screen (Image by author)

2. PO Header: Enter purchase order header details in this tab. Purchase order header details contain the below fields.

  • Purchase order number (PO#)
  • Purchase order date (PO Date)
  • Supplier Number (Supplier#)
  • Supplier Name
  • Delivery address details
  • Supplier address details
1*fn5kg77zTEkNqPOFF5Greg.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a
PO Header Screen (Image by author)

3. PO Line: Enter purchase order line details. The purchase order line contains the below details.

  • Quantity
  • Unit Price
  • Amount

and other details.

Let’s go through the code for developing this screen with the tabs.

The below code snippet contains Python code for developing the PO inquiry screen.

Let’s understand the code.

The below lines are importing required libraries from the Tkinter framework.

1*fSLU7N6qRktq7zZfriTzzA.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

I am developing this application on the Oracle database. The below line of codes connects the application with the Oracle database.

1*22lpi-pWr95SLmfagT8xcg.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Refer to the below article if you want to know more about connecting the python applications with the Oracle database.

The below line of code creates a window with Title “PO Application” and creates three tabs on this window: PO Enquiry, PO Header, PO Line

1*siDKD9nDscQ5HnzMJzhzaA.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

The below line of code adds PO#, PO Date, Supplier#, Supplier Name fields to the PO Enquiry tab.

1*AKNYk0OvfO7CY5PJWv5bBg.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Add window.mainloop() to show your window.

1*7SOiHxU3-xzrxazms7s9ow.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Get the complete code from the Github location mentioned in the reference list.

Report Development

Python provides reportlab for developing picture-perfect professional reports. Below is an image of the purchase order report developed using the reportlab library.

1*8BJTthOqhEm05sCR7iCr_A.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a
Purchase Order Report (Image by author)

The below code snippet shows the code behind this report.

Let’s understand the code for developing the report.

The first few lines of code are importing the reportlab libraries and cx_Oracle for connection with the database.

1*CXwBU5Phro4XRKtmsXLOVA.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Here, connect to the Oracle database and open two cursors: one with purchase order header information and the other with purchase order line details.

1*Kd8Bn43G_z5RBrGz8wEfMA.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Next, create a variable logo and assign the path where the logo image is stored on your computer.

1*5jEbuxaPOZKZtoykQ01x9Q.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Now open a loop with purchase order header information. SimpleDocTemplate is called with the report file name (podocname+.pdf ) and the size of the report with margin details. In my case, the report file name is made of supplier number — purchase order number- the date when the report was created.

The last line in the below code snippet opens an empty array Story.

1*ucSvYGviacbES5GnrBS9lg.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Report data will be added to this empty array and this empty array will be added to the report as a paragraph.

Below lines of code add the log to the top right side of the report.

1*O-mF9ZnoyxD6ofH0wh6iJA.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

The below lines of code creates an array with the delivery address details and then add that array data to the Story array.

1*2Q5rP-HnYwfHd2G24L-p7w.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Likewise, the below line of codes adds PO line details to polintab array.

1*_Drhz8e9NvDPNz3GoT1Zaw.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

The below lines of code create a table on the report with polintab array data.

Note: Unlike python NumPy array, reportlab tab starts with columns and then rows. So, ‘ALIGN’,(3,0),(5,-1), ‘RIGHT’ indicates right align data from columns 3rd to 5th.

1*EWuu6pC59vJefbs9_z4_RQ.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Finally, the below line of codes adds the polintab table to the Story array and shows that table on the report. doc.build(Story) builds the report with Story array data.

1*3WgfGbV7zl24jL0WAUGY5A.png?q=20
how-i-developed-a-fully-functional-purchasing-application-using-python-282e4b18114a

Conclusion

It’s been fun developing applications and the report on the Oracle database using Python. Python is a language with limitless possibilities and we are on a journey to explore these potentials.

Although this article shows how to develop purchasing applications, the steps can be used to develop any kind of application on a database using Python.

Looking forward to your feedback!

Reference

https://www.reportlab.com/docs/reportlab-userguide.pdf

Python+SQL+Oracle and endless possibilities


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK