mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-06 15:28:49 +00:00
* Adds ReturnOrder and ReturnOrderAttachment models * Adds new 'role' specific for return orders * Refactor total_price into a mixin - Required for PurchaseOrder and SalesOrder - May not be required for ReturnOrder (remains to be seen) * Adds API endpoints for ReturnOrder - Add list endpoint - Add detail endpoint - Adds required serializer models * Adds basic "index" page for Return Order model * Update API version * Update navbar text * Add db migration for new "role" * Add ContactList and ContactDetail API endpoints * Adds template and JS code for manipulation of contacts - Display a table - Create / edit / delete * Splits order.js into multiple files - Javascript files was becoming extremely large - Hard to debug and find code - Split into purchase_order / return_order / sales_order * Fix role name (change 'returns' to 'return_order') - Similar to existing roles for purchase_order and sales_order * Adds detail page for ReturnOrder * URL cleanup - Use <int:pk> instead of complex regex * More URL cleanup * Add "return orders" list to company detail page * Break JS status codes into new javascript file - Always difficult to track down where these are rendered - Enough to warrant their own file now * Add ability to edit return order from detail page * Database migrations - Add new ReturnOrder modeles - Add new 'contact' field to external orders * Adds "contact" to ReturnOrder - Implement check to ensure that the selected "contact" matches the selected "company" * Adjust filters to limit contact options * Fix typo * Expose 'contact' field for PurchaseOrder model * Render contact information * Add "contact" for SalesOrder * Adds setting to enable / disable return order functionality - Simply hides the navigation elements - API is not disabled * Support filtering ReturnOrder by 'status' - Refactors existing filter into the OrderFilter class * js linting * More JS linting * Adds ReturnOrderReport model * Add serializer for the ReturnOrderReport model - A little bit of refactoring along the way * Admin integration for new report model * Refactoring for report.api - Adds generic mixins for filtering queryset (based on updates to label.api) - Reduces repeated code a *lot* * Exposes API endpoints for ReturnOrderReport * Adds default example report file for ReturnOrder - Requires some more work :) * Refactor report printing javascript code - Replace all existing functions with 'printReports' * Improvements for default StockItem test report template - Fix bug in template - Handle potential errors in template tags - Add more helpers to report tags - Improve test result rendering * Reduce logging verbosity from weasyprint * Refactor javascript for label printing - Consolidate into a single function - Similar to refactor of report functions * Add report print button to return order page * Record user reference when creating via API * Refactor order serializers - Move common code into AbstractOrderSerializer class * Adds extra line item model for the return order - Adds serializer and API endpoints as appropriate * Render extra line table for return order - Refactor existing functions into a single generic function - Reduces repeated JS code a lot * Add ability to create a new extra line item * Adds button for creating a new lien item * JS linting * Update test * Typo fix (cherry picked from commit 28ac2be35bd0148c598629988d40b1a234f069a5) * Enable search for return order * Don't do pricing (yet) for returnorder extra line table - Fixes an uncaught error * Error catching for api.js * Updates for order models: - Add 'target_date' field to abstract Order model - Add IN_PROGRESS status code for return order - Refactor 'overdue' and 'outstanding' API queries - Refactor OVERDUE_FILTER on order models - Refactor is_overdue on order models - More table filters for return order model * JS cleanup * Create ReturnOrderLineItem model - New type of status label - Add TotalPriceMixin to ReturnOrder model * Adds an API serializer for the ReturnOrderLineItem model * Add API endpoints for ReturnOrderLineItem model - Including some refactoring along the way * javascript: refactor loadTableFilters function - Pass enforced query through to the filters - Call Object.assign() to construct a superset query - Removes a lot of code duplication * Refactor hard-coded URLS to use {% url %} lookup - Forces error if the URL is wrong - If we ever change the URL, will still work * Implement creation of new return order line items * Adds 'part_detail' annotation to ReturnOrderLineItem serializer - Required for rendering part information * javascript: refactor method for creating a group of buttons in a table * javascript: refactor common buttons with helper functions * Allow edit and delete of return order line items * Add form option to automatically reload a table on success - Pass table name to options.refreshTable * JS linting * Add common function for createExtraLineItem * Refactor loading of attachment tables - Setup drag-and-drop as part of core function * CI fixes * Refactoring out some more common API endpoint code * Update migrations * Fix permission typo * Refactor for unit testing code * Add unit tests for Contact model * Tests for returnorder list API * Annotate 'line_items' to ReturnOrder serializer * Driving the refactor tractor * More unit tests for the ReturnOrder API endpoints * Refactor "print orders" button for various order tables - Move into "setupFilterList" code (generic) * add generic 'label printing' button to table actions buttons * Refactor build output table * Refactoring icon generation for js * Refactoring for Part API * Fix database model type for 'received_date' * Add API endpoint to "issue" a ReturnOrder * Improvements for stock tracking table - Add new status codes - Add rendering for SalesOrder - Add rendering for ReturnOrder - Fix status badges * Adds functionality to receive line items against a return order * Add endpoints for completing and cancelling orders * Add option to allow / prevent editing of ReturnOrder after completed * js linting * Wrap "add extra line" button in setting check * Updates to order/admin.py * Remove inline admin for returnorderline model * Updates to pass CI * Serializer fix * order template fixes * Unit test fix * Fixes for ReturnOrder.receive_line_item * Unit testing for receiving line items against an RMA * Improve example report for return order * Extend unit tests for reporting * Cleanup here and there * Unit testing for order views * Clear "sales_order" field when returning against ReturnOrder * Add 'location' to deltas when returning from customer * Bug fix for unit test
1439 lines
39 KiB
JavaScript
1439 lines
39 KiB
JavaScript
{% load i18n %}
|
|
|
|
/* globals
|
|
constructForm,
|
|
imageHoverIcon,
|
|
loadTableFilters,
|
|
renderLink,
|
|
setupFilterList,
|
|
*/
|
|
|
|
/* exported
|
|
createCompany,
|
|
createContact,
|
|
createManufacturerPart,
|
|
createSupplierPart,
|
|
createSupplierPartPriceBreak,
|
|
deleteContacts,
|
|
deleteManufacturerParts,
|
|
deleteManufacturerPartParameters,
|
|
deleteSupplierParts,
|
|
duplicateSupplierPart,
|
|
editCompany,
|
|
editContact,
|
|
editSupplierPartPriceBreak,
|
|
loadCompanyTable,
|
|
loadContactTable,
|
|
loadManufacturerPartTable,
|
|
loadManufacturerPartParameterTable,
|
|
loadSupplierPartTable,
|
|
loadSupplierPriceBreakTable,
|
|
*/
|
|
|
|
|
|
/**
|
|
* Construct a set of form fields for creating / editing a ManufacturerPart
|
|
* @returns
|
|
*/
|
|
function manufacturerPartFields() {
|
|
|
|
return {
|
|
part: {},
|
|
manufacturer: {},
|
|
MPN: {
|
|
icon: 'fa-hashtag',
|
|
},
|
|
description: {},
|
|
link: {
|
|
icon: 'fa-link',
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* Launches a form to create a new ManufacturerPart
|
|
* @param {object} options
|
|
*/
|
|
function createManufacturerPart(options={}) {
|
|
|
|
var fields = manufacturerPartFields();
|
|
|
|
if (options.part) {
|
|
fields.part.value = options.part;
|
|
fields.part.hidden = true;
|
|
}
|
|
|
|
if (options.manufacturer) {
|
|
fields.manufacturer.value = options.manufacturer;
|
|
}
|
|
|
|
fields.manufacturer.secondary = {
|
|
title: '{% trans "Add Manufacturer" %}',
|
|
fields: function() {
|
|
var company_fields = companyFormFields();
|
|
|
|
company_fields.is_manufacturer.value = true;
|
|
|
|
return company_fields;
|
|
}
|
|
};
|
|
|
|
constructForm('{% url "api-manufacturer-part-list" %}', {
|
|
fields: fields,
|
|
method: 'POST',
|
|
title: '{% trans "Add Manufacturer Part" %}',
|
|
onSuccess: options.onSuccess
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Launches a form to edit a ManufacturerPart
|
|
* @param {integer} part - ID of a ManufacturerPart
|
|
* @param {object} options
|
|
*/
|
|
function editManufacturerPart(part, options={}) {
|
|
|
|
var url = `/api/company/part/manufacturer/${part}/`;
|
|
|
|
var fields = manufacturerPartFields();
|
|
|
|
fields.part.hidden = true;
|
|
|
|
constructForm(url, {
|
|
fields: fields,
|
|
title: '{% trans "Edit Manufacturer Part" %}',
|
|
onSuccess: options.onSuccess
|
|
});
|
|
}
|
|
|
|
|
|
function supplierPartFields(options={}) {
|
|
|
|
var fields = {
|
|
part: {
|
|
filters: {
|
|
purchaseable: true,
|
|
}
|
|
},
|
|
manufacturer_part: {
|
|
filters: {
|
|
part_detail: true,
|
|
manufacturer_detail: true,
|
|
},
|
|
auto_fill: true,
|
|
},
|
|
supplier: {},
|
|
SKU: {
|
|
icon: 'fa-hashtag',
|
|
},
|
|
description: {},
|
|
link: {
|
|
icon: 'fa-link',
|
|
},
|
|
note: {
|
|
icon: 'fa-sticky-note',
|
|
},
|
|
packaging: {
|
|
icon: 'fa-box',
|
|
},
|
|
pack_size: {},
|
|
};
|
|
|
|
if (options.part) {
|
|
fields.manufacturer_part.filters.part = options.part;
|
|
}
|
|
|
|
return fields;
|
|
}
|
|
|
|
/*
|
|
* Launch a form to create a new SupplierPart
|
|
*/
|
|
function createSupplierPart(options={}) {
|
|
|
|
var fields = supplierPartFields({
|
|
part: options.part,
|
|
});
|
|
|
|
if (options.part) {
|
|
fields.part.hidden = true;
|
|
fields.part.value = options.part;
|
|
}
|
|
|
|
if (options.supplier) {
|
|
fields.supplier.value = options.supplier;
|
|
}
|
|
|
|
if (options.manufacturer_part) {
|
|
fields.manufacturer_part.value = options.manufacturer_part;
|
|
}
|
|
|
|
// Add a secondary modal for the supplier
|
|
fields.supplier.secondary = {
|
|
title: '{% trans "Add Supplier" %}',
|
|
fields: function() {
|
|
var company_fields = companyFormFields();
|
|
|
|
company_fields.is_supplier.value = true;
|
|
|
|
return company_fields;
|
|
}
|
|
};
|
|
|
|
// Add a secondary modal for the manufacturer part
|
|
fields.manufacturer_part.secondary = {
|
|
title: '{% trans "Add Manufacturer Part" %}',
|
|
fields: function(data) {
|
|
var mp_fields = manufacturerPartFields();
|
|
|
|
if (data.part) {
|
|
mp_fields.part.value = data.part;
|
|
mp_fields.part.hidden = true;
|
|
}
|
|
|
|
return mp_fields;
|
|
}
|
|
};
|
|
|
|
var header = '';
|
|
if (options.part) {
|
|
var part_model = {};
|
|
inventreeGet(`{% url "api-part-list" %}${options.part}/.*`, {}, {
|
|
async: false,
|
|
success: function(response) {
|
|
part_model = response;
|
|
}
|
|
});
|
|
header = constructLabel('Base Part', {});
|
|
header += renderPart(part_model);
|
|
header += `<div> </div>`;
|
|
}
|
|
|
|
constructForm('{% url "api-supplier-part-list" %}', {
|
|
fields: fields,
|
|
method: 'POST',
|
|
title: '{% trans "Add Supplier Part" %}',
|
|
onSuccess: options.onSuccess,
|
|
header_html: header,
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Launch a modal form to duplicate an existing SupplierPart instance
|
|
*/
|
|
function duplicateSupplierPart(part, options={}) {
|
|
|
|
var fields = options.fields || supplierPartFields();
|
|
|
|
// Retrieve information for the supplied part
|
|
inventreeGet(`{% url "api-supplier-part-list" %}${part}/`, {}, {
|
|
success: function(data) {
|
|
|
|
// Remove fields which we do not want to duplicate
|
|
delete data['pk'];
|
|
delete data['available'];
|
|
delete data['availability_updated'];
|
|
|
|
constructForm('{% url "api-supplier-part-list" %}', {
|
|
method: 'POST',
|
|
fields: fields,
|
|
title: '{% trans "Duplicate Supplier Part" %}',
|
|
data: data,
|
|
onSuccess: function(response) {
|
|
handleFormSuccess(response, options);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Launch a modal form to edit an existing SupplierPart instance
|
|
*/
|
|
function editSupplierPart(part, options={}) {
|
|
|
|
var fields = options.fields || supplierPartFields();
|
|
|
|
// Hide the "part" field
|
|
if (fields.part) {
|
|
fields.part.hidden = true;
|
|
}
|
|
|
|
constructForm(`{% url "api-supplier-part-list" %}${part}/`, {
|
|
fields: fields,
|
|
title: options.title || '{% trans "Edit Supplier Part" %}',
|
|
onSuccess: options.onSuccess
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Delete one or more SupplierPart objects from the database.
|
|
* - User will be provided with a modal form, showing all the parts to be deleted.
|
|
* - Delete operations are performed sequentialy, not simultaneously
|
|
*/
|
|
function deleteSupplierParts(parts, options={}) {
|
|
|
|
if (parts.length == 0) {
|
|
return;
|
|
}
|
|
|
|
function renderPartRow(sup_part) {
|
|
var part = sup_part.part_detail;
|
|
var thumb = thumbnailImage(part.thumbnail || part.image);
|
|
var supplier = '-';
|
|
var MPN = '-';
|
|
|
|
if (sup_part.supplier_detail) {
|
|
supplier = sup_part.supplier_detail.name;
|
|
}
|
|
|
|
if (sup_part.manufacturer_part_detail) {
|
|
MPN = sup_part.manufacturer_part_detail.MPN;
|
|
}
|
|
|
|
return `
|
|
<tr>
|
|
<td>${thumb} ${part.full_name}</td>
|
|
<td>${sup_part.SKU}</td>
|
|
<td>${supplier}</td>
|
|
<td>${MPN}</td>
|
|
</tr>`;
|
|
}
|
|
|
|
var rows = '';
|
|
var ids = [];
|
|
|
|
parts.forEach(function(sup_part) {
|
|
rows += renderPartRow(sup_part);
|
|
ids.push(sup_part.pk);
|
|
});
|
|
|
|
var html = `
|
|
<div class='alert alert-block alert-danger'>
|
|
{% trans "All selected supplier parts will be deleted" %}
|
|
</div>
|
|
<table class='table table-striped table-condensed'>
|
|
<tr>
|
|
<th>{% trans "Part" %}</th>
|
|
<th>{% trans "SKU" %}</th>
|
|
<th>{% trans "Supplier" %}</th>
|
|
<th>{% trans "MPN" %}</th>
|
|
</tr>
|
|
${rows}
|
|
</table>
|
|
`;
|
|
|
|
constructForm('{% url "api-supplier-part-list" %}', {
|
|
method: 'DELETE',
|
|
multi_delete: true,
|
|
title: '{% trans "Delete Supplier Parts" %}',
|
|
preFormContent: html,
|
|
form_data: {
|
|
items: ids,
|
|
},
|
|
onSuccess: options.success,
|
|
});
|
|
}
|
|
|
|
|
|
/* Construct set of fields for SupplierPartPriceBreak form */
|
|
function supplierPartPriceBreakFields(options={}) {
|
|
let fields = {
|
|
part: {
|
|
hidden: true,
|
|
},
|
|
quantity: {},
|
|
price: {
|
|
icon: 'fa-dollar-sign',
|
|
},
|
|
price_currency: {
|
|
icon: 'fa-coins',
|
|
},
|
|
};
|
|
|
|
return fields;
|
|
}
|
|
|
|
/* Create a new SupplierPartPriceBreak instance */
|
|
function createSupplierPartPriceBreak(part_id, options={}) {
|
|
|
|
let fields = supplierPartPriceBreakFields(options);
|
|
|
|
fields.part.value = part_id;
|
|
|
|
constructForm('{% url "api-part-supplier-price-list" %}', {
|
|
fields: fields,
|
|
method: 'POST',
|
|
fields: fields,
|
|
title: '{% trans "Add Price Break" %}',
|
|
onSuccess: function(response) {
|
|
handleFormSuccess(response, options);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// Returns a default form-set for creating / editing a Company object
|
|
function companyFormFields() {
|
|
|
|
return {
|
|
name: {},
|
|
description: {},
|
|
website: {
|
|
icon: 'fa-globe',
|
|
},
|
|
address: {
|
|
icon: 'fa-envelope',
|
|
},
|
|
currency: {
|
|
icon: 'fa-dollar-sign',
|
|
},
|
|
phone: {
|
|
icon: 'fa-phone',
|
|
},
|
|
email: {
|
|
icon: 'fa-at',
|
|
},
|
|
contact: {
|
|
icon: 'fa-address-card',
|
|
},
|
|
is_supplier: {},
|
|
is_manufacturer: {},
|
|
is_customer: {}
|
|
};
|
|
}
|
|
|
|
|
|
function editCompany(pk, options={}) {
|
|
|
|
var fields = options.fields || companyFormFields();
|
|
|
|
constructForm(
|
|
`/api/company/${pk}/`,
|
|
{
|
|
method: 'PATCH',
|
|
fields: fields,
|
|
reload: true,
|
|
title: '{% trans "Edit Company" %}',
|
|
}
|
|
);
|
|
}
|
|
|
|
/*
|
|
* Launches a form to create a new company.
|
|
* As this can be called from many different contexts,
|
|
* we abstract it here!
|
|
*/
|
|
function createCompany(options={}) {
|
|
|
|
// Default field set
|
|
var fields = options.fields || companyFormFields();
|
|
|
|
constructForm(
|
|
'{% url "api-company-list" %}',
|
|
{
|
|
method: 'POST',
|
|
fields: fields,
|
|
follow: true,
|
|
title: '{% trans "Add new Company" %}',
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
/*
|
|
* Load company listing data into specified table.
|
|
*
|
|
* Args:
|
|
* - table: Table element on the page
|
|
* - url: Base URL for the API query
|
|
* - options: table options.
|
|
*/
|
|
function loadCompanyTable(table, url, options={}) {
|
|
|
|
let params = options.params || {};
|
|
let filters = loadTableFilters('company', params);
|
|
|
|
setupFilterList('company', $(table));
|
|
|
|
var columns = [
|
|
{
|
|
field: 'pk',
|
|
title: 'ID',
|
|
visible: false,
|
|
switchable: false,
|
|
},
|
|
{
|
|
field: 'name',
|
|
title: '{% trans "Company" %}',
|
|
sortable: true,
|
|
switchable: false,
|
|
formatter: function(value, row) {
|
|
var html = imageHoverIcon(row.image) + renderLink(value, row.url);
|
|
|
|
if (row.is_customer) {
|
|
html += `<span title='{% trans "Customer" %}' class='fas fa-user-tie float-right'></span>`;
|
|
}
|
|
|
|
if (row.is_manufacturer) {
|
|
html += `<span title='{% trans "Manufacturer" %}' class='fas fa-industry float-right'></span>`;
|
|
}
|
|
|
|
if (row.is_supplier) {
|
|
html += `<span title='{% trans "Supplier" %}' class='fas fa-building float-right'></span>`;
|
|
}
|
|
|
|
return html;
|
|
}
|
|
},
|
|
{
|
|
field: 'description',
|
|
title: '{% trans "Description" %}',
|
|
},
|
|
{
|
|
field: 'website',
|
|
title: '{% trans "Website" %}',
|
|
formatter: function(value) {
|
|
if (value) {
|
|
return renderLink(value, value);
|
|
}
|
|
return '';
|
|
}
|
|
},
|
|
];
|
|
|
|
if (options.pagetype == 'suppliers') {
|
|
columns.push({
|
|
sortable: true,
|
|
field: 'parts_supplied',
|
|
title: '{% trans "Parts Supplied" %}',
|
|
formatter: function(value, row) {
|
|
return renderLink(value, `/company/${row.pk}/?display=supplier-parts`);
|
|
}
|
|
});
|
|
} else if (options.pagetype == 'manufacturers') {
|
|
columns.push({
|
|
sortable: true,
|
|
field: 'parts_manufactured',
|
|
title: '{% trans "Parts Manufactured" %}',
|
|
formatter: function(value, row) {
|
|
return renderLink(value, `/company/${row.pk}/?display=manufacturer-parts`);
|
|
}
|
|
});
|
|
}
|
|
|
|
$(table).inventreeTable({
|
|
url: url,
|
|
method: 'get',
|
|
queryParams: filters,
|
|
original: params,
|
|
groupBy: false,
|
|
sidePagination: 'server',
|
|
formatNoMatches: function() {
|
|
return '{% trans "No company information found" %}';
|
|
},
|
|
showColumns: true,
|
|
name: options.pagetype || 'company',
|
|
columns: columns,
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Construct a set of form fields for the Contact model
|
|
*/
|
|
function contactFields(options={}) {
|
|
|
|
let fields = {
|
|
company: {
|
|
icon: 'fa-building',
|
|
},
|
|
name: {
|
|
icon: 'fa-user',
|
|
},
|
|
phone: {
|
|
icon: 'fa-phone'
|
|
},
|
|
email: {
|
|
icon: 'fa-at',
|
|
},
|
|
role: {
|
|
icon: 'fa-user-tag',
|
|
},
|
|
};
|
|
|
|
if (options.company) {
|
|
fields.company.value = options.company;
|
|
}
|
|
|
|
return fields;
|
|
}
|
|
|
|
|
|
/*
|
|
* Launches a form to create a new Contact
|
|
*/
|
|
function createContact(options={}) {
|
|
let fields = options.fields || contactFields(options);
|
|
|
|
constructForm('{% url "api-contact-list" %}', {
|
|
method: 'POST',
|
|
fields: fields,
|
|
title: '{% trans "Create New Contact" %}',
|
|
onSuccess: function(response) {
|
|
handleFormSuccess(response, options);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Launches a form to edit an existing Contact
|
|
*/
|
|
function editContact(pk, options={}) {
|
|
let fields = options.fields || contactFields(options);
|
|
|
|
constructForm(`{% url "api-contact-list" %}${pk}/`, {
|
|
fields: fields,
|
|
title: '{% trans "Edit Contact" %}',
|
|
onSuccess: function(response) {
|
|
handleFormSuccess(response, options);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Launches a form to delete one (or more) contacts
|
|
*/
|
|
function deleteContacts(contacts, options={}) {
|
|
|
|
if (contacts.length == 0) {
|
|
return;
|
|
}
|
|
|
|
function renderContact(contact) {
|
|
return `
|
|
<tr>
|
|
<td>${contact.name}</td>
|
|
<td>${contact.email}</td>
|
|
<td>${contact.role}</td>
|
|
</tr>`;
|
|
}
|
|
|
|
let rows = '';
|
|
let ids = [];
|
|
|
|
contacts.forEach(function(contact) {
|
|
rows += renderContact(contact);
|
|
ids.push(contact.pk);
|
|
});
|
|
|
|
let html = `
|
|
<div class='alert alert-block alert-danger'>
|
|
{% trans "All selected contacts will be deleted" %}
|
|
</div>
|
|
<table class='table table-striped table-condensed'>
|
|
<tr>
|
|
<th>{% trans "Name" %}</th>
|
|
<th>{% trans "Email" %}</th>
|
|
<th>{% trans "Role" %}</th>
|
|
</tr>
|
|
${rows}
|
|
</table>`;
|
|
|
|
constructForm('{% url "api-contact-list" %}', {
|
|
method: 'DELETE',
|
|
multi_delete: true,
|
|
title: '{% trans "Delete Contacts" %}',
|
|
preFormContent: html,
|
|
form_data: {
|
|
items: ids,
|
|
},
|
|
onSuccess: function(response) {
|
|
handleFormSuccess(response, options);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Load table listing company contacts
|
|
*/
|
|
function loadContactTable(table, options={}) {
|
|
|
|
var params = options.params || {};
|
|
|
|
var filters = loadTableFilters('contact', params);
|
|
|
|
setupFilterList('contact', $(table), '#filter-list-contacts');
|
|
|
|
$(table).inventreeTable({
|
|
url: '{% url "api-contact-list" %}',
|
|
queryParams: filters,
|
|
original: params,
|
|
idField: 'pk',
|
|
uniqueId: 'pk',
|
|
sidePagination: 'server',
|
|
formatNoMatches: function() {
|
|
return '{% trans "No contacts found" %}';
|
|
},
|
|
showColumns: true,
|
|
name: 'contacts',
|
|
columns: [
|
|
{
|
|
field: 'name',
|
|
title: '{% trans "Name" %}',
|
|
sortable: true,
|
|
switchable: false,
|
|
},
|
|
{
|
|
field: 'phone',
|
|
title: '{% trans "Phone Number" %}',
|
|
sortable: false,
|
|
switchable: true,
|
|
},
|
|
{
|
|
field: 'email',
|
|
title: '{% trans "Email Address" %}',
|
|
sortable: false,
|
|
switchable: true,
|
|
},
|
|
{
|
|
field: 'role',
|
|
title: '{% trans "Role" %}',
|
|
sortable: false,
|
|
switchable: false,
|
|
},
|
|
{
|
|
field: 'actions',
|
|
title: '',
|
|
sortable: false,
|
|
switchable: false,
|
|
visible: options.allow_edit || options.allow_delete,
|
|
formatter: function(value, row) {
|
|
var pk = row.pk;
|
|
|
|
let html = '';
|
|
|
|
if (options.allow_edit) {
|
|
html += makeEditButton('btn-contact-edit', pk, '{% trans "Edit Contact" %}');
|
|
}
|
|
|
|
if (options.allow_delete) {
|
|
html += makeDeleteButton('btn-contact-delete', pk, '{% trans "Delete Contact" %}');
|
|
}
|
|
|
|
return wrapButtons(html);
|
|
}
|
|
}
|
|
],
|
|
onPostBody: function() {
|
|
// Edit button callback
|
|
if (options.allow_edit) {
|
|
$(table).find('.btn-contact-edit').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
editContact(pk, {
|
|
onSuccess: function() {
|
|
$(table).bootstrapTable('refresh');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// Delete button callback
|
|
if (options.allow_delete) {
|
|
$(table).find('.btn-contact-delete').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
|
|
var row = $(table).bootstrapTable('getRowByUniqueId', pk);
|
|
|
|
if (row && row.pk) {
|
|
|
|
deleteContacts([row], {
|
|
onSuccess: function() {
|
|
$(table).bootstrapTable('refresh');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/* Delete one or more ManufacturerPart objects from the database.
|
|
* - User will be provided with a modal form, showing all the parts to be deleted.
|
|
* - Delete operations are performed sequentialy, not simultaneously
|
|
*/
|
|
function deleteManufacturerParts(selections, options={}) {
|
|
|
|
if (selections.length == 0) {
|
|
return;
|
|
}
|
|
|
|
function renderPartRow(man_part, opts={}) {
|
|
var part = man_part.part_detail;
|
|
var thumb = thumbnailImage(part.thumbnail || part.image);
|
|
|
|
return `
|
|
<tr>
|
|
<td>${thumb} ${part.full_name}</td>
|
|
<td>${man_part.MPN}</td>
|
|
<td>${man_part.manufacturer_detail.name}</td>
|
|
</tr>`;
|
|
}
|
|
|
|
var rows = '';
|
|
var ids = [];
|
|
|
|
selections.forEach(function(man_part) {
|
|
rows += renderPartRow(man_part);
|
|
ids.push(man_part.pk);
|
|
});
|
|
|
|
var html = `
|
|
<div class='alert alert-block alert-danger'>
|
|
{% trans "All selected manufacturer parts will be deleted" %}
|
|
</div>
|
|
<table class='table table-striped table-condensed'>
|
|
<tr>
|
|
<th>{% trans "Part" %}</th>
|
|
<th>{% trans "MPN" %}</th>
|
|
<th>{% trans "Manufacturer" %}</th>
|
|
</tr>
|
|
${rows}
|
|
</table>
|
|
`;
|
|
|
|
constructForm('{% url "api-manufacturer-part-list" %}', {
|
|
method: 'DELETE',
|
|
multi_delete: true,
|
|
title: '{% trans "Delete Manufacturer Parts" %}',
|
|
preFormContent: html,
|
|
form_data: {
|
|
items: ids,
|
|
},
|
|
onSuccess: options.success,
|
|
});
|
|
}
|
|
|
|
|
|
function deleteManufacturerPartParameters(selections, options={}) {
|
|
|
|
if (selections.length == 0) {
|
|
return;
|
|
}
|
|
|
|
function renderParam(param) {
|
|
return `
|
|
<tr>
|
|
<td>${param.name}</td>
|
|
<td>${param.units}</td>
|
|
</tr>`;
|
|
}
|
|
|
|
var rows = '';
|
|
var ids = [];
|
|
|
|
selections.forEach(function(param) {
|
|
rows += renderParam(param);
|
|
ids.push(param.pk);
|
|
});
|
|
|
|
var html = `
|
|
<div class='alert alert-block alert-danger'>
|
|
{% trans "All selected parameters will be deleted" %}
|
|
</div>
|
|
<table class='table table-striped table-condensed'>
|
|
<tr>
|
|
<th>{% trans "Name" %}</th>
|
|
<th>{% trans "Value" %}</th>
|
|
</tr>
|
|
${rows}
|
|
</table>
|
|
`;
|
|
|
|
constructForm('{% url "api-manufacturer-part-parameter-list" %}', {
|
|
method: 'DELETE',
|
|
multi_delete: true,
|
|
title: '{% trans "Delete Parameters" %}',
|
|
preFormContent: html,
|
|
form_data: {
|
|
items: ids,
|
|
},
|
|
onSuccess: options.success,
|
|
});
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
* Load manufacturer part table
|
|
*/
|
|
function loadManufacturerPartTable(table, url, options) {
|
|
|
|
// Query parameters
|
|
var params = options.params || {};
|
|
|
|
// Load filters
|
|
var filters = loadTableFilters('manufacturer-part', params);
|
|
|
|
var filterTarget = options.filterTarget || '#filter-list-manufacturer-part';
|
|
|
|
setupFilterList('manufacturer-part', $(table), filterTarget);
|
|
|
|
$(table).inventreeTable({
|
|
url: url,
|
|
method: 'get',
|
|
original: params,
|
|
queryParams: filters,
|
|
uniqueId: 'pk',
|
|
sidePagination: 'server',
|
|
name: 'manufacturerparts',
|
|
groupBy: false,
|
|
formatNoMatches: function() {
|
|
return '{% trans "No manufacturer parts found" %}';
|
|
},
|
|
columns: [
|
|
{
|
|
checkbox: true,
|
|
switchable: false,
|
|
},
|
|
{
|
|
visible: params['part_detail'],
|
|
switchable: params['part_detail'],
|
|
sortable: true,
|
|
field: 'part_detail.full_name',
|
|
title: '{% trans "Part" %}',
|
|
formatter: function(value, row) {
|
|
|
|
var url = `/part/${row.part}/`;
|
|
|
|
var html = imageHoverIcon(row.part_detail.thumbnail) + renderLink(value, url);
|
|
|
|
if (row.part_detail.is_template) {
|
|
html += makeIconBadge('fa-clone', '{% trans "Template part" %}');
|
|
}
|
|
|
|
if (row.part_detail.assembly) {
|
|
html += makeIconBadge('fa-tools', '{% trans "Assembled part" %}');
|
|
}
|
|
|
|
if (!row.part_detail.active) {
|
|
html += `<span class='badge badge-right rounded-pill bg-warning'>{% trans "Inactive" %}</span>`;
|
|
}
|
|
|
|
return html;
|
|
}
|
|
},
|
|
{
|
|
sortable: true,
|
|
field: 'manufacturer',
|
|
title: '{% trans "Manufacturer" %}',
|
|
formatter: function(value, row) {
|
|
if (value && row.manufacturer_detail) {
|
|
var name = row.manufacturer_detail.name;
|
|
var url = `/company/${value}/`;
|
|
var html = imageHoverIcon(row.manufacturer_detail.image) + renderLink(name, url);
|
|
|
|
return html;
|
|
} else {
|
|
return '-';
|
|
}
|
|
}
|
|
},
|
|
{
|
|
sortable: true,
|
|
field: 'MPN',
|
|
title: '{% trans "MPN" %}',
|
|
formatter: function(value, row) {
|
|
return renderLink(value, `/manufacturer-part/${row.pk}/`);
|
|
}
|
|
},
|
|
{
|
|
field: 'link',
|
|
title: '{% trans "Link" %}',
|
|
formatter: function(value) {
|
|
if (value) {
|
|
return renderLink(value, value);
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: 'description',
|
|
title: '{% trans "Description" %}',
|
|
sortable: false,
|
|
switchable: true,
|
|
},
|
|
{
|
|
field: 'actions',
|
|
title: '',
|
|
sortable: false,
|
|
switchable: false,
|
|
formatter: function(value, row) {
|
|
let pk = row.pk;
|
|
let html = '';
|
|
|
|
html += makeEditButton('button-manufacturer-part-edit', pk, '{% trans "Edit manufacturer part" %}');
|
|
html += makeDeleteButton('button-manufacturer-part-delete', pk, '{% trans "Delete manufacturer part" %}');
|
|
|
|
return wrapButtons(html);
|
|
}
|
|
}
|
|
],
|
|
onPostBody: function() {
|
|
// Callbacks
|
|
$(table).find('.button-manufacturer-part-edit').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
|
|
editManufacturerPart(
|
|
pk,
|
|
{
|
|
onSuccess: function() {
|
|
$(table).bootstrapTable('refresh');
|
|
}
|
|
}
|
|
);
|
|
});
|
|
|
|
$(table).find('.button-manufacturer-part-delete').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
var row = $(table).bootstrapTable('getRowByUniqueId', pk);
|
|
|
|
deleteManufacturerParts(
|
|
[row],
|
|
{
|
|
success: function() {
|
|
$(table).bootstrapTable('refresh');
|
|
}
|
|
}
|
|
);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Load table of ManufacturerPartParameter objects
|
|
*/
|
|
function loadManufacturerPartParameterTable(table, url, options) {
|
|
|
|
var params = options.params || {};
|
|
|
|
// Load filters
|
|
var filters = loadTableFilters('manufacturer-part-parameters', params);
|
|
|
|
setupFilterList('manufacturer-part-parameters', $(table));
|
|
|
|
$(table).inventreeTable({
|
|
url: url,
|
|
method: 'get',
|
|
original: params,
|
|
queryParams: filters,
|
|
name: 'manufacturerpartparameters',
|
|
groupBy: false,
|
|
formatNoMatches: function() {
|
|
return '{% trans "No parameters found" %}';
|
|
},
|
|
columns: [
|
|
{
|
|
checkbox: true,
|
|
switchable: false,
|
|
visible: true,
|
|
},
|
|
{
|
|
field: 'name',
|
|
title: '{% trans "Name" %}',
|
|
switchable: false,
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'value',
|
|
title: '{% trans "Value" %}',
|
|
switchable: false,
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'units',
|
|
title: '{% trans "Units" %}',
|
|
switchable: true,
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'actions',
|
|
title: '',
|
|
switchable: false,
|
|
sortable: false,
|
|
formatter: function(value, row) {
|
|
let pk = row.pk;
|
|
let html = '';
|
|
|
|
html += makeEditButton('button-parameter-edit', pk, '{% trans "Edit parameter" %}');
|
|
html += makeDeleteButton('button-parameter-delete', pk, '{% trans "Delete parameter" %}');
|
|
|
|
return wrapButtons(html);
|
|
}
|
|
}
|
|
],
|
|
onPostBody: function() {
|
|
// Setup callback functions
|
|
$(table).find('.button-parameter-edit').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
|
|
constructForm(`{% url "api-manufacturer-part-parameter-list" %}${pk}/`, {
|
|
fields: {
|
|
name: {},
|
|
value: {},
|
|
units: {},
|
|
},
|
|
title: '{% trans "Edit Parameter" %}',
|
|
refreshTable: table,
|
|
});
|
|
});
|
|
$(table).find('.button-parameter-delete').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
|
|
constructForm(`{% url "api-manufacturer-part-parameter-list" %}${pk}/`, {
|
|
method: 'DELETE',
|
|
title: '{% trans "Delete Parameter" %}',
|
|
refreshTable: table,
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Load supplier part table
|
|
*/
|
|
function loadSupplierPartTable(table, url, options) {
|
|
|
|
// Query parameters
|
|
var params = options.params || {};
|
|
|
|
// Load filters
|
|
var filters = loadTableFilters('supplier-part', params);
|
|
|
|
setupFilterList('supplier-part', $(table));
|
|
|
|
$(table).inventreeTable({
|
|
url: url,
|
|
method: 'get',
|
|
original: params,
|
|
sidePagination: 'server',
|
|
uniqueId: 'pk',
|
|
queryParams: filters,
|
|
name: 'supplierparts',
|
|
groupBy: false,
|
|
sortable: true,
|
|
formatNoMatches: function() {
|
|
return '{% trans "No supplier parts found" %}';
|
|
},
|
|
columns: [
|
|
{
|
|
checkbox: true,
|
|
switchable: false,
|
|
},
|
|
{
|
|
visible: params['part_detail'],
|
|
switchable: params['part_detail'],
|
|
sortable: true,
|
|
field: 'part_detail.full_name',
|
|
sortName: 'part',
|
|
title: '{% trans "Part" %}',
|
|
formatter: function(value, row) {
|
|
|
|
var url = `/part/${row.part}/`;
|
|
|
|
var html = imageHoverIcon(row.part_detail.thumbnail) + renderLink(value, url);
|
|
|
|
if (row.part_detail.is_template) {
|
|
html += makeIconBadge('fa-clone', '{% trans "Template part" %}');
|
|
}
|
|
|
|
if (row.part_detail.assembly) {
|
|
html += makeIconBadge('fa-tools', '{% trans "Assembled part" %}');
|
|
}
|
|
|
|
if (!row.part_detail.active) {
|
|
html += `<span class='badge badge-right rounded-pill bg-warning'>{% trans "Inactive" %}</span>`;
|
|
}
|
|
|
|
return html;
|
|
}
|
|
},
|
|
{
|
|
sortable: true,
|
|
field: 'supplier',
|
|
title: '{% trans "Supplier" %}',
|
|
formatter: function(value, row) {
|
|
if (value) {
|
|
var name = row.supplier_detail.name;
|
|
var url = `/company/${value}/`;
|
|
var html = imageHoverIcon(row.supplier_detail.image) + renderLink(name, url);
|
|
|
|
return html;
|
|
} else {
|
|
return '-';
|
|
}
|
|
},
|
|
},
|
|
{
|
|
sortable: true,
|
|
field: 'SKU',
|
|
title: '{% trans "Supplier Part" %}',
|
|
formatter: function(value, row) {
|
|
return renderLink(value, `/supplier-part/${row.pk}/`);
|
|
}
|
|
},
|
|
{
|
|
visible: params['manufacturer_detail'],
|
|
switchable: params['manufacturer_detail'],
|
|
sortable: true,
|
|
sortName: 'manufacturer',
|
|
field: 'manufacturer_detail.name',
|
|
title: '{% trans "Manufacturer" %}',
|
|
formatter: function(value, row) {
|
|
if (value && row.manufacturer_detail) {
|
|
var name = value;
|
|
var url = `/company/${row.manufacturer_detail.pk}/`;
|
|
var html = imageHoverIcon(row.manufacturer_detail.image) + renderLink(name, url);
|
|
|
|
return html;
|
|
} else {
|
|
return '-';
|
|
}
|
|
}
|
|
},
|
|
{
|
|
visible: params['manufacturer_detail'],
|
|
switchable: params['manufacturer_detail'],
|
|
sortable: true,
|
|
sortName: 'MPN',
|
|
field: 'manufacturer_part_detail.MPN',
|
|
title: '{% trans "MPN" %}',
|
|
formatter: function(value, row) {
|
|
if (value && row.manufacturer_part) {
|
|
return renderLink(value, `/manufacturer-part/${row.manufacturer_part}/`);
|
|
} else {
|
|
return '-';
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: 'description',
|
|
title: '{% trans "Description" %}',
|
|
sortable: false,
|
|
},
|
|
{
|
|
field: 'packaging',
|
|
title: '{% trans "Packaging" %}',
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'pack_size',
|
|
title: '{% trans "Pack Quantity" %}',
|
|
sortable: true,
|
|
formatter: function(value, row) {
|
|
var output = `${value}`;
|
|
|
|
if (row.part_detail && row.part_detail.units) {
|
|
output += ` ${row.part_detail.units}`;
|
|
}
|
|
|
|
return output;
|
|
}
|
|
},
|
|
{
|
|
field: 'link',
|
|
sortable: false,
|
|
title: '{% trans "Link" %}',
|
|
formatter: function(value) {
|
|
if (value) {
|
|
return renderLink(value, value);
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: 'note',
|
|
title: '{% trans "Notes" %}',
|
|
sortable: false,
|
|
},
|
|
{
|
|
field: 'in_stock',
|
|
title: '{% trans "In Stock" %}',
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'available',
|
|
title: '{% trans "Availability" %}',
|
|
sortable: true,
|
|
formatter: function(value, row) {
|
|
if (row.availability_updated) {
|
|
let html = formatDecimal(value);
|
|
let date = renderDate(row.availability_updated, {showTime: true});
|
|
|
|
html += makeIconBadge(
|
|
'fa-info-circle',
|
|
`{% trans "Last Updated" %}: ${date}`
|
|
);
|
|
return html;
|
|
} else {
|
|
return '-';
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: 'updated',
|
|
title: '{% trans "Last Updated" %}',
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'actions',
|
|
title: '',
|
|
sortable: false,
|
|
switchable: false,
|
|
formatter: function(value, row) {
|
|
let pk = row.pk;
|
|
let html = '';
|
|
|
|
html += makeEditButton('button-supplier-part-edit', pk, '{% trans "Edit supplier part" %}');
|
|
html += makeDeleteButton('button-supplier-part-delete', pk, '{% trans "Delete supplier part" %}');
|
|
|
|
return wrapButtons(html);
|
|
}
|
|
}
|
|
],
|
|
onPostBody: function() {
|
|
// Callbacks
|
|
$(table).find('.button-supplier-part-edit').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
|
|
editSupplierPart(
|
|
pk,
|
|
{
|
|
onSuccess: function() {
|
|
$(table).bootstrapTable('refresh');
|
|
}
|
|
}
|
|
);
|
|
});
|
|
|
|
$(table).find('.button-supplier-part-delete').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
var row = $(table).bootstrapTable('getRowByUniqueId', pk);
|
|
|
|
deleteSupplierParts(
|
|
[row],
|
|
{
|
|
success: function() {
|
|
$(table).bootstrapTable('refresh');
|
|
}
|
|
}
|
|
);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/*
|
|
* Load a table of supplier price break data
|
|
*/
|
|
function loadSupplierPriceBreakTable(options={}) {
|
|
|
|
var table = options.table || $('#price-break-table');
|
|
|
|
// Setup button callbacks once table is loaded
|
|
function setupCallbacks() {
|
|
table.find('.button-price-break-delete').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
|
|
constructForm(`{% url "api-part-supplier-price-list" %}${pk}/`, {
|
|
method: 'DELETE',
|
|
title: '{% trans "Delete Price Break" %}',
|
|
refreshTable: table,
|
|
});
|
|
});
|
|
|
|
table.find('.button-price-break-edit').click(function() {
|
|
var pk = $(this).attr('pk');
|
|
|
|
constructForm(`{% url "api-part-supplier-price-list" %}${pk}/`, {
|
|
fields: supplierPartPriceBreakFields(),
|
|
title: '{% trans "Edit Price Break" %}',
|
|
refreshTable: table,
|
|
});
|
|
});
|
|
}
|
|
|
|
setupFilterList('supplierpricebreak', table, '#filter-list-supplierpricebreak');
|
|
|
|
table.inventreeTable({
|
|
name: 'buypricebreaks',
|
|
url: '{% url "api-part-supplier-price-list" %}',
|
|
queryParams: {
|
|
part: options.part,
|
|
},
|
|
formatNoMatches: function() {
|
|
return '{% trans "No price break information found" %}';
|
|
},
|
|
onPostBody: function() {
|
|
setupCallbacks();
|
|
},
|
|
columns: [
|
|
{
|
|
field: 'pk',
|
|
title: 'ID',
|
|
visible: false,
|
|
switchable: false,
|
|
},
|
|
{
|
|
field: 'quantity',
|
|
title: '{% trans "Quantity" %}',
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'price',
|
|
title: '{% trans "Price" %}',
|
|
sortable: true,
|
|
formatter: function(value, row, index) {
|
|
return formatCurrency(value, {
|
|
currency: row.price_currency
|
|
});
|
|
}
|
|
},
|
|
{
|
|
field: 'updated',
|
|
title: '{% trans "Last updated" %}',
|
|
sortable: true,
|
|
formatter: function(value, row) {
|
|
var html = renderDate(value);
|
|
|
|
let buttons = '';
|
|
|
|
buttons += makeEditButton('button-price-break-edit', row.pk, '{% trans "Edit price break" %}');
|
|
buttons += makeDeleteButton('button-price-break-delete', row.pk, '{% trans "Delete price break" %}');
|
|
|
|
html += wrapButtons(buttons);
|
|
|
|
return html;
|
|
}
|
|
},
|
|
]
|
|
});
|
|
}
|