diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms_common.py | 47 | ||||
-rw-r--r-- | ishtar_common/models.py | 26 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/forms/qa_document_packaging.html | 32 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_document.html | 4 | ||||
-rw-r--r-- | ishtar_common/urls.py | 5 | ||||
-rw-r--r-- | ishtar_common/views.py | 31 |
6 files changed, 136 insertions, 9 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 991968e3b..49d1829bc 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1745,6 +1745,53 @@ class QADocumentDuplicateForm(IshtarForm): return new +class QADocumentPackagingForm(IshtarForm): + container = forms.IntegerField( + label=_("Container"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-container'), + associated_model=Container, new=True), + validators=[models.valid_id(Container)]) + container_to_change = forms.ChoiceField( + label=_("Change "), required=True, + choices=( + ('current-and-reference', _(u"current and reference containers")), + ('reference', _(u"the reference container")), + ('current', _(u"the current container")), + ) + ) + + def __init__(self, *args, **kwargs): + self.confirm = False + self.user = None + if 'user' in kwargs: + self.user = kwargs.pop('user') + if hasattr(self.user, 'ishtaruser'): + self.user = self.user.ishtaruser + self.items = kwargs.pop('items') + + super(QADocumentPackagingForm, self).__init__(*args, **kwargs) + + def save(self, items, user): + container = Container.objects.get(pk=self.cleaned_data['container']) + container_to_change = self.cleaned_data.get('container_to_change', '') + container_attrs = [] + if container_to_change in ('reference', 'current-and-reference'): + container_attrs.append('container_ref') + if container_to_change in ('current', 'current-and-reference'): + container_attrs.append('container') + for document in items: + changed = False + for container_attr in container_attrs: + if getattr(document, container_attr) == container: + continue + setattr(document, container_attr, container) + changed = True + if changed: + document.history_modifier = user + document.save() + + class QALockForm(forms.Form): action = forms.ChoiceField( label=_("Action"), choices=(('lock', _("Lock")), diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d9112b5e7..42b4c479a 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -5633,8 +5633,13 @@ class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel, QuickAction( url="document-qa-duplicate", icon_class="fa fa-clone", text=_("Duplicate"), target="one", - rights=['change_document', - 'change_own_document']), + rights=['change_document', 'change_own_document']), + QuickAction( + url="document-qa-packaging", icon_class="fa fa-gift", + text=_("Packaging"), target="many", + rights=['change_document', 'change_own_document'], + module='warehouse' + ), ] SERIALIZATION_FILES = ["image", "thumbnail", "associated_file"] @@ -5795,11 +5800,18 @@ class Document(BaseHistorizedItem, QRCodeItem, OwnPerms, ImageModel, # is_locked = self.is_locked(request.user) can_edit_document = self.can_do(request, 'change_document') - if can_edit_document: - actions += [ - (reverse("document-qa-duplicate", args=[self.pk]), - _("Duplicate"), "fa fa-clone", "", "", True), - ] + if not can_edit_document: + return actions + actions += [ + (reverse("document-qa-duplicate", args=[self.pk]), + _("Duplicate"), "fa fa-clone", "", "", True), + ] + if get_current_profile().warehouse: + actions.append( + (reverse("document-qa-packaging", args=[self.pk]), + _("Packaging"), + "fa fa-gift", "", "", True) + ) return actions @property diff --git a/ishtar_common/templates/ishtar/forms/qa_document_packaging.html b/ishtar_common/templates/ishtar/forms/qa_document_packaging.html new file mode 100644 index 000000000..02f60e6c0 --- /dev/null +++ b/ishtar_common/templates/ishtar/forms/qa_document_packaging.html @@ -0,0 +1,32 @@ +{% extends "ishtar/forms/qa_base.html" %} +{% load i18n inline_formset table_form %} + +{% block main_form %} + {% if form.non_field_errors %} + <div class="alert alert-danger" role="alert"> + {{form.non_field_errors}} + </div> + {% endif %} + + <h4>{% trans "Documents" %}</h4> + <ul>{% for item in items %} + <li>{{item}}</li>{% endfor %} + </ul> + + <h4>{% trans "Packaging" %}</h4> + {% for hidden in form.hidden_fields %} + {{hidden}} + {% if hidden.errors %}<div class="invalid-feedback"> + {{ hidden.errors }} + </div>{% endif %} + {% endfor %} + <div class="form-row"> + {% with form.container as field %} + {% include "blocks/bs_field_snippet.html" %} + {% endwith %} + {% with form.container_to_change as field %} + {% include "blocks/bs_field_snippet.html" %} + {% endwith %} + </div> +{% endblock %} + diff --git a/ishtar_common/templates/ishtar/sheet_document.html b/ishtar_common/templates/ishtar/sheet_document.html index 0212b1695..598de5f76 100644 --- a/ishtar_common/templates/ishtar/sheet_document.html +++ b/ishtar_common/templates/ishtar/sheet_document.html @@ -83,8 +83,8 @@ {% if item.container or item.container_ref or item.item_number != 1 or item.duplicate %} <h4 class="col-12">{% trans "Container" %}</h4> - {% field_flex_detail "Container" item.container %} - {% field_flex_detail "Reference container" item.container_ref %} + {% field_flex_detail "Container" item.container 2 %} + {% field_flex_detail "Reference container" item.container_ref 2 %} {% if item.item_number != 1 %}{% field_flex "Item number" item.item_number %}{% endif %} {% if item.duplicate %}{% field_flex "Has a duplicate" item.duplicate %}{% endif %} {% endif %} diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 79c9676ed..5ec8d4ee5 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -333,6 +333,11 @@ urlpatterns += [ check_rights(['change_document', 'change_own_document'])( views.QADocumentDuplicateFormView.as_view()), name='document-qa-duplicate'), + url(r'^document-qa-packaging/(?P<pks>[0-9-]+)?/$', + check_rights(['change_document', 'change_own_document'])( + views.QADocumentPackagingFormView.as_view()), + name='document-qa-packaging'), + url(r'autocomplete-documenttag/$', views.autocomplete_documenttag, name='autocomplete-documenttag'), url(r'new-documenttag/(?:(?P<parent_name>[^/]+)/)?' diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 64219ba66..160653bbb 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1988,6 +1988,11 @@ class DocumentSelectView(IshtarMixin, LoginRequiredMixin, self.pk = form.cleaned_data['pk'] return super(DocumentSelectView, self).form_valid(form) + def get_form_kwargs(self): + kwargs = super(DocumentSelectView, self).get_form_kwargs() + kwargs["user"] = self.request.user + return kwargs + def get_context_data(self, **kwargs): data = super(DocumentSelectView, self).get_context_data(**kwargs) if self.request.GET and "open_item" in self.request.GET: @@ -2435,3 +2440,29 @@ class QADocumentDuplicateFormView(QAItemForm): return data +class QADocumentPackagingFormView(QAItemForm): + template_name = 'ishtar/forms/qa_document_packaging.html' + model = models.Document + form_class = forms.QADocumentPackagingForm + page_name = _(u"Packaging") + base_url = "document-qa-packaging" + + def dispatch(self, request, *args, **kwargs): + returned = super(QADocumentPackagingFormView, self).dispatch( + request, *args, **kwargs) + """ + for item in self.items: + if item.is_locked(request.user): + return HttpResponseRedirect(reverse("qa-not-available")) + """ + return returned + + def get_form_kwargs(self): + kwargs = super(QADocumentPackagingFormView, self).get_form_kwargs() + kwargs['user'] = self.request.user + kwargs['prefix'] = "qa-packaging" + return kwargs + + def form_valid(self, form): + form.save(self.items, self.request.user) + return HttpResponseRedirect(reverse("success")) |