django-orchestra-test/orchestra/contrib/orders/forms.py

69 lines
3.4 KiB
Python
Raw Normal View History

from django import forms
from django.contrib.admin import widgets
from django.utils import timezone
2014-09-10 16:53:09 +00:00
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from orchestra.admin.forms import AdminFormMixin
2014-09-18 15:07:39 +00:00
from orchestra.admin.utils import change_url
from .models import Order
class BillSelectedOptionsForm(AdminFormMixin, forms.Form):
billing_point = forms.DateField(initial=timezone.now,
2015-04-05 10:46:24 +00:00
label=_("Billing point"), widget=widgets.AdminDateWidget,
help_text=_("Date you want to bill selected orders"))
fixed_point = forms.BooleanField(initial=False, required=False,
2015-04-05 10:46:24 +00:00
label=_("Fixed point"),
help_text=_("Deisgnates whether you want the billing point to be an "
"exact date, or adapt it to the billing period."))
2014-10-11 16:21:51 +00:00
proforma = forms.BooleanField(initial=False, required=False,
2015-04-05 10:46:24 +00:00
label=_("Pro-forma (billing simulation)"),
help_text=_("Creates a Pro Forma instead of billing the orders."))
2014-09-19 14:47:25 +00:00
new_open = forms.BooleanField(initial=False, required=False,
2015-04-05 10:46:24 +00:00
label=_("Create a new open bill"),
help_text=_("Deisgnates whether you want to put this orders on a new "
"open bill, or allow to reuse an existing one."))
2014-09-11 14:00:20 +00:00
2014-09-10 16:53:09 +00:00
def selected_related_choices(queryset):
for order in queryset:
2015-04-02 16:14:55 +00:00
verbose = '<a href="{order_url}">{description}</a> '
verbose += '<a class="account" href="{account_url}">{account}</a>'
2014-09-10 16:53:09 +00:00
verbose = verbose.format(
2014-09-18 15:07:39 +00:00
order_url=change_url(order), description=order.description,
account_url=change_url(order.account), account=str(order.account)
2014-09-10 16:53:09 +00:00
)
yield (order.pk, mark_safe(verbose))
class BillSelectRelatedForm(AdminFormMixin, forms.Form):
2014-09-14 09:52:45 +00:00
# This doesn't work well with reordering after billing
# pricing_with_all = forms.BooleanField(label=_("Do pricing with all orders"),
# initial=False, required=False, help_text=_("The price may vary "
# "depending on the billed orders. This options designates whether "
# "all existing orders will be used for price computation or not."))
select_all = forms.BooleanField(label=_("Select all"), required=False)
2014-09-14 09:52:45 +00:00
selected_related = forms.ModelMultipleChoiceField(label=_("Related orders"),
2015-04-05 10:46:24 +00:00
queryset=Order.objects.none(), widget=forms.CheckboxSelectMultiple,
required=False)
billing_point = forms.DateField(widget=forms.HiddenInput())
fixed_point = forms.BooleanField(widget=forms.HiddenInput(), required=False)
2014-10-11 16:21:51 +00:00
proforma = forms.BooleanField(widget=forms.HiddenInput(), required=False)
new_open = forms.BooleanField(widget=forms.HiddenInput(), required=False)
def __init__(self, *args, **kwargs):
super(BillSelectRelatedForm, self).__init__(*args, **kwargs)
queryset = kwargs['initial'].get('related_queryset', None)
if queryset:
self.fields['selected_related'].queryset = queryset
2014-09-10 16:53:09 +00:00
self.fields['selected_related'].choices = selected_related_choices(queryset)
2014-09-10 16:53:09 +00:00
class BillSelectConfirmationForm(AdminFormMixin, forms.Form):
billing_point = forms.DateField(widget=forms.HiddenInput())
fixed_point = forms.BooleanField(widget=forms.HiddenInput(), required=False)
2014-10-11 16:21:51 +00:00
proforma = forms.BooleanField(widget=forms.HiddenInput(), required=False)
new_open = forms.BooleanField(widget=forms.HiddenInput(), required=False)