mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 09:12:11 +01: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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,34 @@
 | 
			
		||||
{% load crispy_forms_tags pretty_money %}
 | 
			
		||||
{% load render_table from django_tables2 %}
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <h1>{% trans "Remittance #" %}{{ object.pk }}</h1>
 | 
			
		||||
 | 
			
		||||
    <p><a class="btn btn-default" href="{% url 'treasury:remittance_list' %}">{% trans "Remittances list" %}</a></p>
 | 
			
		||||
 | 
			
		||||
    {% if object.pk %}
 | 
			
		||||
        <div id="div_id_type" class="form-group"><label for="id_count" class="col-form-label">{% trans "Count" %}</label>
 | 
			
		||||
            <div class="">
 | 
			
		||||
                <input type="text" name="count" value="{{ object.count }}" class="textinput textInput form-control" id="id_count" disabled>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        <div id="div_id_type" class="form-group"><label for="id_amount" class="col-form-label">{% trans "Amount" %}</label>
 | 
			
		||||
            <div class="">
 | 
			
		||||
                <input class="textinput textInput form-control" type="text" value="{{ object.amount|pretty_money }}" id="id_amount" disabled>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 | 
			
		||||
    {% crispy form %}
 | 
			
		||||
    {% render_table special_transactions %}
 | 
			
		||||
 | 
			
		||||
    <hr>
 | 
			
		||||
 | 
			
		||||
    <h2>{% trans "Linked transactions" %}</h2>
 | 
			
		||||
    {% if special_transactions.data %}
 | 
			
		||||
        {% render_table special_transactions %}
 | 
			
		||||
    {% else %}
 | 
			
		||||
        <div class="alert alert-warning">
 | 
			
		||||
            {% trans "There is no transaction linked with this remittance." %}
 | 
			
		||||
        </div>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user