Beispiel #1
0
 def remove_purchases(self,item_name:str,date_time:str,amount:int,
 on_account:on_account_records,liquid_aced:liquid_aced_records,inventory:inventory_records):
     #search record by using item name date time as a primary key
     record = self.search_by_name_and_date_time(item_name,date_time)
     # verify if record exist or not
     if record:
         # verify the amount that is going to be returned 
         if record['amount'] >= amount:
             # calculate the total price of purchase return
             purchase_price = amount*record['unit_price']  
             # minus sign indicate that this amount is removed from the purchases          
             amount = -1*amount
             # date and time of the moment of purchase return recorded
             dat = datetime.now()
             date_time = f"{dat.year}-{dat.month}-{dat.day} {dat.hour}:{dat.minute}:{dat.second}"
             # add amount to the aced account which use to buy the purchases
             liquid_aced.purchase_return_on_account(record['account_name'],purchase_price,on_account)
             # remove stock from the inventory it also validate amount weather it can be return
             # or not
             inventory.remove_stock(item_name,record['unit_price'],-1*amount)
             # store record in purchase model or in it self
             self.add_record(item_name,amount,purchase_price,
             record['unit_price'],date_time,record['account_name'])
         else:    
             raise shope_managment_system_exception(amount+" this number of products cannot be removed  ")
     else:
         raise shope_managment_system_exception(" product with "+item_name+" and date time "+date_time+" not exist")        
Beispiel #2
0
 def remove_liquid_aced(self,account_name:str,amount:int):
     # search the record if exist than validate the value than subract the amount from
     # account in such a way result would be zero else give error i
     record = self.search_by_name(account_name)
     if record != {}:
         price = record['amount'] - amount
         if price >= 0:
             record['amount'] -= amount
             return True
         raise shope_managment_system_exception(" account can not support  "+amount+" to spend ")
     raise shope_managment_system_exception(" liquid aced account name "+account_name+" not exist ")                
Beispiel #3
0
 def verify_files(self, path):
     lis = os.listdir(path)
     if lis == []:
         for files_name in load_and_store_models.sub_files:
             open(os.path.join(path, files_name), 'w').close()
     elif len(lis) == len(load_and_store_models.sub_files):
         for file_name in load_and_store_models.sub_files:
             if not lis.__contains__(file_name):
                 raise shope_managment_system_exception(
                     " invalid files in " + path)
     else:
         raise shope_managment_system_exception(" invalid files in " + path)
 def remove_stock(self, item_name: str, unit_price: int, amount: int):
     # remove stock for purchase model only
     # find the item name and unit price if amount is greater than substract the amount
     # from the inventory
     # else raise error
     for record in self.inventory:
         if record['name'] == item_name and record[
                 'unit_price'] == unit_price:
             if record['amount'] >= amount:
                 record['amount'] -= amount
             else:
                 raise shope_managment_system_exception(" product with " +
                                                        item_name +
                                                        " and price " +
                                                        unit_price +
                                                        " not exist")
             return True
     raise shope_managment_system_exception(
         " item_name or unit_price not match ")
Beispiel #5
0
 def search_by_name_and_date_time(self,item_name:str,date_time:str):
     try:
         dat = datetime.strptime(date_time,"%Y-%m-%d %H:%M:%S")
         dat = f"{dat.year}-{dat.month}-{dat.day} {dat.hour}:{dat.minute}:{dat.second}"
         for record in self.purchases:
             if record['date'] == dat and record['name'] == item_name:
                return record
         return None       
     except Exception:
         raise shope_managment_system_exception(" invalid date time it should be yyyy-mm-dd hh:mm:ss ")    
Beispiel #6
0
 def payed_payment(self, account_name, payed, liquid_aced):
     # this method settle account by adding the amount in accounts payed amount
     # the result must not excced have_to_pay amount if that account not exist than
     # throw an error
     record = self.search_by_name(account_name)
     if record != {}:
         price = record['payed']
         price += payed
         if price <= record['have_to_pay']:
             self.recover_to_aced_and_liability(liquid_aced, account_name,
                                                payed)
             record['payed'] += payed
         else:
             raise shope_managment_system_exception(
                 " account " + account_name + " did not owe  " + price +
                 " but it accually owe " + record['have_to_pay'])
     else:
         raise shope_managment_system_exception("account with name " +
                                                account_name +
                                                " doesnot exist ")
Beispiel #7
0
 def search_by_name(self, item_name: str,
                    inventory_data: inventory_records):
     records = []
     try:
         for record in self.sales:
             if inventory_data.search_by_id(
                     record['id'])['name'] == item_name:
                 records.append(record)
         return records
     except Exception:
         raise shope_managment_system_exception(
             " data might be corrupted cannot relate sales with inventory ")
Beispiel #8
0
 def search_all(self, inventory_data: inventory_records):
     records = []
     temp: dict
     try:
         for record in self.sales:
             temp = record.copy()
             temp['name'] = inventory_data.search_by_id(
                 record['id'])['name']
             records.append(temp)
         return records
     except Exception:
         raise shope_managment_system_exception(
             " data might be corrupted cannot relate sales with inventory ")
Beispiel #9
0
 def sale_return_on_account(self,account_name:str,amount:int,on_account:on_account_records):
     # remove amount from the aced account in case of sales return if account not exist than
     # settle the loan if exist than the resulting value must be >= 0
     if account_name != self.ignore_account_name:
         record = self.search_by_name(account_name)
         if record == {}:
             on_account.payed_payment(account_name,amount,self)
         else:
             price = record['amount'] - amount
             if price >= 0:
                 record['amount'] = price 
             else:
                 raise shope_managment_system_exception(" account  "+account_name," dosnot have enough credit to support the transection")    
 def sale_stock(self, item_name: str, unit_price: str, amount: int):
     # deals with sales in inventory used by sale model only
     # search the inventory with item name and unit price
     # if record exist than check its type if type is nonrenewable which is 1
     # than remove the amount from the inventory by ensuring that the result >= 0
     # else raise respactive error
     record = self.search_by_name_and_unit_price(item_name, unit_price)
     if record != {}:
         if inventory_records.types[
                 record['type']] == inventory_records.types[
                     1] and record['amount'] >= amount:
             record['amount'] -= amount
             return record
         elif inventory_records.types[
                 record['type']] == inventory_records.types[0]:
             return record
         else:
             raise shope_managment_system_exception(
                 " not enough product for sale for item " + record['name'])
     else:
         raise shope_managment_system_exception(" product  " +
                                                record['name'] +
                                                " does not exist ")
Beispiel #11
0
 def purchase_on_account(self,account_name:str,amount:int,on_account:on_account_records):
     # used by purchase model it remove the amount used by an account for purchasing 
     # if that account does not exist than it make this account a liability or loan
     if account_name != self.ignore_account_name:
         record = self.search_by_name(account_name)
         if record == {}:
             on_account.add_account_loan(account_name,amount,self)
         else:
             price = record['amount'] - amount
             # if account exist but result if smaller than zero than it give error
             if price >= 0:
                 record['amount'] = price 
             else:
                 raise shope_managment_system_exception(" account  "+account_name," dosnot have enough credit to support the transection")    
Beispiel #12
0
 def remove_expance(self, expance_name: str, date_time: str, amount: int,
                    liquid_aced: liquid_aced_records):
     # find the expance with name ,
     # add the amount to the liquid aced amount which is responsible for this expance
     #  and record the amount with negative value in it
     record = self.search_by_name_and_date_time(expance_name, date_time)
     if record:
         if record['amount'] >= amount:
             amount = -1 * amount
             dat = datetime.now()
             date_time = f"{dat.year}-{dat.month}-{dat.day} {dat.hour}:{dat.minute}:{dat.second}"
             liquid_aced.add_liquid_aced(record['account_name'],
                                         -1 * amount)
             self.add_record(expance_name, amount, date_time,
                             record['account_name'])
         else:
             raise shope_managment_system_exception(
                 amount + " this number of products cannot be removed  ")
     else:
         raise shope_managment_system_exception(" product with " +
                                                expance_name +
                                                " and date time " +
                                                date_time + " not exist")
Beispiel #13
0
 def search_by_name_and_date_time(self, item_name: str, date_time,
                                  inventory_data: inventory_records):
     try:
         dat = datetime.strptime(date_time, "%Y-%m-%d %H:%M:%S")
         dat = f"{dat.year}-{dat.month}-{dat.day} {dat.hour}:{dat.minute}:{dat.second}"
         for sales_record in self.sales:
             if sales_record[
                     'date'] == date_time and inventory_data.search_by_id(
                         sales_record['id'])['name'] == item_name:
                 return sales_record
         return None
     except Exception:
         raise shope_managment_system_exception(
             " invalid date time it should be yyyy-mm-dd hh:mm:ss or inventory id "
         )
Beispiel #14
0
 def remove_sales(self,
                  item_name: str,
                  date_time: str,
                  amount: int,
                  inventory_data: inventory_records,
                  on_account: on_account_records,
                  liquid_aced: liquid_aced_records,
                  add_in_inventory=True):
     # search record by date time and its name as a primary key
     # remove the amount from which whole sale of that product is added
     # add the product in inventory if needed by using sales return method
     # and finally add the record in it self by with new whole sale price, and -ve amount
     record = self.search_by_name_and_date_time(item_name, date_time,
                                                inventory_data)
     account_name = record['account_name']
     if record:
         if record['amount'] >= amount:
             whole_sale_price = amount * record['unit_sale_price']
             amount = -1 * amount
             dat = datetime.now()
             date_time = f"{dat.year}-{dat.month}-{dat.day} {dat.hour}:{dat.minute}:{dat.second}"
             inventory_data.add_sale_return(record['id'], -1 * amount)
             liquid_aced.sale_return_on_account(account_name,
                                                whole_sale_price,
                                                on_account)
             self.add_record(record['id'], date_time, whole_sale_price,
                             record['unit_sale_price'], amount,
                             account_name)
         else:
             raise shope_managment_system_exception(
                 amount + " this number of products cannot be removed  ")
     else:
         raise shope_managment_system_exception(" product with " +
                                                item_name +
                                                " and date time " +
                                                date_time + " not exist")
Beispiel #15
0
 def add_purchase(self,account_name:str,item_name:str,amount:int,purchase_price:int,type_of_sale:int,
 on_account:on_account_records,liquid_aced:liquid_aced_records,inventory:inventory_records):
     if len(inventory.types) > type_of_sale:
         #calculating unit price of a product that is beign purchase
         unit_price = purchase_price/amount
         # date on which this purchase is recorded
         dat = datetime.now()
         # format of date
         date_time = f"{dat.year}-{dat.month}-{dat.day} {dat.hour}:{dat.minute}:{dat.second}"
         # remove price from the liquid_aced account which is used to buy these purchases
         liquid_aced.purchase_on_account(account_name,purchase_price,on_account)
         # store record in it self
         self.add_record(item_name,amount,purchase_price,unit_price,date_time,account_name)
         # add purchases in inventory stock
         inventory.add_stock(unit_price,item_name,amount,type_of_sale)
     else:
         raise shope_managment_system_exception(" type number is invalid ")