mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
Close remittances
This commit is contained in:
@ -45,8 +45,35 @@ class ProductFormSetHelper(FormHelper):
|
||||
class RemittanceForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.helper = FormHelper()
|
||||
self.helper.add_input(Submit('submit', _("Submit"), attr={'class': 'btn btn-block btn-primary'}))
|
||||
|
||||
if self.instance.pk:
|
||||
self.fields["type"].disabled = True
|
||||
self.fields["type"].required = False
|
||||
|
||||
if not self.instance.closed:
|
||||
self.helper.add_input(Submit('submit', _("Submit"), attr={'class': 'btn btn-block btn-primary'}))
|
||||
if self.instance.transactions:
|
||||
self.helper.add_input(Submit("close", _("Close"), css_class='btn btn-success'))
|
||||
else:
|
||||
self.fields["comment"].disabled = True
|
||||
self.fields["comment"].required = False
|
||||
|
||||
def clean(self):
|
||||
if self.instance.closed:
|
||||
self.add_error("comment", _("Remittance is already closed."))
|
||||
|
||||
cleaned_data = super().clean()
|
||||
|
||||
if "type" in self.changed_data:
|
||||
self.add_error("type", _("You can't change the type of the remittance."))
|
||||
|
||||
if "close" in self.data:
|
||||
self.instance.closed = True
|
||||
self.cleaned_data["closed"] = True
|
||||
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = Remittance
|
||||
|
@ -35,10 +35,10 @@ class InvoiceTable(tables.Table):
|
||||
|
||||
|
||||
class RemittanceTable(tables.Table):
|
||||
edit = tables.LinkColumn("treasury:remittance_update",
|
||||
verbose_name=_("Edit"),
|
||||
view = tables.LinkColumn("treasury:remittance_update",
|
||||
verbose_name=_("View"),
|
||||
args=[A("pk")],
|
||||
text=_("Edit"),
|
||||
text=_("View"),
|
||||
attrs={
|
||||
'a': {'class': 'btn btn-primary'}
|
||||
}, )
|
||||
@ -52,7 +52,7 @@ class RemittanceTable(tables.Table):
|
||||
}
|
||||
model = Remittance
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('id', 'date', 'type', 'comment', 'count', 'amount', 'edit',)
|
||||
fields = ('id', 'date', 'type', 'comment', 'count', 'amount', 'view',)
|
||||
|
||||
|
||||
class SpecialTransactionTable(tables.Table):
|
||||
|
@ -236,10 +236,12 @@ class RemittanceUpdateView(LoginRequiredMixin, UpdateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
|
||||
form = ctx["form"]
|
||||
ctx["table"] = RemittanceTable(data=Remittance.objects.all())
|
||||
data = SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).all()
|
||||
ctx["special_transactions"] = SpecialTransactionTable(
|
||||
data=SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).all(),
|
||||
exclude=('remittance_add', ))
|
||||
data=data,
|
||||
exclude=('remittance_add', 'remittance_remove', ) if self.object.closed else ('remittance_add', ))
|
||||
|
||||
return ctx
|
||||
|
||||
|
Reference in New Issue
Block a user