Fixes #64
This commit is contained in:
parent
cdc6e229dc
commit
1e6c90163d
2 changed files with 12 additions and 7 deletions
|
@ -43,16 +43,16 @@ class InvoiceController(ForId, object):
|
||||||
cart_controller = CartController(cart)
|
cart_controller = CartController(cart)
|
||||||
cart_controller.validate_cart() # Raises ValidationError on fail.
|
cart_controller.validate_cart() # Raises ValidationError on fail.
|
||||||
|
|
||||||
cls.void_all_invoices(cart)
|
cls.update_old_invoices(cart)
|
||||||
invoice = cls._generate(cart)
|
invoice = cls._generate(cart)
|
||||||
|
|
||||||
return cls(invoice)
|
return cls(invoice)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def void_all_invoices(cls, cart):
|
def update_old_invoices(cls, cart):
|
||||||
invoices = commerce.Invoice.objects.filter(cart=cart).all()
|
invoices = commerce.Invoice.objects.filter(cart=cart).all()
|
||||||
for invoice in invoices:
|
for invoice in invoices:
|
||||||
cls(invoice).void()
|
cls(invoice).update_status()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resolve_discount_value(cls, item):
|
def resolve_discount_value(cls, item):
|
||||||
|
@ -299,6 +299,10 @@ class InvoiceController(ForId, object):
|
||||||
def update_validity(self):
|
def update_validity(self):
|
||||||
''' Voids this invoice if the cart it is attached to has updated. '''
|
''' Voids this invoice if the cart it is attached to has updated. '''
|
||||||
if not self._invoice_matches_cart():
|
if not self._invoice_matches_cart():
|
||||||
|
if self.total_payments() > 0:
|
||||||
|
# Free up the payments made to this invoice
|
||||||
|
self.refund()
|
||||||
|
else:
|
||||||
self.void()
|
self.void()
|
||||||
|
|
||||||
def void(self):
|
def void(self):
|
||||||
|
|
|
@ -564,19 +564,20 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
invoice = TestingInvoiceController.for_id(invoice.invoice.id)
|
invoice = TestingInvoiceController.for_id(invoice.invoice.id)
|
||||||
invoice2 = TestingInvoiceController.for_cart(cart.cart)
|
invoice2 = TestingInvoiceController.for_cart(cart.cart)
|
||||||
|
cn2 = self._credit_note_for_invoice(invoice.invoice)
|
||||||
|
|
||||||
invoice._refresh()
|
invoice._refresh()
|
||||||
|
|
||||||
# The first invoice should be refunded
|
# The first invoice should be refunded
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
commerce.invoice.STATUS_REFUNDED,
|
commerce.Invoice.STATUS_VOID,
|
||||||
invoice.invoice.status,
|
invoice.invoice.status,
|
||||||
)
|
)
|
||||||
|
|
||||||
# The credit note should be equal to the payments value of first inv
|
# Both credit notes should be for the same amount
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
cn.credit_note.value,
|
cn.credit_note.value,
|
||||||
invoice.total_payments(),
|
cn2.credit_note.value,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_sends_email_on_invoice_creation(self):
|
def test_sends_email_on_invoice_creation(self):
|
||||||
|
|
Loading…
Reference in a new issue