Skip to content

Commit

Permalink
if price exists in db, do not add one when creating a commodity trans…
Browse files Browse the repository at this point in the history
…action
  • Loading branch information
sdementen committed Mar 4, 2018
1 parent c4e5e6c commit 62df230
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions piecash/core/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ def validate(self):

value = (self.value / self.quantity).quantize(Decimal("0.000001"))
try:
# find existing price if any
# find existing price if any and if so, do nothing
pr = self.book.prices(commodity=self.account.commodity,
currency=self.transaction.currency,
date=self.transaction.post_date,
type="transaction",
source="user:split-register")
pr.value = value
)

except KeyError:
# otherwise, add a price in the database
pr = Price(commodity=self.account.commodity,
currency=self.transaction.currency,
date=self.transaction.post_date,
Expand Down Expand Up @@ -224,10 +224,10 @@ def __init__(self,
num="",
):

assert enter_date is None or isinstance(enter_date, datetime.datetime), "enter_date should be a datetime object"
assert post_date is None or (
isinstance(post_date, datetime.date)
and not isinstance(post_date, datetime.datetime)), "post_date should be a date object"
if not (enter_date is None or type(enter_date) is datetime.datetime):
raise GncValidationError("enter_date should be a datetime object")
if not (post_date is None or type(post_date) is datetime.date):
raise GncValidationError("post_date should be a date object")

self.currency = currency
self.description = description
Expand Down

0 comments on commit 62df230

Please sign in to comment.