Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Produce receipt for customer purchases

receipt purchases customers

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 hyenaa


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 06 April 2015 - 06:54 AM

So the thing is that I want to make a receipt for every customer from a store. The groceries from a store is contained in a file store_sales.txt. Here is a small example of how this file looks:


On each line there is a barcode for a product. Different groceries of different customers are seperated by a '='. 

Most of the barcodes can be translated to a an article with a 'name' and a 'price'. The file that contains this translation is called store_data.txt. Here is an example of this file:

8710002700000 koffie 250 gram      4.98
8710002002733 koffie 500 gram      9.69
8712001063869 thee   100 gram      2.15
8712001171560 thee 20 x 4 gram     2.09

As said most barcodes can be fount in the store_data file but others can not. In that case there should be a statement on the receipt that states this (something like 'article does not exist).

This is what I have coded to do this all:

class Product:
    def __init__ (self,code,naam,prijs):
        self.code = code
        self.naam= naam
        self.prijs = prijs
class Winkel:
    def __init__(self):
        self.product_list= []
    def append_product(self, product):
    def find_product(self,code):
        for product in self.product_list:
            if product.code== code:
                return product
        return None
    def execute_it (self, code):
         product = self.find_product(code)
         if product is None:
             print 'product code %s does not exist.' % code
             return product
    def to_pay(self):    
           resultaat = 0.0
           for product in self.product_list:
               resultaat += product.prijs         
def read_winkel(filenaam):  
    resultaat = Winkel()
    invoerfile = open(filenaam)
    lines = invoerfile.readlines()
    for line in lines:
        product = read_product(line)
    return resultaat          
def read_product(line):
    data= line.split()
    code= str(data[0])
    naam= data[1:-1]
    prijs= float(data[-1])
    return Product(code,naam,prijs)
def verwerk_klant(winkel, filenaam):
    invoer = open(filenaam).read()    
    klanten = invoer.split('=')  
    for klant in klanten:
        verwerk_purchase(winkel, klant)
def verwerk_purchase(winkel, klant):
    resultaat = Winkel()
    lines = klant.splitlines()
    for line in lines:
        product= winkel.execute_it(line)
    return resultaat
def read_line(line):
    code = int(line[0])
    return code '''
def show_purchase(customer_purchase):
    for product in self.product_list:
        print product.prijs
winkel = read_winkel(r'winkel_data.txt')

(winkel means store and klant means customer)

The output should look like this:

****** Bert’s Buurtwinkel ******
artikel prijs
koffie 250 gram 4.98
koffie 250 gram 4.98
thee 100 gram 2.15
bier 24 x 0.33 l 16.95
>>>>>>>>>>> te betalen: 29.06
***** Bedankt en tot ziens *****

However my output is:

product code  bestaat niet.
product code  bestaat niet.
product code 7523423423234 bestaat niet.
product code  bestaat niet.
product code  bestaat niet.
product code  bestaat niet.

It clearly reads only one customer but it does not translate the products at all. I'm only a beginning programmer so my apologies if it looks like a mess. I hope someone here can help me out. I've attached the two files aswell. Thank you for reading.


Attached Files

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download