Я пытаюсь получить доступ к переменной экземпляра self.code в классе Line в классе Quote.Я пытаюсь выполнить следующее правило: при составлении цитаты, содержащей строки 'door_sign' и 'escape_sign', они получают скидку 10% от всей цитаты.
Вот код.
class Client:
def __init__(self, postcode):
self.postcode = postcode
class Line:
def __init__(self, code, unit_cost, quantity=1):
self.code = code
self.unit_cost = unit_cost
self.quantity = quantity
def cost(self):
if self.code == 'door_sign' and self.quantity >=3:
return self.unit_cost * self.quantity * 0.8
else:
return self.unit_cost * self.quantity
class Quote:
def __init__(self, client=None, lines=[]):
self.client = client
self.lines = lines
def cost(self):
**** Вот где моя проблема ****
for l in self.lines:
if line.code == 'door_sign' and 'escape_sign':
return sum([l.cost() * 0.9])
else:
return sum([l.cost()])
print('Rule')
assert Quote(client=Client(postcode=3000), lines=[
Line(code='escape_sign', unit_cost=20.0, quantity=10),
]).cost() == 200.0
assert Quote(client=Client(postcode=3000), lines=[
Line(code='door_sign', unit_cost=10.0, quantity=1),
Line(code='escape_sign', unit_cost=20.0, quantity=10),
]).cost() == 189.0