mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Barcode Refactor (#3640)
* define a simple model mixin class for barcode * Adds generic function for assigning a barcode to a model instance * StockItem model now implements the BarcodeMixin class * Implement simple unit tests for new code * Fix unit tests * Data migration for uid field * Remove references to old 'uid' field * Migration for removing old uid field from StockItem model * Bump API version * Change lookup_barcode to be a classmethod * Change barcode_model_type to be a class method * Cleanup for generic barcode scan and assign API: - Raise ValidationError as appropriate - Improved unit testing - Groundwork for future generic implementation * Further unit tests for barcode scanning * Adjust error messages for compatibility * Unit test fix * Fix hash_barcode function - Add unit tests to ensure it produces the same results as before the refactor * Add BarcodeMixin to Part model * Remove old format_barcode function from Part model * Further fixes for unit tests * Add support for assigning arbitrary barcode to Part instance - Simplify barcode API - Add more unit tests * More unit test fixes * Update unit test * Adds generic endpoint for unassigning barcode data * Update web dialog for unlinking a barcode * Template cleanup * Add Barcode mixin to StockLocation class * Add some simple unit tests for new model mixin * Support assigning / unassigning barcodes for StockLocation * remove failing outdated test * Update template to integrate new barcode support for StockLocation * Add BarcodeMixin to SupplierPart model * Adds QR code view for SupplierPart * Major simplification of barcode API endpoints - Separate existing barcode plugin into two separate classes - Simplify and consolidate the response from barcode scanning - Update unit testing * Yet more unit test fixes * Yet yet more unit test fixes
This commit is contained in:
@ -352,19 +352,17 @@ function barcodeScanDialog() {
|
||||
|
||||
|
||||
/*
|
||||
* Dialog for linking a particular barcode to a stock item.
|
||||
* Dialog for linking a particular barcode to a database model instsance
|
||||
*/
|
||||
function linkBarcodeDialog(stockitem) {
|
||||
function linkBarcodeDialog(data, options={}) {
|
||||
|
||||
var modal = '#modal-form';
|
||||
|
||||
barcodeDialog(
|
||||
'{% trans "Link Barcode to Stock Item" %}',
|
||||
options.title,
|
||||
{
|
||||
url: '/api/barcode/link/',
|
||||
data: {
|
||||
stockitem: stockitem,
|
||||
},
|
||||
data: data,
|
||||
onScan: function() {
|
||||
|
||||
$(modal).modal('hide');
|
||||
@ -376,13 +374,13 @@ function linkBarcodeDialog(stockitem) {
|
||||
|
||||
|
||||
/*
|
||||
* Remove barcode association from a device.
|
||||
* Remove barcode association from a database model instance.
|
||||
*/
|
||||
function unlinkBarcode(stockitem) {
|
||||
function unlinkBarcode(data, options={}) {
|
||||
|
||||
var html = `<b>{% trans "Unlink Barcode" %}</b><br>`;
|
||||
|
||||
html += '{% trans "This will remove the association between this stock item and the barcode" %}';
|
||||
html += '{% trans "This will remove the link to the associated barcode" %}';
|
||||
|
||||
showQuestionDialog(
|
||||
'{% trans "Unlink Barcode" %}',
|
||||
@ -391,13 +389,10 @@ function unlinkBarcode(stockitem) {
|
||||
accept_text: '{% trans "Unlink" %}',
|
||||
accept: function() {
|
||||
inventreePut(
|
||||
`/api/stock/${stockitem}/`,
|
||||
'/api/barcode/unlink/',
|
||||
data,
|
||||
{
|
||||
// Clear the UID field
|
||||
uid: '',
|
||||
},
|
||||
{
|
||||
method: 'PATCH',
|
||||
method: 'POST',
|
||||
success: function() {
|
||||
location.reload();
|
||||
},
|
||||
|
Reference in New Issue
Block a user