Skip to content

Commit

Permalink
0.2.13.2
Browse files Browse the repository at this point in the history
========

* **New:** Removed ``msrp``, ``cost`` and ``unit`` arguments from
  ``BudgetEntry.__init__()`` and added a new ``good`` argument to get all of
  the data from the related ``Good`` instance. But the ``msrp``, ``cost`` and
  ``unit`` attributes of ``BudgetEntry`` class are still there to store the
  values that may not correlate with the related ``Good`` in future.
  • Loading branch information
eoyilmaz committed Feb 15, 2015
1 parent 0bd6da0 commit fc6a94d
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 180 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
Stalker Changes
===============

0.2.13.2
========

* **New:** Removed ``msrp``, ``cost`` and ``unit`` arguments from
``BudgetEntry.__init__()`` and added a new ``good`` argument to get all of
the data from the related ``Good`` instance. But the ``msrp``, ``cost`` and
``unit`` attributes of ``BudgetEntry`` class are still there to store the
values that may not correlate with the related ``Good`` in future.

0.2.13.1
========

Expand Down
2 changes: 1 addition & 1 deletion stalker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
See docs for more information.
"""

__version__ = '0.2.13.1'
__version__ = '0.2.13.2'


import sys
Expand Down
62 changes: 39 additions & 23 deletions stalker/models/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,17 @@ def _validate_entry(self, key, entry):


class BudgetEntry(Entity):
"""Manages budget entries in a budget
"""Manages entries in a Budget.
With budget entries one can manage project budget costs. Each entry shows
one component of a bigger budget.
With BudgetEntries one can manage project budget entries one by one. Each
entry shows one component of a bigger budget. Entries are generally a
reflection of a :class:`.Good` instance and shows how many of that Good has
been included in this Budget, and what was the discounted price of that
Good.
:param float cost: This should be the direct copy of the Good.cost that
this item is related to.
:param float msrp: Again this should be the direct copy of the Good.msrp
that this item is related to.
:param budget: The :class:`.Budget` that this entry is a part of.
:param good: Stores a :class:`.Good` instance to carry all the
cost/msrp/unit data from.
:param float price: The decided price of this entry. This is generally
bigger than the cost and should be also bigger than msrp but the person
that is editing the the budget which this entry is related to can decide
Expand All @@ -270,9 +272,6 @@ class BudgetEntry(Entity):
price of this entry. It can be the same number of the :attr:`.price`
multiplied by the :attr:`.amount` or can be something else that reflects
the reality. Generally it is for calculating the "service" cost/profit.
:param str unit: The unit of this budget entry. Nothing so important for
now. Just a text like "$/hour". Stalker doesn't do any unit conversions
for now.
:param float amount: Defines the amount of :class:`Good` that is in
consideration for this entry.
"""
Expand All @@ -289,7 +288,6 @@ class BudgetEntry(Entity):
)

budget_id = Column(
'budget_id',
Integer,
ForeignKey('Budgets.id')
)
Expand All @@ -301,6 +299,17 @@ class BudgetEntry(Entity):
uselist=False
)

good_id = Column(
Integer,
ForeignKey('Goods.id')
)

good = relationship(
'Good',
primaryjoin='BudgetEntries.c.good_id==Goods.c.id',
uselist=False
)

cost = Column(Float, default=0.0)
msrp = Column(Float, default=0.0)

Expand All @@ -312,30 +321,23 @@ class BudgetEntry(Entity):

def __init__(self,
budget=None,
cost=0,
msrp=0,
good=None,
price=0,
realized_total=0,
unit='',
amount=0.0,
**kwargs):
super(BudgetEntry, self).__init__(**kwargs)

self.budget = budget
self.cost = cost
self.msrp = msrp
self.good = good
self.cost = good.cost
self.msrp = good.msrp
self.unit = good.unit

self.price = price
self.realized_total = realized_total

self.amount = amount
self.unit = unit

@property
def total(self):
"""returns the total cost of this entry
"""
return self.amount * self.cost

@validates('budget')
def _validate_budget(self, key, budget):
Expand Down Expand Up @@ -446,3 +448,17 @@ def _validate_amount(self, key, amount):
)

return float(amount)

@validates('good')
def _validate_good(self, key, good):
"""validates the given good value
"""
if not isinstance(good, Good):
raise TypeError(
'%s.good should be a stalker.models.budget.Good instance, '
'not %s' % (
self.__class__.__name__, good.__class__.__name__
)
)

return good
12 changes: 10 additions & 2 deletions tests/db/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,9 +1247,13 @@ def test_persistence_of_Budget_and_BudgetEntry(self):
DBSession.add(test_budget)
DBSession.commit()

good = Good(name='Some Good', cost=9, msrp=10, unit='$/hour')
DBSession.add(good)
DBSession.commit()

# create some entries
entry1 = BudgetEntry(budget=test_budget, amount=5.0)
entry2 = BudgetEntry(budget=test_budget, amount=1.0)
entry1 = BudgetEntry(budget=test_budget, good=good, amount=5.0)
entry2 = BudgetEntry(budget=test_budget, good=good, amount=1.0)

DBSession.add_all([entry1, entry2])
DBSession.commit()
Expand Down Expand Up @@ -1313,6 +1317,10 @@ def test_persistence_of_Budget_and_BudgetEntry(self):
BudgetEntry.query.all() == []
)

# we still should have the good
good_db = Good.query.filter(Good.name == 'Some Good').first()
self.assertTrue(good_db is not None)

def test_persistence_of_Page(self):
"""testing the persistence of Page
"""
Expand Down
Loading

0 comments on commit fc6a94d

Please sign in to comment.