First pass at allowing manual invoices.
This commit is contained in:
parent
a9bc647570
commit
2e5a8e3668
1 changed files with 32 additions and 1 deletions
|
@ -72,6 +72,38 @@ class InvoiceController(ForId, object):
|
||||||
value = condition.price
|
value = condition.price
|
||||||
return value
|
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
|
@classmethod
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def _generate_from_cart(cls, cart):
|
def _generate_from_cart(cls, cart):
|
||||||
|
@ -129,7 +161,6 @@ class InvoiceController(ForId, object):
|
||||||
|
|
||||||
# Generate the invoice
|
# Generate the invoice
|
||||||
|
|
||||||
user = cart.user
|
|
||||||
min_due_time = cart.reservation_duration + cart.time_last_updated
|
min_due_time = cart.reservation_duration + cart.time_last_updated
|
||||||
|
|
||||||
return cls._generate(cart.user, cart, min_due_time, line_items)
|
return cls._generate(cart.user, cart, min_due_time, line_items)
|
||||||
|
|
Loading…
Reference in a new issue