2016-04-03 00:06:35 +00:00
|
|
|
from registrasion.controllers.cart import CartController
|
2016-04-10 04:41:43 +00:00
|
|
|
from registrasion.controllers.credit_note import CreditNoteController
|
2016-04-07 00:23:38 +00:00
|
|
|
from registrasion.controllers.invoice import InvoiceController
|
2016-04-22 05:06:24 +00:00
|
|
|
from registrasion.models import commerce
|
2016-04-03 00:06:35 +00:00
|
|
|
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
|
|
|
2016-04-03 03:21:57 +00:00
|
|
|
|
2016-04-03 00:06:35 +00:00
|
|
|
class TestingCartController(CartController):
|
|
|
|
|
|
|
|
def set_quantity(self, product, quantity, batched=False):
|
|
|
|
''' Sets the _quantity_ of the given _product_ in the cart to the given
|
|
|
|
_quantity_. '''
|
|
|
|
|
|
|
|
self.set_quantities(((product, quantity),))
|
|
|
|
|
|
|
|
def add_to_cart(self, product, quantity):
|
|
|
|
''' Adds _quantity_ of the given _product_ to the cart. Raises
|
|
|
|
ValidationError if constraints are violated.'''
|
|
|
|
|
|
|
|
try:
|
2016-04-22 05:06:24 +00:00
|
|
|
product_item = commerce.ProductItem.objects.get(
|
2016-04-03 00:06:35 +00:00
|
|
|
cart=self.cart,
|
|
|
|
product=product)
|
|
|
|
old_quantity = product_item.quantity
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
old_quantity = 0
|
|
|
|
self.set_quantity(product, old_quantity + quantity)
|
2016-04-06 07:24:25 +00:00
|
|
|
|
|
|
|
def next_cart(self):
|
|
|
|
self.cart.active = False
|
|
|
|
self.cart.save()
|
2016-04-07 00:23:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestingInvoiceController(InvoiceController):
|
2016-04-06 22:28:43 +00:00
|
|
|
|
2016-04-24 22:13:44 +00:00
|
|
|
def pay(self, reference, amount, pre_validate=True):
|
2016-04-06 22:28:43 +00:00
|
|
|
''' Testing method for simulating an invoice paymenht by the given
|
|
|
|
amount. '''
|
2016-04-07 08:26:31 +00:00
|
|
|
|
2016-04-24 22:13:44 +00:00
|
|
|
if pre_validate:
|
|
|
|
# Manual payments don't pre-validate; we should test that things
|
|
|
|
# still work if we do silly things.
|
|
|
|
self.validate_allowed_to_pay()
|
2016-04-06 22:28:43 +00:00
|
|
|
|
|
|
|
''' Adds a payment '''
|
2016-04-22 05:06:24 +00:00
|
|
|
commerce.ManualPayment.objects.create(
|
2016-04-06 22:28:43 +00:00
|
|
|
invoice=self.invoice,
|
|
|
|
reference=reference,
|
|
|
|
amount=amount,
|
|
|
|
)
|
|
|
|
|
|
|
|
self.update_status()
|
2016-04-10 04:41:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestingCreditNoteController(CreditNoteController):
|
|
|
|
|
|
|
|
def refund(self):
|
2016-04-22 05:06:24 +00:00
|
|
|
commerce.CreditNoteRefund.objects.create(
|
2016-04-10 04:41:43 +00:00
|
|
|
parent=self.credit_note,
|
|
|
|
reference="Whoops."
|
|
|
|
)
|