Python code for Delivery Challan: The Material Delivery using the PyCharm IDE.
import datetime
# Define a function to generate a Delivery Challan
def generate_challan(order_id, customer_name, delivery_address, items):
# Create a file to store the Delivery Challan
filename = f"Delivery Challan_{order_id}.txt"
with open(filename, "w") as file:
# Write the header information
file.write(f"Delivery Challan - Order #{order_id}\n")
file.write(f"Customer Name: {customer_name}\n")
file.write(f"Delivery Address: {delivery_address}\n\n")
file.write("Items:\n")
# Write the items and their quantities
for item, quantity in items.items():
file.write(f"{item}: {quantity}\n")
file.write("\n")
# Write the date and time of generation
file.write(f"Generated on: {datetime.datetime.now()}")
return filename
# Define a function to generate a Gatepass
def generate_gatepass(order_id, customer_name, vehicle_number):
# Create a file to store the Gatepass
filename = f"Gatepass_{order_id}.txt"
with open(filename, "w") as file:
# Write the header information
file.write(f"Gatepass - Order #{order_id}\n")
file.write(f"Customer Name: {customer_name}\n")
file.write(f"Vehicle Number: {vehicle_number}\n")
# Write the date and time of generation
file.write(f"Generated on: {datetime.datetime.now()}")
return filename
# Example usage
order_id = 12345
customer_name = "John Smith"
delivery_address = "123 Main St, Anytown, USA"
items = {"Widget": 10, "Gadget": 5, "Thingamajig": 3}
vehicle_number = "ABC-1234"
challan_filename = generate_challan(order_id, customer_name, delivery_address, items)
print(f"Delivery Challan generated: {challan_filename}")
gatepass_filename = generate_gatepass(order_id, customer_name, vehicle_number)
print(f"Gatepass generated: {gatepass_filename}")
This code defines two functions – generate_challan
and generate_gatepass
– which generate the Delivery Challan and Gatepass respectively. The code also includes an example usage, which you can modify to suit your needs.
When you run this code in PyCharm, it will generate two text files – one for the Delivery Challan and one for the Gatepass – in the current directory. The filenames will include the order ID, so you can easily keep track of which files correspond to which orders.
Delivery challan that includes the date and time, order details, customer information, and a list of items being delivered:
import datetime
def generate_challan(order_id, customer_name, delivery_address, items):
# Create a file to store the Delivery Challan
filename = f"Delivery Challan_{order_id}.txt"
with open(filename, "w") as file:
# Write the header information
file.write(f"Delivery Challan - Order #{order_id}\n")
file.write(f"Date: {datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S')}\n\n")
# Write the order details
file.write("Order Details:\n")
file.write(f"Customer Name: {customer_name}\n")
file.write(f"Delivery Address: {delivery_address}\n\n")
# Write the items and their quantities
file.write("Items:\n")
for item, quantity in items.items():
file.write(f"{item}: {quantity}\n")
return filename
This code will generate a text file with the name “Delivery Challan_[order_id].txt”, where [order_id] is the actual order ID passed as a parameter to the generate_challan
function.
To use the function, you can call it with the order details and a dictionary of items and their quantities:
order_id = 12345
customer_name = "John Smith"
delivery_address = "123 Main St, Anytown, USA"
items = {"Widget": 10, "Gadget": 5, "Thingamajig": 3}
challan_filename = generate_challan(order_id, customer_name, delivery_address, items)
print(f"Delivery Challan generated: {challan_filename}")
When you run this code, it will generate a file named “Delivery Challan_12345.txt” (assuming the order ID is 12345) in the same directory as your Python script. The file will contain the order details, customer information, and list of items with their quantities.
Scope of accounting and finance: The fields of accounting and finance are pivotal to the…
Top Programming Languages in 2024: Staying ahead in the ever-evolving field of programming requires keeping…
Top Nihari Restaurants in Karachi, the bustling metropolis of Pakistan, is a food lover's paradise.…
Advancing Your Skills: Welcome back, Python programmers! Now that you've grasped the fundamental building blocks…
Building the Foundation: Welcome back, aspiring Python programmers! In the previous chapter, we explored the…
Chapter 1: Dive into Python: Welcome, aspiring programmers! Have you ever felt the thrill of…
This website uses cookies.