Skip to content
Snippets Groups Projects
Commit f1159d80 authored by b4-sharp's avatar b4-sharp
Browse files

Add calculate_price() to ItemSet model

parent 9de3699c
No related branches found
No related tags found
No related merge requests found
......@@ -60,7 +60,7 @@ class ItemSet(db.Model):
description = db.Column(db.String(256), nullable=False)
price = db.Column(
db.Integer, nullable=False
) # In pounds, as we're not dividing or multiplying this will not matter in calculations. Do we neccesarily need this? It could be calculated dynamically from the items held.
) # TODO: Rename price to quantity
items = db.relationship(
"Item",
secondary=itemSets,
......@@ -68,8 +68,11 @@ class ItemSet(db.Model):
backref=db.backref("ItemSets", lazy=True),
)
def calculate_price(self):
return sum(int(item.price) for item in self.items)
def __repr__(self):
return f"id: {self.id}, description: {self.description}, items: {self.items}"
return f"id: {self.id}, description: {self.description}, items: {self.items}, quantity: {self.price}, price: { self.calculate_price() }" # TODO: Rename price to quantity
class User(db.Model, UserMixin):
......
from store import app
""" An instance of the database needs to exist to unit test,
as the database is seeded from file this can be used as a test database.
Really there should be an inmemory database for testing purposes, but
further research into how flask works with such a thing needs to be done.
"""
# An instance of the database needs to exist to unit test,
# as the database is seeded from file this can be used as a test database.
# It would probably be best to create a variant of it here, but for now
# just use the main database to test against.
from store.utility import *
import unittest
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment