Skip to content

Commit

Permalink
Fix VAT being applied twice to discount entries
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanpetrea committed Aug 8, 2023
1 parent 3cf3984 commit b00262c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions silver/documents_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def _add_mf_cycle(self, billing_date, metered_features_billed_up_to, subscriptio
# Should return an entry info for trial as well, but need to filter it out from discounts
entry_info = None
else:
amount, _ = subscription._add_mfs_entries(
amount_before_tax, _ = subscription._add_mfs_entries(
start_date=relative_start_date, end_date=relative_end_date,
proforma=proforma, invoice=invoice, bonuses=bonuses
)
Expand All @@ -615,7 +615,7 @@ def _add_mf_cycle(self, billing_date, metered_features_billed_up_to, subscriptio
end_date=relative_end_date,
origin_type=OriginType.MeteredFeature,
subscription=subscription,
amount=amount
amount=amount_before_tax
)

return relative_end_date, entry_info
Expand Down
6 changes: 3 additions & 3 deletions silver/models/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ def _add_plan_entries(self, start_date, end_date, invoice=None, proforma=None) \
)
]

return entries[0].total, entries
return entries[0].total_before_tax, entries

def _included_units_from_bonuses(
self, metered_feature, start_date, end_date, extra_proration_fraction: Fraction, bonuses: List
Expand Down Expand Up @@ -1253,9 +1253,9 @@ def _add_mfs_entries(self, start_date, end_date, invoice=None, proforma=None, bo
start_date=start_date, end_date=end_date
)
entries.append(bonus_entry)
mfs_total += bonus_entry.total
mfs_total += bonus_entry.total_before_tax

mfs_total += entry.total
mfs_total += entry.total_before_tax

return mfs_total, entries

Expand Down
7 changes: 5 additions & 2 deletions silver/tests/commands/test_generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ def test_subscription_cycle_billing_duration(self):
def test_discounts_per_document(self):
billing_date = generate_docs_date('2015-07-01')

customer = CustomerFactory.create(sales_tax_percent=Decimal('0.00'))
customer = CustomerFactory.create(sales_tax_percent=Decimal('19.00'))
discount = DiscountFactory.create(percentage=Decimal('25'), duration_count=None, duration_interval=None)
discount.customers.add(customer)

Expand Down Expand Up @@ -2661,7 +2661,10 @@ def test_discounts_per_document(self):
assert all([not entry.prorated
for entry in proforma.proforma_entries.all()])
consumed_mfs_value = (consumed_units - included_units) * mf_price
assert proforma.total == (plan.amount + consumed_mfs_value) * Decimal('0.75')
assert proforma.total_before_tax == (plan.amount + consumed_mfs_value) * Decimal('0.75')
assert proforma.total == (
(plan.amount + consumed_mfs_value) * Decimal('0.75') * Decimal('1.19')
).quantize(Decimal('0.00'))

def test_discounts_noncumulative(self):
# TODO
Expand Down

0 comments on commit b00262c

Please sign in to comment.