From 2e5a8e3668908ddefbce0d4dcfb9b701098e248f Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Thu, 15 Sep 2016 08:50:56 +1000 Subject: [PATCH] First pass at allowing manual invoices. --- registrasion/controllers/invoice.py | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/registrasion/controllers/invoice.py b/registrasion/controllers/invoice.py index 118b49cb..3d4df7fc 100644 --- a/registrasion/controllers/invoice.py +++ b/registrasion/controllers/invoice.py @@ -72,6 +72,38 @@ class InvoiceController(ForId, object): value = condition.price return value + @classmethod + @transaction.atomic + def manual_invoice(cls, user, due_delta, description_price_pairs): + ''' Generates an invoice for arbitrary items, not held in a user's + cart. + + Arguments: + user (User): The user the invoice is being generated for. + due_delta (datetime.timedelta): The length until the invoice is + due. + description_price_pairs ([(str, long or Decimal), ...]): A list of + pairs. Each pair consists of the description for each line item + and the price for that line item. The price will be cast to + Decimal. + + Returns: + an Invoice. + ''' + + line_items = [] + for description, price in description_price_pairs: + line_item = commerce.LineItem( + description=description, + quantity=1, + price=Decimal(price), + product=None, + ) + line_items.append(line_item) + + min_due_time = timezone.now() + due_delta + return cls._generate(user, None, min_due_time, line_items) + @classmethod @transaction.atomic def _generate_from_cart(cls, cart): @@ -129,7 +161,6 @@ class InvoiceController(ForId, object): # Generate the invoice - user = cart.user min_due_time = cart.reservation_duration + cart.time_last_updated return cls._generate(cart.user, cart, min_due_time, line_items)