Skip to content

Commit

Permalink
make rounding invoices optional
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Oct 5, 2024
1 parent 574841e commit a3a066e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions auctions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,7 @@ class Meta:
"only_approved_sellers",
"only_approved_bidders",
"invoice_payment_instructions",
"invoice_rounding",
"minimum_bid",
"winning_bid_percent_to_club_for_club_members",
"lot_entry_fee_for_club_members",
Expand Down Expand Up @@ -1755,6 +1756,10 @@ def __init__(self, *args, **kwargs):
"invoice_payment_instructions",
css_class="col-md-6",
),
Div(
"invoice_rounding",
css_class="col-md-3",
),
Div(
"use_categories",
css_class="col-md-3",
Expand Down
25 changes: 25 additions & 0 deletions auctions/migrations/0150_auction_invoice_rounding_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1 on 2024-10-05 13:38

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("auctions", "0149_alter_userdata_email_me_when_people_comment_on_my_lots_and_more"),
]

operations = [
migrations.AddField(
model_name="auction",
name="invoice_rounding",
field=models.BooleanField(
default=True,
help_text="Round invoice totals to whole dollar amounts. Check if you plan to accept cash payments.",
),
),
migrations.AlterField(
model_name="auction",
name="allow_bidding_on_lots",
field=models.BooleanField(default=True, verbose_name="Allow online bidding"),
),
]
7 changes: 6 additions & 1 deletion auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,10 @@ class Auction(models.Model):
email_users_when_invoices_ready = models.BooleanField(default=True)
invoice_payment_instructions = models.CharField(max_length=255, blank=True, null=True, default="")
invoice_payment_instructions.help_text = "Shown to the user on their invoice. For example, 'You will receive a seperate PayPal invoice with payment instructions'"
# partial for #139
invoice_rounding = models.BooleanField(default=True)
invoice_rounding.help_text = (
"Round invoice totals to whole dollar amounts. Check if you plan to accept cash payments."
)
minimum_bid = models.PositiveIntegerField(default=2, validators=[MinValueValidator(1)])
minimum_bid.help_text = "Lowest price any lot will be sold for"
lot_entry_fee_for_club_members = models.PositiveIntegerField(
Expand Down Expand Up @@ -3127,6 +3130,8 @@ def user_should_be_paid(self):
@property
def rounded_net(self):
"""Always round in the customer's favor (against the club) to make sure that the club doesn't need to deal with change, only whole dollar amounts"""
if not self.auction.invoice_rounding:
return self.net
rounded = round(self.net)
if self.user_should_be_paid:
if self.net > rounded:
Expand Down
10 changes: 10 additions & 0 deletions auctions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,16 @@ def test_lot_prices(self):
lot = lots.filter(pk=self.lot.pk).first()
assert lot.your_cut == 0

def test_invoice_rounding(self):
invoice, created = Invoice.objects.get_or_create(auctiontos_user=self.tos)
assert invoice.rounded_net == -4
self.auction.invoice_rounding = False
self.auction.winning_bid_percent_to_club = 12
self.auction.save()
invoice, created = Invoice.objects.get_or_create(auctiontos_user=self.tos)
assert invoice.net == invoice.rounded_net
assert round(invoice.rounded_net, 2) == -3.2


class LotRefundDialogTests(TestCase):
def setUp(self):
Expand Down

0 comments on commit a3a066e

Please sign in to comment.