Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barcode logging #8150

Merged
merged 47 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1a22e8a
Add model for recording barcode scan results
SchrodingersGat Sep 20, 2024
9411757
Add "admin" interface for new model
SchrodingersGat Sep 20, 2024
3bc7954
Add API endpoints for barcode scan history
SchrodingersGat Sep 20, 2024
a2513bb
Add global setting to control barcode result save
SchrodingersGat Sep 20, 2024
3b37a07
Add frontend API endpoint
SchrodingersGat Sep 20, 2024
ad6405a
Add PUI table in "admin center"
SchrodingersGat Sep 20, 2024
4809877
Add API filter class
SchrodingersGat Sep 20, 2024
c56c077
Enable table filtering
SchrodingersGat Sep 20, 2024
58d8b28
Update model definition
SchrodingersGat Sep 20, 2024
d00160c
Allow more characters for barcode log
SchrodingersGat Sep 20, 2024
e6330bf
Log results to server
SchrodingersGat Sep 20, 2024
5494fff
Add setting to control how long results are stored
SchrodingersGat Sep 20, 2024
bdeef1f
Table updates
SchrodingersGat Sep 20, 2024
b0e67cf
Add background task to delete old barcode scans
SchrodingersGat Sep 20, 2024
11ef9d0
Add detail drawer for barcode scan
SchrodingersGat Sep 20, 2024
99fdd32
Log messages for BarcodePOReceive
SchrodingersGat Sep 20, 2024
56109bd
Add warning message if barcode logging is not enabled
SchrodingersGat Sep 20, 2024
9a91827
Add "context" data to BarcodeScanResult
SchrodingersGat Sep 20, 2024
09e2ed0
Display context data (if available)
SchrodingersGat Sep 20, 2024
d567f48
Add context data when scanning
SchrodingersGat Sep 20, 2024
1449dab
Simplify / refactor BarcodeSOAllocate
SchrodingersGat Sep 20, 2024
0d068ed
Refactor BarcodePOAllocate
SchrodingersGat Sep 20, 2024
53ec320
Limit the number of saved scans
SchrodingersGat Sep 20, 2024
c7b60f0
Improve error message display in PUI
SchrodingersGat Sep 20, 2024
29b5ea3
Simplify barcode logging
SchrodingersGat Sep 20, 2024
2028bd2
Improve table
SchrodingersGat Sep 20, 2024
be9b2f1
Updates
SchrodingersGat Sep 20, 2024
760756b
Settings page fix
SchrodingersGat Sep 20, 2024
c4341af
Fix panel tooltips
SchrodingersGat Sep 20, 2024
df8ddaa
Adjust table
SchrodingersGat Sep 20, 2024
f4f9641
Add "result" field
SchrodingersGat Sep 21, 2024
08adcb8
Refactor calls to "log_scan"
SchrodingersGat Sep 21, 2024
23843d7
Display result in PUI table
SchrodingersGat Sep 21, 2024
a0a9352
Merge branch 'master' into barcode-log
SchrodingersGat Sep 21, 2024
f5889db
Merge remote-tracking branch 'origin/master' into barcode-log
SchrodingersGat Sep 21, 2024
5500b51
Updates
SchrodingersGat Sep 22, 2024
47a68f6
Fix typo
SchrodingersGat Sep 22, 2024
58a80b8
Update unit test
SchrodingersGat Sep 22, 2024
282b7b1
Improve exception handling
SchrodingersGat Sep 22, 2024
9aa0e01
Unit test updates
SchrodingersGat Sep 22, 2024
92ad4f3
Merge remote-tracking branch 'origin/master' into barcode-log
SchrodingersGat Sep 22, 2024
56a104a
Enhanced unit test
SchrodingersGat Sep 23, 2024
5b5f235
Ensure all database key config values are upper case
SchrodingersGat Sep 23, 2024
bbcbc86
Refactor some playwright helpers
SchrodingersGat Sep 23, 2024
fb00a75
Adds playwright test for barcode scan history table
SchrodingersGat Sep 23, 2024
678fd0b
Requires some timeout
SchrodingersGat Sep 23, 2024
40b0edd
Add docs
SchrodingersGat Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/docs/settings/global.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Configuration of barcode functionality:
{{ globalsetting("BARCODE_WEBCAM_SUPPORT") }}
{{ globalsetting("BARCODE_SHOW_TEXT") }}
{{ globalsetting("BARCODE_GENERATION_PLUGIN") }}
{{ globalsetting("BARCODE_STORE_RESULTS") }}
{{ globalsetting("BARCODE_RESULTS_MAX_NUM") }}

### Pricing and Currency

Expand Down
4 changes: 4 additions & 0 deletions src/backend/InvenTree/InvenTree/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,9 @@ class RetrieveUpdateDestroyAPI(CleanMixin, generics.RetrieveUpdateDestroyAPIView
"""View for retrieve, update and destroy API."""


class RetrieveDestroyAPI(generics.RetrieveDestroyAPIView):
"""View for retrieve and destroy API."""


class UpdateAPI(CleanMixin, generics.UpdateAPIView):
"""View for update API."""
9 changes: 9 additions & 0 deletions src/backend/InvenTree/common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ def formfield_for_dbfield(self, db_field, request, **kwargs):
search_fields = ('content_type', 'comment')


@admin.register(common.models.BarcodeScanResult)
class BarcodeScanResultAdmin(admin.ModelAdmin):
"""Admin interface for BarcodeScanResult objects."""

list_display = ('data', 'timestamp', 'user', 'endpoint')

list_filter = ('user', 'endpoint')


@admin.register(common.models.ProjectCode)
class ProjectCodeAdmin(ImportExportModelAdmin):
"""Admin settings for ProjectCode."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.15 on 2024-09-20 13:15

import InvenTree.models
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('common', '0029_inventreecustomuserstatemodel'),
]

operations = [
migrations.CreateModel(
name='BarcodeScanResult',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('data', models.CharField(help_text='Barcode data', max_length=250, verbose_name='Data')),
('timestamp', models.DateTimeField(auto_now_add=True, help_text='Date and time of the barcode scan', verbose_name='Timestamp')),
('endpoint', models.CharField(blank=True, help_text='URL endpoint which processed the barcode', max_length=250, null=True, verbose_name='Path')),
('context', models.JSONField(blank=True, help_text='Context data for the barcode scan', max_length=1000, null=True, verbose_name='Context')),
('response', models.JSONField(blank=True, help_text='Response data from the barcode scan', max_length=1000, null=True, verbose_name='Response')),
('user', models.ForeignKey(blank=True, help_text='User who scanned the barcode', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='User')),
],
options={
'verbose_name': 'Barcode Scan',
},
bases=(InvenTree.models.PluginValidationMixin, models.Model),
),
]
71 changes: 71 additions & 0 deletions src/backend/InvenTree/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import build.validators
import common.currency
import common.validators
import InvenTree.exceptions
import InvenTree.fields
import InvenTree.helpers
import InvenTree.models
Expand Down Expand Up @@ -1398,6 +1399,18 @@ def save(self, *args, **kwargs):
'default': True,
'validator': bool,
},
'BARCODE_STORE_RESULTS': {
'name': _('Store Barcode Results'),
'description': _('Store barcode scan results in the database'),
'default': False,
'validator': bool,
},
'BARCODE_RESULTS_MAX_NUM': {
'name': _('Barcode Scans Maximum Count'),
'description': _('Maximum number of barcode scan results to store'),
'default': 100,
'validator': [int, MinValueValidator(1)],
},
'BARCODE_INPUT_DELAY': {
'name': _('Barcode Input Delay'),
'description': _('Barcode input processing delay time'),
Expand Down Expand Up @@ -3445,3 +3458,61 @@ def clean(self) -> None:
})

return super().clean()


class BarcodeScanResult(InvenTree.models.InvenTreeModel):
"""Model for storing barcode scans results."""

BARCODE_SCAN_MAX_LEN = 250

class Meta:
"""Model meta options."""

verbose_name = _('Barcode Scan')

data = models.CharField(
max_length=BARCODE_SCAN_MAX_LEN,
verbose_name=_('Data'),
help_text=_('Barcode data'),
blank=False,
null=False,
)

user = models.ForeignKey(
User,
on_delete=models.SET_NULL,
blank=True,
null=True,
verbose_name=_('User'),
help_text=_('User who scanned the barcode'),
)

timestamp = models.DateTimeField(
auto_now_add=True,
verbose_name=_('Timestamp'),
help_text=_('Date and time of the barcode scan'),
)

endpoint = models.CharField(
max_length=250,
verbose_name=_('Path'),
help_text=_('URL endpoint which processed the barcode'),
blank=True,
null=True,
)

context = models.JSONField(
max_length=1000,
verbose_name=_('Context'),
help_text=_('Context data for the barcode scan'),
blank=True,
null=True,
)

response = models.JSONField(
max_length=1000,
verbose_name=_('Response'),
help_text=_('Response data from the barcode scan'),
blank=True,
null=True,
)
Loading
Loading