Merge pull request #1148 from SchrodingersGat/order-parts

Order parts
This commit is contained in:
Oliver 2020-11-27 12:28:04 +11:00 committed by GitHub
commit a5e6ac2300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 11 deletions

View File

@ -0,0 +1,17 @@
{% extends "modal_form.html" %}
{% load i18n %}
{% block pre_form_content %}
{{ block.super }}
{% if part %}
<div class='alert alert-block alert-info'>
{% include "hover_image.html" with image=part.image %}
{{ part.full_name}}
<br>
<i>{{ part.description }}</i>
</div>
{% endif %}
{% endblock %}

View File

@ -291,7 +291,7 @@ class SupplierPartCreate(AjaxCreateView):
model = SupplierPart
form_class = EditSupplierPartForm
ajax_template_name = 'modal_form.html'
ajax_template_name = 'company/supplier_part_create.html'
ajax_form_title = _('Create new Supplier Part')
context_object_name = 'part'
role_required = 'purchase_order.add'
@ -304,6 +304,27 @@ class SupplierPartCreate(AjaxCreateView):
# TODO - What validation steps can be performed on the single_pricing field?
pass
def get_context_data(self):
"""
Supply context data to the form
"""
ctx = super().get_context_data()
# Add 'part' object
form = self.get_form()
part = form['part'].value()
try:
part = Part.objects.get(pk=part)
except (ValueError, Part.DoesNotExist):
part = None
ctx['part'] = part
return ctx
def save(self, form):
"""
If single_pricing is defined, add a price break for quantity=1

View File

@ -11,11 +11,11 @@
{% if parts|length > 0 %}
<div class='alert alert-info alert-block' role='alert'>
{% trans "Select suppliers." %}
{% trans "Select suppliers" %}
</div>
{% else %}
<div class='alert alert-warning alert-block' role='alert'>
{% trans "No purchaseable parts selected." %}
{% trans "No purchaseable parts selected" %}
</div>
{% endif %}
@ -39,8 +39,8 @@
{{ part.full_name }} <small><i>{{ part.description }}</i></small>
</td>
<td>
<button class='btn btn-default btn-create' onClick='newSupplierPartFromOrderWizard()' id='new_supplier_part_{{ part.id }}' title='Create new supplier part for {{ part }}' type='button'>
<span part-id='{{ part.id }}' class='fas fa-plus-circle'></span>
<button class='btn btn-default btn-create' onClick='newSupplierPartFromOrderWizard()' id='new_supplier_part_{{ part.id }}' part='{{ part.pk }}' title='{% trans "Create new supplier part" $}' type='button'>
<span part='{{ part.pk }}' class='fas fa-plus-circle'></span>
</button>
</td>
<td>

View File

@ -243,6 +243,22 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
});
});
// Callback for 'buy' button
$(table).find('.button-buy').click(function() {
var pk = $(this).attr('pk');
var idx = $(this).closest('tr').attr('data-index');
var row = $(table).bootstrapTable('getData')[idx];
launchModalForm('{% url "order-parts" %}', {
data: {
parts: [
pk,
]
}
});
});
// Callback for 'build' button
$(table).find('.button-build').click(function() {
var pk = $(this).attr('pk');
@ -563,7 +579,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
}
if (row.sub_part_detail.purchaseable) {
html += makeIconButton('fa-shopping-cart icon-blue', 'button-buy', row.sub_part, '{% trans "Order stock" %}', {disabled: true});
html += makeIconButton('fa-shopping-cart icon-blue', 'button-buy', row.sub_part, '{% trans "Order stock" %}');
}
html += makeIconButton('fa-sign-in-alt icon-green', 'button-add', row.sub_part, '{% trans "Allocate stock" %}');

View File

@ -21,9 +21,16 @@ function newSupplierPartFromOrderWizard(e) {
e = e || window.event;
var src = e.target || e.srcElement;
var src = e.srcElement || e.target;
var part = $(src).attr('part-id');
var part = $(src).attr('part');
console.log('part: ' + part);
if (!part) {
part = $(src).closest('button').attr('part');
console.log('parent: ' + part);
}
launchModalForm("/supplier-part/new/", {
modal: '#modal-form-secondary',
@ -125,7 +132,7 @@ function loadPurchaseOrderTable(table, options) {
name: 'purchaseorder',
groupBy: false,
original: options.params,
formatNoMatches: function() { return "{% trans "No purchase orders found" %}"; },
formatNoMatches: function() { return '{% trans "No purchase orders found" %}'; },
columns: [
{
field: 'pk',
@ -208,7 +215,7 @@ function loadSalesOrderTable(table, options) {
name: 'salesorder',
groupBy: false,
original: options.params,
formatNoMatches: function() { return "{% trans "No sales orders found" %}"; },
formatNoMatches: function() { return '{% trans "No sales orders found" %}'; },
columns: [
{
field: 'pk',
@ -265,7 +272,7 @@ function loadSalesOrderTable(table, options) {
{
sortable: true,
field: 'shipment_date',
title: "{% trans "Shipment Date" %}",
title: '{% trans "Shipment Date" %}',
},
{
sortable: true,