Skip to content

Commit

Permalink
Fix Transline.original_amount attribute
Browse files Browse the repository at this point in the history
A bug was introduced in a14201d when
this was converted to a hybrid property.

Closes #275 on github.
  • Loading branch information
sde1000 committed Jan 17, 2024
1 parent 8538603 commit 7e447b0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion quicktill/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,11 +1175,20 @@ class Transline(Base, Logged):
name="discount_name_constraint"),
)

# The original_amount instance attribute may be accessed before
# the instance is committed to the database, and at this point
# self.discount may be None; treat this as zero
@hybrid_property
def original_amount(self):
"""The original amount of the transaction line before any discounts
"""
return self.amount + self.discount
return self.amount + (self.discount or zero)

# The original_amount class attribute relies on amount and
# discount having nullable=False
@original_amount.expression
def original_amount(cls):
return cls.amount + cls.discount

transaction = relationship(
Transaction,
Expand Down

0 comments on commit 7e447b0

Please sign in to comment.