Python Class: Store Management System
Classified in Computers
Written at on English with a size of 4.38 KB.
Python Store Management System
This code defines a Store
class in Python, designed to manage customers, sellers, and orders. It uses basic object-oriented principles and data structures.
Class Definition
from Problema2.Cliente import Cliente from Problema2.Vendedor import Vendedor class Tienda(): def __init__(self): self.__personas = [] self.__pedidos = [] def altaCliente(self, Cliente): alta = False if Cliente in self.__personas: alta = False else: self.__personas.append(Cliente) alta = True return alta def altaVendedor(self, Vendedor): alta = False if Vendedor in self.__personas: alta = False else: self.__personas.append(Vendedor) alta = True return alta def altaPedido(self, Pedido): alta = False if Pedido in self.__pedidos: alta = False else: self.__pedidos.append(Pedido) alta = True return alta def numClientes(self): contador = 0 i = 0 while i < len(self.__personas): if self.__personas[i] == Cliente: contador = contador + 1 i = i + 1 return contador def numVendedores(self): contador = 0 i = 0 while i < len(self.__personas): if self.__personas[i] == Vendedor: contador = contador + 1 i = i + 1 return contador def numPedidos(self): return len(self.__pedidos) def importeTotalPedidos(self): total = 0.0 i = 0 while i < len(self.__pedidos): total = total + self.__pedidos[i].total i = i + 1 return total def listadoClientes(self): lista = "" i = 0 while(i < len(self.__personas)): if(isinstance(Cliente, self.__personas[i])): lista = lista + self.__personas[i].__str__ + " " i = i + 1 return lista def listadoVendedores(self): lista = "" i = 0 while(i < len(self.__personas)): if(isinstance(self.__personas[i], Vendedor)): lista = lista + self.__personas[i].__str__ + " " i = i + 1 return lista def listadoPedidosFecha(self, fecha): listado = "" i = 0 while i < len(self.__pedidos): if fecha == self.__pedidos[i].fechaPedido: listado += self.__pedidos[i].__str__ + " " i = i + 1 return listado
Methods
__init__
: Initializes the store with empty lists for people (__personas
) and orders (__pedidos
).altaCliente
: Adds a customer (Cliente
) to the store. ReturnsTrue
if successful,False
if the customer already exists.altaVendedor
: Adds a seller (Vendedor
) to the store. ReturnsTrue
if successful,False
if the seller already exists.altaPedido
: Adds an order (Pedido
) to the store. ReturnsTrue
if successful,False
if the order already exists.numClientes
: Returns the number of customers in the store.numVendedores
: Returns the number of sellers in the store.numPedidos
: Returns the number of orders in the store.importeTotalPedidos
: Returns the total amount of all orders.listadoClientes
: Returns a string listing all customers.listadoVendedores
: Returns a string listing all sellers.listadoPedidosFecha
: Returns a string listing all orders for a given date.
Key Improvements
- Corrected Spelling and Grammar: Fixed minor errors in the original text.
- Clearer Headings: Used appropriate heading levels (h2, h3) for better structure.
- Formatted Code: Presented the code within a
<pre>
tag for better readability. - Added Bold and Italics: Used
<code>
,<ul>
, and<li>
tags for emphasis and list structure.