mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-13 12:23:44 +01:00
Merge pull request #621 from eitchtee/fix/convert-applies-form-amount
fix(transactions): apply the form amount when converting a paid transaction
This commit is contained in:
3 files changed
+11
-6
No files matched your search
@@ -895,6 +895,8 @@ class InstallmentPlanForm(forms.ModelForm):
|
||||
# The converted transaction becomes the first installment
|
||||
source_transaction.installment_plan = instance
|
||||
source_transaction.installment_id = instance.installment_start
|
||||
# Take the amount set on the form, even if already paid
|
||||
source_transaction.amount = instance.installment_amount
|
||||
source_transaction.save()
|
||||
instance.update_transactions()
|
||||
elif is_new:
|
||||
|
||||
@@ -976,9 +976,7 @@ class RecurringTransaction(models.Model):
|
||||
existing_transaction.category = self.category
|
||||
existing_transaction.notes = self.notes if self.add_notes_to_transaction else ""
|
||||
existing_transaction.recurring_transaction = self
|
||||
|
||||
if not existing_transaction.is_paid: # Don't update value for paid transactions
|
||||
existing_transaction.amount = self.amount
|
||||
existing_transaction.amount = self.amount
|
||||
|
||||
existing_transaction.save()
|
||||
existing_transaction.tags.set(self.tags(manager="all_objects").all())
|
||||
|
||||
@@ -275,8 +275,9 @@ class TransactionConvertViewTests(TestCase):
|
||||
recurring = RecurringTransaction.all_objects.get()
|
||||
self.transaction.refresh_from_db()
|
||||
self.assertEqual(self.transaction.recurring_transaction, recurring)
|
||||
# Paid amount is preserved
|
||||
self.assertEqual(self.transaction.amount, 50)
|
||||
# The form's amount applies even though the original was paid
|
||||
self.assertEqual(self.transaction.amount, 60)
|
||||
self.assertTrue(self.transaction.is_paid)
|
||||
self.assertEqual(
|
||||
recurring.transactions.filter(date=date(2030, 1, 15)).count(), 1
|
||||
)
|
||||
@@ -288,7 +289,7 @@ class TransactionConvertViewTests(TestCase):
|
||||
{
|
||||
"account": self.account.id,
|
||||
"type": "EX",
|
||||
"installment_amount": "50",
|
||||
"installment_amount": "70",
|
||||
"description": "TV",
|
||||
"add_description_to_transaction": "on",
|
||||
"number_of_installments": 3,
|
||||
@@ -306,6 +307,10 @@ class TransactionConvertViewTests(TestCase):
|
||||
self.assertTrue(self.transaction.is_paid)
|
||||
self.assertEqual(self.transaction.description, "TV")
|
||||
self.assertEqual(plan.transactions.count(), 3)
|
||||
# The form's amount applies to every installment, including the paid original
|
||||
self.assertEqual(
|
||||
set(plan.transactions.values_list("amount", flat=True)), {70}
|
||||
)
|
||||
|
||||
def test_linked_transaction_cannot_be_converted_into_plan(self):
|
||||
self._post(
|
||||
|
||||
Reference in new issue
Block a user