Create a new purchase order directly from the "Order Parts" form wizard

This commit is contained in:
Oliver Walters 2019-06-13 20:42:09 +10:00
parent 915395e676
commit f52aa0af21
3 changed files with 32 additions and 1 deletions

View File

@ -42,7 +42,7 @@
id='new_po_{{ supplier.id }}'
title='Create new purchase order for {{ supplier.name }}'
type='button'>
<span onclick='newPurchaseOrderFromWizard()' class='glyphicon glyphicon-small glyphicon-plus'></span>
<span supplier-id='{{ supplier.id }}' onclick='newPurchaseOrderFromOrderWizard()' class='glyphicon glyphicon-small glyphicon-plus'></span>
</button>
</td>
<td>

View File

@ -4,6 +4,7 @@
<th data-field='reference'>Order Reference</th>
<th data-field='description'>Description</th>
<th data-field='status'>Status</th>
<th data-field='items'>Items</th>
</tr>
{% for order in orders %}
<tr>
@ -11,6 +12,7 @@
<td><a href="{% url 'purchase-order-detail' order.id %}">{{ order }}</a></td>
<td>{{ order.description }}</td>
<td>{% include "order/order_status.html" %}</td>
<td>{{ order.lines.count }}</td>
</tr>
{% endfor %}
</table>

View File

@ -38,3 +38,32 @@ function newSupplierPartFromOrderWizard(e) {
},
});
}
function newPurchaseOrderFromOrderWizard(e) {
/* Create a new purchase order directly from an order form.
* Launches a secondary modal and (if successful),
* back-fills the newly created purchase order.
*/
e = e || window.event;
var src = e.target || e.srcElement;
var supplier = $(src).attr('supplier-id');
launchModalForm("/order/purchase-order/new/", {
modal: '#modal-form-secondary',
data: {
supplier: supplier,
},
success: function(response) {
/* A new purchase order has been created! */
var dropdown = '#id-purchase-order-' + supplier;
var option = new Option(response.text, response.pk, true, true);
$('#modal-form').find(dropdown).append(option).trigger('change');
},
});
}