Create SupplierPart directly from PurchaseOrderLineItem dialog (#3361)

* Move JS code from html to external .js file

* Add secondary dialog for creating a new SupplierPart from the PurchaseOrderLineItem dialog

* JS linting
This commit is contained in:
Oliver 2022-07-20 12:53:31 +10:00 committed by GitHub
parent e383d6e955
commit afcd60b387
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 20 deletions

View File

@ -168,23 +168,16 @@
{% if order.status == PurchaseOrderStatus.PENDING %} {% if order.status == PurchaseOrderStatus.PENDING %}
$('#new-po-line').click(function() { $('#new-po-line').click(function() {
var fields = poLineItemFields({ createPurchaseOrderLineItem({{ order.pk }}, {
order: {{ order.pk }},
{% if order.supplier %} {% if order.supplier %}
supplier: {{ order.supplier.pk }}, supplier: {{ order.supplier.pk }},
{% if order.supplier.currency %} {% if order.supplier.currency %}
currency: '{{ order.supplier.currency }}', currency: '{{ order.supplier.currency }}',
{% endif %} {% endif %}
{% endif %} {% endif %}
});
constructForm('{% url "api-po-line-list" %}', {
fields: fields,
method: 'POST',
title: '{% trans "Add Line Item" %}',
onSuccess: function() { onSuccess: function() {
$('#po-line-table').bootstrapTable('refresh'); $('#po-line-table').bootstrapTable('refresh');
}, }
}); });
}); });

View File

@ -102,10 +102,14 @@ function editManufacturerPart(part, options={}) {
} }
function supplierPartFields() { function supplierPartFields(options={}) {
return { var fields = {
part: {}, part: {
filters: {
purchaseable: true,
}
},
manufacturer_part: { manufacturer_part: {
filters: { filters: {
part_detail: true, part_detail: true,
@ -128,6 +132,12 @@ function supplierPartFields() {
icon: 'fa-box', icon: 'fa-box',
} }
}; };
if (options.part) {
fields.manufacturer_part.filters.part = options.part;
}
return fields;
} }
/* /*
@ -135,10 +145,11 @@ function supplierPartFields() {
*/ */
function createSupplierPart(options={}) { function createSupplierPart(options={}) {
var fields = supplierPartFields(); var fields = supplierPartFields({
part: options.part,
});
if (options.part) { if (options.part) {
fields.manufacturer_part.filters.part = options.part;
fields.part.hidden = true; fields.part.hidden = true;
fields.part.value = options.part; fields.part.value = options.part;
} }

View File

@ -255,15 +255,20 @@ function renderOwner(name, data, parameters={}, options={}) {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function renderPurchaseOrder(name, data, parameters={}, options={}) { function renderPurchaseOrder(name, data, parameters={}, options={}) {
var html = `<span>${data.reference}</span>`; var html = '';
var thumbnail = null;
if (data.supplier_detail) { if (data.supplier_detail) {
thumbnail = data.supplier_detail.thumbnail || data.supplier_detail.image; thumbnail = data.supplier_detail.thumbnail || data.supplier_detail.image;
html += ' - ' + select2Thumbnail(thumbnail); html += select2Thumbnail(thumbnail);
html += `<span>${data.supplier_detail.name}</span>`; }
html += `<span>${data.reference}</span>`;
var thumbnail = null;
if (data.supplier_detail) {
html += ` - <span>${data.supplier_detail.name}</span>`;
} }
if (data.description) { if (data.description) {

View File

@ -16,6 +16,7 @@
renderLink, renderLink,
salesOrderStatusDisplay, salesOrderStatusDisplay,
setupFilterList, setupFilterList,
supplierPartFields,
*/ */
/* exported /* exported
@ -25,6 +26,8 @@
completePurchaseOrder, completePurchaseOrder,
completeShipment, completeShipment,
completePendingShipments, completePendingShipments,
createPurchaseOrder,
createPurchaseOrderLineItem,
createSalesOrder, createSalesOrder,
createSalesOrderShipment, createSalesOrderShipment,
editPurchaseOrderLineItem, editPurchaseOrderLineItem,
@ -539,6 +542,26 @@ function createPurchaseOrder(options={}) {
} }
// Create a new PurchaseOrderLineItem
function createPurchaseOrderLineItem(order, options={}) {
var fields = poLineItemFields({
order: order,
supplier: options.supplier,
currency: options.currency,
});
constructForm('{% url "api-po-line-list" %}', {
fields: fields,
method: 'POST',
title: '{% trans "Add Line Item" %}',
onSuccess: function(response) {
handleFormSuccess(response, options);
}
});
}
/* Construct a set of fields for the SalesOrderLineItem form */ /* Construct a set of fields for the SalesOrderLineItem form */
function soLineItemFields(options={}) { function soLineItemFields(options={}) {
@ -590,13 +613,40 @@ function poLineItemFields(options={}) {
var fields = { var fields = {
order: { order: {
hidden: true, filters: {
supplier_detail: true,
}
}, },
part: { part: {
filters: { filters: {
part_detail: true, part_detail: true,
supplier_detail: true, supplier_detail: true,
supplier: options.supplier, supplier: options.supplier,
},
secondary: {
method: 'POST',
title: '{% trans "Add Supplier Part" %}',
fields: function(data) {
var fields = supplierPartFields({
part: data.part,
});
fields.supplier.value = options.supplier;
// Adjust manufacturer part query based on selected part
fields.manufacturer_part.adjustFilters = function(query, opts) {
var part = getFormFieldValue('part', {}, opts);
if (part) {
query.part = part;
}
return query;
};
return fields;
}
} }
}, },
quantity: {}, quantity: {},
@ -610,6 +660,7 @@ function poLineItemFields(options={}) {
if (options.order) { if (options.order) {
fields.order.value = options.order; fields.order.value = options.order;
fields.order.hidden = true;
} }
if (options.currency) { if (options.currency) {