Form for creating a new SalesOrder

This commit is contained in:
Oliver Walters 2020-04-20 22:13:07 +10:00
parent ebbcff3c7f
commit ce1dd88129
8 changed files with 71 additions and 1 deletions

View File

@ -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',

View File

@ -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 """

View File

@ -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,

View File

@ -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) {

View File

@ -33,4 +33,12 @@ loadSalesOrderTable("#sales-order-table", {
url: "{% url 'api-so-list' %}",
});
$("#so-create").click(function() {
launchModalForm("{% url 'so-create' %}",
{
follow: true,
}
);
});
{% endblock %}

View File

@ -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<pk>\d+)/', include(sales_order_detail_urls)),

View File

@ -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 """

View File

@ -22,7 +22,7 @@
<a class='dropdown-toggle' data-toggle='dropdown' href='#'><span class='fas fa-truck icon-header'></span>{% trans "Sell" %}</a>
<ul class='dropdown-menu'>
<li><a href="{% url 'customer-index' %}"><span class='fas fa-user-tie icon-header'></span>{% trans "Customers" %}</a>
<li><a href="#"><span class='fas fa-list icon-header'></span>{% trans "Sales Orders" %}</a></li>
<li><a href="{% url 'so-index' %}"><span class='fas fa-list icon-header'></span>{% trans "Sales Orders" %}</a></li>
</ul>
</li>
</ul>