diff --git a/TODO.md b/TODO.md
index 528d13dc..7b243d91 100644
--- a/TODO.md
+++ b/TODO.md
@@ -444,3 +444,6 @@ mkhomedir_helper or create ssh homes with bash.rc and such
# mailscanner phishing, spam, whitelist choices
+
+
+# show base and total desglosed
diff --git a/orchestra/admin/forms.py b/orchestra/admin/forms.py
index e19f00f4..3cc06866 100644
--- a/orchestra/admin/forms.py
+++ b/orchestra/admin/forms.py
@@ -1,3 +1,4 @@
+import textwrap
from functools import partial
from django import forms
@@ -35,32 +36,47 @@ class AdminFormMixin(object):
class AdminFormSet(BaseModelFormSet):
def as_admin(self):
- prepopulated = {}
- fieldsets = [
- (None, {'fields': list(self.form().fields.keys())})
- ]
- readonly = getattr(self.form.Meta, 'readonly_fields', ())
- if not hasattr(self.modeladmin, 'verbose_name_plural'):
- opts = self.modeladmin.model._meta
- self.modeladmin.verbose_name_plural = opts.verbose_name_plural
- inline_admin_formset = helpers.InlineAdminFormSet(self.modeladmin, self,
- fieldsets, prepopulated, readonly, model_admin=self.modeladmin)
- template = Template(
- '{% include "admin/edit_inline/tabular.html" %}'
+ template = Template(textwrap.dedent("""\
+
""")
)
context = Context({
- 'inline_admin_formset': inline_admin_formset
+ 'formset': self
})
return template.render(context)
-def adminmodelformset_factory(modeladmin, form, formset=AdminFormSet, **kwargs):
- model = kwargs.pop('model', modeladmin.model)
- formset = modelformset_factory(model, form=form, formset=formset, **kwargs)
- formset.modeladmin = modeladmin
- return formset
-
-
class AdminPasswordChangeForm(forms.Form):
"""
A form used to change the password of a user in the admin interface.
diff --git a/orchestra/contrib/bills/actions.py b/orchestra/contrib/bills/actions.py
index 1d1be374..a247bbe5 100644
--- a/orchestra/contrib/bills/actions.py
+++ b/orchestra/contrib/bills/actions.py
@@ -6,14 +6,15 @@ from django.contrib import messages
from django.contrib.admin import helpers
from django.core.urlresolvers import reverse
from django.db import transaction
+from django.forms.models import modelformset_factory
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.utils import translation, timezone
from django.utils.safestring import mark_safe
from django.utils.translation import ungettext, ugettext_lazy as _
-from orchestra.admin.forms import adminmodelformset_factory
from orchestra.admin.decorators import action_with_confirmation
+from orchestra.admin.forms import AdminFormSet
from orchestra.admin.utils import get_object_from_url, change_url
from . import settings
@@ -41,7 +42,7 @@ def close_bills(modeladmin, request, queryset, action='close_bills'):
if not bill.is_open:
messages.warning(request, _("Selected bills should be in open state"))
return False
- SelectSourceFormSet = adminmodelformset_factory(modeladmin, SelectSourceForm, extra=0)
+ SelectSourceFormSet = modelformset_factory(modeladmin.model, form=SelectSourceForm, formset=AdminFormSet, extra=0)
formset = SelectSourceFormSet(queryset=queryset)
if request.POST.get('post') == 'generic_confirmation':
formset = SelectSourceFormSet(request.POST, request.FILES, queryset=queryset)
diff --git a/orchestra/contrib/bills/forms.py b/orchestra/contrib/bills/forms.py
index 9d2295cf..7105e63f 100644
--- a/orchestra/contrib/bills/forms.py
+++ b/orchestra/contrib/bills/forms.py
@@ -7,7 +7,7 @@ from orchestra.forms import SpanWidget
class SelectSourceForm(forms.ModelForm):
bill_link = forms.CharField(label=_("Number"), required=False, widget=SpanWidget)
- account_link = forms.CharField(label=_("Account"), required=False)
+ account_link = forms.CharField(label=_("Account"), required=False, widget=SpanWidget)
show_total = forms.CharField(label=_("Total"), required=False, widget=SpanWidget)
display_type = forms.CharField(label=_("Type"), required=False, widget=SpanWidget)
source = forms.ChoiceField(label=_("Source"), required=False)
@@ -16,7 +16,6 @@ class SelectSourceForm(forms.ModelForm):
fields = (
'bill_link', 'display_type', 'account_link', 'show_total', 'source'
)
- readonly_fields = ('account_link',)
def __init__(self, *args, **kwargs):
super(SelectSourceForm, self).__init__(*args, **kwargs)
@@ -34,6 +33,7 @@ class SelectSourceForm(forms.ModelForm):
self.fields['show_total'].widget.display = total
self.fields['bill_link'].widget.display = admin_link('__str__')(bill)
self.fields['display_type'].widget.display = bill.get_type_display()
+ self.fields['account_link'].widget.display = admin_link('account')(bill)
def clean_source(self):
source_id = self.cleaned_data['source']
diff --git a/orchestra/contrib/bills/models.py b/orchestra/contrib/bills/models.py
index ca36ad82..9383961d 100644
--- a/orchestra/contrib/bills/models.py
+++ b/orchestra/contrib/bills/models.py
@@ -312,6 +312,10 @@ class Bill(models.Model):
html = self.html or self.render()
return html_to_pdf(html, pagination=self.has_multiple_pages)
+ def updated(self):
+ self.updated_on = timezone.now()
+ self.save(update_fields=('updated_on',))
+
def save(self, *args, **kwargs):
if not self.type:
self.type = self.get_type()
diff --git a/orchestra/contrib/domains/actions.py b/orchestra/contrib/domains/actions.py
index 62081dc7..04ba8529 100644
--- a/orchestra/contrib/domains/actions.py
+++ b/orchestra/contrib/domains/actions.py
@@ -4,12 +4,12 @@ from django.contrib import messages
from django.contrib.admin import helpers
from django.db.models import Q
from django.db.models.functions import Concat, Coalesce
+from django.forms.models import modelformset_factory
from django.shortcuts import render
from django.utils.safestring import mark_safe
from django.utils.translation import ungettext, ugettext_lazy as _
from django.template.response import TemplateResponse
-from orchestra.admin.forms import adminmodelformset_factory
from orchestra.admin.utils import get_object_from_url, change_url, admin_link
from orchestra.utils.python import AttrDict
@@ -54,8 +54,8 @@ def edit_records(modeladmin, request, queryset):
"but has been automatically added to this list.")
link = '%(name)s' % context
modeladmin_copy.verbose_name_plural = mark_safe(link)
- RecordFormSet = adminmodelformset_factory(
- modeladmin_copy, RecordForm, formset=RecordEditFormSet, extra=1, can_delete=True)
+ RecordFormSet = modelformset_factory(
+ modeladmin.model, form=RecordForm, formset=RecordEditFormSet, extra=1, can_delete=True)
formset = RecordFormSet(queryset=domain.records.all(), prefix=domain.id)
formset.instance = domain
formset.cls = RecordFormSet
diff --git a/orchestra/contrib/orders/billing.py b/orchestra/contrib/orders/billing.py
index 328e59ef..813ae9c0 100644
--- a/orchestra/contrib/orders/billing.py
+++ b/orchestra/contrib/orders/billing.py
@@ -58,6 +58,7 @@ class BillsBackend(object):
order_billed_until=line.order.old_billed_until
)
self.create_sublines(billine, line.discounts)
+ bill.updated()
return bills
# def format_period(self, ini, end):