Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions sprint_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
class OnlineSalesRegisterCollector:

def __init__(self):
self.__name_items = []
self.__number_items = 0
self.__item_price = {'чипсы': 50, 'кола': 100, 'печенье': 45, 'молоко': 55, 'кефир': 70}
self.__tax_rate = {'чипсы': 20, 'кола': 20, 'печенье': 20, 'молоко': 10, 'кефир': 10}

@property
def get_name_items(self):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно лучше: название пропертей стоит давать по названию атрибута

return self.__name_items

@property
def get_number_items(self):
return self.__number_items

def add_item_to_cheque(self, name):
if len(name) != 0 or len(name) < 40:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: условие составлено не верно

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Коммент необходимо описать более развернуто, указать, что именно мы получим при такой реализации условия, а что мы должны быти получить по заданию, чтобы дать студенту направление мысли для исправления

raise ValueError('Нельзя добавить товар, если в его названии нет символов или их больше 40')
else:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: отсутствует проверка наличия товара в справочнике

self.__name_items.append(name)
self.__number_items += 1

def delete_item_from_check(self, name):
if name in self.__name_items:
self.__name_items.remove(name)
self.__number_items -= 1
else:
raise NameError('Позиция отсутствует в чеке')

def check_amount(self):
total = []
for i in range(len(self.__name_items)):
if self.__name_items[i] in self.__item_price:
total.append(self.__item_price.get(self.__name_items[i]))
if len(self.__name_items) > 10:
return sum(total) - (sum(total) * 10) / 100
else:
return sum(total) * 0.9

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: в данном случае должна возвращаться полная стоимость товаров


def twenty_percent_tax_calculation(self):
twenty_percent_tax = []
for i in range(0, len(self.__name_items)):
if self.__name_items[i] in self.__tax_rate:
if self.__tax_rate.get(self.__name_items[i]) == 20:
twenty_percent_tax.append(self.__name_items[i])
total = []
for i in range(0, len(twenty_percent_tax)):
if twenty_percent_tax[i] in self.__item_price:
total.append(self.__item_price.get(twenty_percent_tax[i]))
if len(twenty_percent_tax) > 10:
return (sum(total) - (sum(total) * 10) / 100)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отсутствует коммент: Нужно исправить: применена формула для расчета 10% ндс а не 20 по методу

else:
return sum(total)
Comment on lines +51 to +54

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: не верная формула расчета НДС. Рассчитана полная стоимость всех позиций


def ten_percent_tax_calculation(self):
ten_percent_tax = []
for i in range(0, len(self.__name_items)):
if self.__name_items[i] in self.__tax_rate:
if self.__tax_rate.get(self.__name_items[i]) == 20:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: неверное условие фильтрации

ten_percent_tax.append(self.__name_items[i])
total = []
for i in range(0, len(ten_percent_tax)):
if ten_percent_tax[i] in self.__item_price:
total.append(self.__item_price.get(ten_percent_tax[i]))
if len(ten_percent_tax) > 10:
return (sum(total) - (sum(total) * 10) / 100)
else:
return sum(total)
Comment on lines +66 to +69

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: не верная формула расчета НДС. Рассчитана полная стоимость всех позиций


def total_tax(self):
return OnlineSalesRegisterCollector.ten_percent_tax_calculation() + OnlineSalesRegisterCollector.twenty_percent_tax_calculation()

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: для вызова данных методов необходимо создать экземпляр класса, а раз вызов происходит внутри класса, то вызов должен происходить через self

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Коммент дает студенту вариативность написания, что является неверным. Создавать экземпляр класса внутри методов этого же класса нельзя, корректным будет только обращение через self


@staticmethod
def get_telephone_number(telephone_number):
if len(str(telephone_number)) > 10:
raise ValueError('Необходимо ввести 10 цифр после "+7"')
try:
float(telephone_number)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: необходимо проверять является ли введенное значение целочисленным. Лучше всего для этого подойдет функция isinstance

except ValueError:
raise ValueError('Необходимо ввести цифры') from None
return f'+7{telephone_number}'