From ce1dd8812996b711b198e9756aa583ac5b01752c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 20 Apr 2020 22:13:07 +1000 Subject: [PATCH] Form for creating a new SalesOrder --- .../static/script/inventree/order.js | 10 +++++++ InvenTree/order/forms.py | 16 ++++++++++ InvenTree/order/models.py | 3 ++ .../templates/order/sales_order_detail.html | 2 ++ .../order/templates/order/sales_orders.html | 8 +++++ InvenTree/order/urls.py | 2 ++ InvenTree/order/views.py | 29 +++++++++++++++++++ InvenTree/templates/navbar.html | 2 +- 8 files changed, 71 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/static/script/inventree/order.js b/InvenTree/InvenTree/static/script/inventree/order.js index b48c0f4e64..1d331491ca 100644 --- a/InvenTree/InvenTree/static/script/inventree/order.js +++ b/InvenTree/InvenTree/static/script/inventree/order.js @@ -144,6 +144,11 @@ function loadPurchaseOrderTable(table, options) { return imageHoverIcon(row.supplier_detail.image) + renderLink(row.supplier_detail.name, `/company/${row.supplier}/purchase-orders/`); } }, + { + field: 'supplier_reference', + title: 'Supplier Reference', + sortable: true, + }, { sortable: true, field: 'description', @@ -212,6 +217,11 @@ function loadSalesOrderTable(table, options) { return imageHoverIcon(row.customer_detail.image) + renderLink(row.customer_detail.name, `/company/${row.customer}/sales-orders/`); } }, + { + field: 'customer_reference', + title: 'Customer Reference', + sotrable: true, + }, { sortable: true, field: 'description', diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 52c761e03e..56569812cd 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -15,6 +15,7 @@ from InvenTree.fields import RoundingDecimalFormField from stock.models import StockLocation from .models import PurchaseOrder, PurchaseOrderLineItem, PurchaseOrderAttachment +from .models import SalesOrder, SalesOrderLineItem class IssuePurchaseOrderForm(HelperForm): @@ -75,6 +76,21 @@ class EditPurchaseOrderForm(HelperForm): ] +class EditSalesOrderForm(HelperForm): + """ Form for editing a SalesOrder object """ + + class Meta: + model = SalesOrder + fields = [ + 'reference', + 'customer', + 'customer_reference', + 'description', + 'link' + ] + + + class EditPurchaseOrderAttachmentForm(HelperForm): """ Form for editing a PurchaseOrderAttachment object """ diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 544c54ec7b..2d678097d4 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -254,6 +254,9 @@ class SalesOrder(Order): customer_reference: Optional field for customer order reference code """ + def get_absolute_url(self): + return reverse('so-detail', kwargs={'pk': self.id}) + customer = models.ForeignKey(Company, on_delete=models.SET_NULL, null=True, diff --git a/InvenTree/order/templates/order/sales_order_detail.html b/InvenTree/order/templates/order/sales_order_detail.html index e82f234ac3..8a47b9d044 100644 --- a/InvenTree/order/templates/order/sales_order_detail.html +++ b/InvenTree/order/templates/order/sales_order_detail.html @@ -41,10 +41,12 @@ $("#so-lines-table").inventreeTable({ visible: false, }, { + sortable: true, field: 'reference', title: 'Reference' }, { + sortable: true, field: 'quantity', title: 'Quantity', formatter: function(value, row, index, field) { diff --git a/InvenTree/order/templates/order/sales_orders.html b/InvenTree/order/templates/order/sales_orders.html index d8d5e22d4d..394d45b3d8 100644 --- a/InvenTree/order/templates/order/sales_orders.html +++ b/InvenTree/order/templates/order/sales_orders.html @@ -33,4 +33,12 @@ loadSalesOrderTable("#sales-order-table", { url: "{% url 'api-so-list' %}", }); +$("#so-create").click(function() { + launchModalForm("{% url 'so-create' %}", + { + follow: true, + } + ); +}); + {% endblock %} \ No newline at end of file diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index e9a68f16a7..086033db23 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -68,6 +68,8 @@ sales_order_detail_urls = [ sales_order_urls = [ + url(r'^new/', views.SalesOrderCreate.as_view(), name='so-create'), + # Display detail view for a single SalesOrder url(r'^(?P\d+)/', include(sales_order_detail_urls)), diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 5a2f0e1920..cdf3676136 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -216,6 +216,35 @@ class PurchaseOrderCreate(AjaxCreateView): self.object.save() +class SalesOrderCreate(AjaxCreateView): + """ View for creating a new SalesOrder object """ + + model = SalesOrder + ajax_form_title = _("Create Sales Order") + form_class = order_forms.EditSalesOrderForm + + def get_initial(self): + initials = super().get_initial().copy() + + initials['status'] = OrderStatus.PENDING + + customer_id = self.request.GET.get('customer', None) + + if customer_id is not None: + try: + customer = Company.objects.get(id=customer_id) + initials['customer'] = customer + except (Company.DoesNotExist, ValueError): + pass + + return initials + + def post_save(self, **kwargs): + # Record the user who created this sales order + self.object.created_by = self.request.user + self.object.save() + + class PurchaseOrderEdit(AjaxUpdateView): """ View for editing a PurchaseOrder using a modal form """ diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index 3e87faa869..bb5dcebad7 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -22,7 +22,7 @@ {% trans "Sell" %}