Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from collections import Counter
- class Supplier:
- def __init__(self, name, address, email, contact_no):
- self.name = name
- self.address = address
- self.email = email
- self.contact_no = contact_no
- class Product:
- def __init__(self, name):
- self.name = name
- class Company():
- data_dict = []
- def purchase(self, product_obj, qty, price, date=datetime.date.today()):
- self.data_dict.append({'product': product_obj.name, 'qty': qty, 'price': price, 'date': str(date)})
- def sale(self, sell_qty, sell_date=datetime.date.today()):
- a = 0
- p = 0
- unit_val = 0
- new_price = 0
- newdict = (sorted(self.data_dict, key=lambda x: x['date']))
- for dt in newdict:
- a += dt['qty']
- p += dt['price']
- if sell_date > dt['date']:
- if sell_qty <= a:
- unit_val = float(p / a)
- new_price = unit_val * a
- a -= sell_qty
- self.data_dict.append({'product': product_obj.name, 'qty': a, 'price': new_price, 'date': str(sell_date)})
- print("sold!")
- else:
- print("Sorry, not enough qty.\n")
- def __str__(self):
- report = []
- for entry in self.data_dict:
- report.append(f"{entry['product']:12} | {entry['qty']:4} | {entry['price']:6.2f} | {entry['date']:8}")
- return "\n".join(report)
- company = Company()
- product = Product('Computer')
- MENU = '''
- 1. Add stock of the product
- 2. Sell stock of the product
- R. Report
- X. eXit
- '''
- while True:
- option = input(MENU).lower()
- if option == "1":
- qty = int(input("Enter the qty of the product.\n"))
- price = float(input("Enter the price of the product.\n"))
- purchase_date = input("Enter purchase date.\n")
- company.purchase(product, qty, price, purchase_date)
- elif option == "2":
- qty = int(input("Enter the qty you wanna sell, pal!"))
- sale_date = input("Enter sell date.\n")
- company.sale(qty)
- elif option == "r":
- print(company)
- 1
- elif option == "x":
- break
- else:
- print("Sorry. Don't know that option.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement