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

Report printing refactor #7074

Merged
merged 210 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 135 commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
8e42e08
Adds a new "generic" ReportTemplate model
SchrodingersGat Apr 20, 2024
d4761d0
expose API endpoints
SchrodingersGat Apr 20, 2024
afb0304
Update model / migrations / serializer
SchrodingersGat Apr 20, 2024
54d2dee
Add new mixin class to existing database models
SchrodingersGat Apr 20, 2024
3eea4fa
- Add detail view for report template
SchrodingersGat Apr 21, 2024
05a7d64
Filter report list by provided item IDs
SchrodingersGat Apr 21, 2024
71e7e5f
Create data migration for converting *old* report templates
SchrodingersGat Apr 21, 2024
fd4c000
Ignore internal reports for data migration
SchrodingersGat Apr 21, 2024
168801f
Add report mixin to StockLocation model
SchrodingersGat Apr 21, 2024
38a4866
Provide model choices in admin interface
SchrodingersGat Apr 21, 2024
7df6aae
Offload context data generation to the model classes
SchrodingersGat Apr 21, 2024
08e31da
Remove old report template models
SchrodingersGat Apr 21, 2024
1c464c0
Refactor JS code in CUI
SchrodingersGat Apr 21, 2024
b631a88
Fix for API filtering
SchrodingersGat Apr 21, 2024
afa6d57
Add data migration to delete old models
SchrodingersGat Apr 21, 2024
2dd6e11
Remove dead URL
SchrodingersGat Apr 21, 2024
d9689e4
Updates
SchrodingersGat Apr 21, 2024
63d3844
Construct sample report templates on app start
SchrodingersGat Apr 21, 2024
cf73110
Bump API version
SchrodingersGat Apr 21, 2024
c745d02
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat Apr 21, 2024
6f0e391
Typo fix
SchrodingersGat Apr 21, 2024
7988e5c
Fix incorrect context calls
SchrodingersGat Apr 21, 2024
50e4305
Merge branch 'master' into pui-reports
SchrodingersGat Apr 22, 2024
446c5ea
Add new LabelTemplate model
SchrodingersGat Apr 22, 2024
3804f55
Expose to admin interface
SchrodingersGat Apr 22, 2024
bde6d1f
Add in extra context from existing label models
SchrodingersGat Apr 22, 2024
baa4666
Add migration to create LabelTemplate instances from existing labels
SchrodingersGat Apr 22, 2024
61937e0
Add API endpoints for listing and updating LabelTemplate objects
SchrodingersGat Apr 22, 2024
e967b80
Adjust 'upload_to' path
SchrodingersGat Apr 22, 2024
134e534
Refactor label printing
SchrodingersGat Apr 22, 2024
49a8372
Move default label templates
SchrodingersGat Apr 22, 2024
9852f2c
Update API endpoints
SchrodingersGat Apr 22, 2024
7858e1a
Merge branch 'master' into pui-reports
SchrodingersGat Apr 25, 2024
57f7bac
Update migrations
SchrodingersGat Apr 25, 2024
3676e7e
Handle LookupError in migration
SchrodingersGat Apr 25, 2024
aa6b66a
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat Apr 29, 2024
eba2ee0
Redirect the "label" API endpoint
SchrodingersGat Apr 29, 2024
d1aee5f
Add new model for handling result of template printing
SchrodingersGat Apr 29, 2024
02c2664
Refactor LabelPrinting mixin
SchrodingersGat Apr 29, 2024
8b3a998
Unlink "labels" app entirely
SchrodingersGat Apr 29, 2024
ec23fdb
Fix typo
SchrodingersGat Apr 29, 2024
89a67cd
Record 'plugin' used to generate a particular output
SchrodingersGat Apr 29, 2024
1fc4c94
Fix imports
SchrodingersGat Apr 29, 2024
432a7fc
Generate label print response
SchrodingersGat Apr 29, 2024
1877310
Refactoring label printing in CUI
SchrodingersGat Apr 29, 2024
a9e75c4
add "items" count to TemplateOutput model
SchrodingersGat Apr 29, 2024
f39d6d9
Fix for InvenTreeLabelSheetPlugin
SchrodingersGat Apr 29, 2024
608e109
Remove old "label" app
SchrodingersGat Apr 29, 2024
58c8a02
Make request object optional
SchrodingersGat Apr 29, 2024
97868ce
Fix filename generation
SchrodingersGat Apr 29, 2024
229fb5c
Add help text for "model_type"
SchrodingersGat Apr 29, 2024
bf6eea9
Simplify TemplateTable
SchrodingersGat Apr 29, 2024
35fe645
Tweak TemplateTable
SchrodingersGat Apr 29, 2024
2daa5a9
Get template editor to display template data again
SchrodingersGat Apr 29, 2024
17a915c
Stringify template name
SchrodingersGat Apr 29, 2024
2a12e54
Add hooks to reset plugin state
SchrodingersGat Apr 29, 2024
88b778b
fix context for StockLocation model
SchrodingersGat Apr 29, 2024
40ce04b
Tweak log messages
SchrodingersGat Apr 29, 2024
e565d36
Fix incorrect serializer
SchrodingersGat Apr 29, 2024
d842024
Cleanup TemplateTable
SchrodingersGat Apr 29, 2024
2bb5ed7
Fix broken import
SchrodingersGat Apr 29, 2024
a6950be
Filter by target model type
SchrodingersGat Apr 29, 2024
ebbed40
Merge branch 'master' into pui-reports
SchrodingersGat Apr 29, 2024
924ddf4
Remove manual file operations
SchrodingersGat Apr 30, 2024
52c7343
Update old migrations
SchrodingersGat Apr 30, 2024
89d61c7
Refactor asset / snippet uploading
SchrodingersGat Apr 30, 2024
326f390
Update comments
SchrodingersGat Apr 30, 2024
470a706
Retain original filename when editing templatese
SchrodingersGat Apr 30, 2024
b5a0b01
Cleanup
SchrodingersGat Apr 30, 2024
3cf3ae9
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat Apr 30, 2024
414ca23
Refactor model type filter to use new hook
SchrodingersGat Apr 30, 2024
cb50785
Add placeholder actions for printing labels and reports
SchrodingersGat Apr 30, 2024
0d60955
Improve hookiness
SchrodingersGat Apr 30, 2024
e22710d
Add new ReportOutput class
SchrodingersGat Apr 30, 2024
9d64bba
Report printing works from PUI now!
SchrodingersGat Apr 30, 2024
4c09541
More inspired filename pattern for generated reports
SchrodingersGat Apr 30, 2024
b7b3af9
Fix template preview window
SchrodingersGat Apr 30, 2024
a330b41
Remove outdated task
SchrodingersGat Apr 30, 2024
f910501
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat Apr 30, 2024
6b2e849
Update data migration to use raw SQL
SchrodingersGat May 1, 2024
e53d705
Add more API endpoint defs
SchrodingersGat May 1, 2024
aaff3cb
Adds placeholder API endpoint for label printing
SchrodingersGat May 1, 2024
5889135
Expose plugin field to the printing endpoint
SchrodingersGat May 1, 2024
bb37707
Adds plugin model type
SchrodingersGat May 1, 2024
937ec3e
Hook to print labels
SchrodingersGat May 1, 2024
27b79e3
Refactor action dropdown items
SchrodingersGat May 1, 2024
eff9b1a
Refactor report printing for CUI
SchrodingersGat May 2, 2024
a5e42c9
Refactor label print for CUI
SchrodingersGat May 2, 2024
c6b3629
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 2, 2024
97e1585
Fix migration
SchrodingersGat May 2, 2024
7f55689
Update ModelType dict
SchrodingersGat May 2, 2024
90c6b2b
Merge branch 'master' into pui-reports
SchrodingersGat May 3, 2024
26af44c
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 3, 2024
0bf9189
playwright test fix
SchrodingersGat May 3, 2024
8cede34
Unit test fixes
SchrodingersGat May 3, 2024
22c6381
Fix model ruleset associations
SchrodingersGat May 3, 2024
fb697dc
Fix for report.js
SchrodingersGat May 3, 2024
6c3a1b3
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 5, 2024
b56be87
Add support for "dynamic" fields in metadata.py
SchrodingersGat May 5, 2024
ecfb505
Add in custom fields based on plugin
SchrodingersGat May 5, 2024
a3bbe26
Refactoring
SchrodingersGat May 5, 2024
6e034a3
Reset plugin on form close
SchrodingersGat May 5, 2024
b0cbd1f
Set custom timeout values
SchrodingersGat May 5, 2024
8dda653
Update migration
SchrodingersGat May 5, 2024
a414612
Cleanup
SchrodingersGat May 5, 2024
f6a769e
Implement more printing actions
SchrodingersGat May 5, 2024
82b743f
Reduce timeout
SchrodingersGat May 6, 2024
6a6cf31
Unit test updates
SchrodingersGat May 6, 2024
9d270be
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 7, 2024
8af0c88
Merge branch 'master' into pui-reports
SchrodingersGat May 9, 2024
c481624
Fix part serializers
SchrodingersGat May 9, 2024
09c0d58
Label printing works in CUI again
SchrodingersGat May 9, 2024
f02c2b6
js linting
SchrodingersGat May 9, 2024
0e7333b
Update <ActionDropdown>
SchrodingersGat May 9, 2024
8921b60
Fix for label printing API endpoint
SchrodingersGat May 9, 2024
847dfa6
Fix filterselectdrawer
SchrodingersGat May 9, 2024
6129021
Improve button rendering
SchrodingersGat May 9, 2024
d137829
Allow printing from StockLocationTable
SchrodingersGat May 9, 2024
c8c360a
Add aria-labels to modal form fields
SchrodingersGat May 9, 2024
7a74f5e
Add test for printing stock item labels from table
SchrodingersGat May 9, 2024
6cba780
Add test for report printing
SchrodingersGat May 9, 2024
e854b86
Add unit testing for report template editing / preview
SchrodingersGat May 9, 2024
88f9d59
Message refactor
SchrodingersGat May 9, 2024
956e93c
Refactor InvenTreeReportMixin class
SchrodingersGat May 9, 2024
6ebedc7
Update playwright test
SchrodingersGat May 10, 2024
ca73867
Update 'verbose_name' for a number of models
SchrodingersGat May 10, 2024
d6c6715
Additional admin filtering
SchrodingersGat May 10, 2024
d3136da
Playwright test updates
SchrodingersGat May 10, 2024
7257464
Run checks against new python lib branch
SchrodingersGat May 10, 2024
2a2451b
remove old app reference
matmair May 10, 2024
bed64b9
fix testing ref
matmair May 10, 2024
891220d
fix app init
matmair May 10, 2024
bd938ce
remove old tests
matmair May 10, 2024
7032ab3
Revert custom target branch
SchrodingersGat May 11, 2024
fbe3be4
Expose label and report output objects to API
SchrodingersGat May 11, 2024
9349781
refactor
SchrodingersGat May 12, 2024
e71ca54
fix a few tests
matmair May 13, 2024
9c13dcc
factor plugin_ref out
matmair May 13, 2024
4b5d70a
fix options testing
matmair May 13, 2024
45d56e1
Merge branch 'master' into pui-reports
SchrodingersGat May 13, 2024
e8b803a
Update table field header
SchrodingersGat May 13, 2024
afc66d4
Merge branch 'pui-reports' of github.com:SchrodingersGat/InvenTree in…
SchrodingersGat May 13, 2024
70504fa
re-enable full options testing
matmair May 14, 2024
9b9035c
fix missing plugin matching
matmair May 14, 2024
5908149
disable call assert
matmair May 14, 2024
d2d62b4
Add custom related field for PluginConfig
SchrodingersGat May 14, 2024
aeae153
Add support for custom pk field in metadata
SchrodingersGat May 14, 2024
d7994b1
switch to labels for testing
matmair May 14, 2024
0807e85
re-align report testing code
matmair May 14, 2024
070724b
disable version check
matmair May 14, 2024
e38818e
Merge branch 'pr/SchrodingersGat/7074' into 7074-testing
matmair May 14, 2024
8581aea
fix url
matmair May 14, 2024
a5c6a20
Implement lazy loading
SchrodingersGat May 14, 2024
121863b
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 15, 2024
9d1fe1f
Allow blank plugin for printing
SchrodingersGat May 15, 2024
e9101fe
Add printing actions for StockItem
SchrodingersGat May 15, 2024
9b50705
Fix for metadata helper
SchrodingersGat May 15, 2024
a2287ef
Use key instead of pk in printing actions
SchrodingersGat May 15, 2024
15e4be4
Support non-standard pk values in RelatedModelField
SchrodingersGat May 15, 2024
f9e5128
pass context data to report serializers
matmair May 15, 2024
3dc7750
disable template / item discovery
matmair May 15, 2024
23dbf10
fix call
matmair May 15, 2024
1f2a3fb
Tweak unit test
SchrodingersGat May 15, 2024
ce25b64
Run python checks against specific branch
SchrodingersGat May 15, 2024
a5ad2d7
Add task for running docs server
SchrodingersGat May 15, 2024
f666234
Custom branch no longer needed
SchrodingersGat May 15, 2024
a62a790
Merge branch 'pr/SchrodingersGat/7074' into 7074-testing
matmair May 15, 2024
91d4985
Starting on documentation updates
SchrodingersGat May 15, 2024
a9bda1c
Merge pull request #3 from matmair/7074-testing
SchrodingersGat May 15, 2024
ba8c397
fix tests for reports
matmair May 15, 2024
764895f
fix label testing
matmair May 16, 2024
7e5d4c5
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair May 16, 2024
f84910a
Merge branch 'master' into pui-reports
SchrodingersGat May 16, 2024
07e601f
Update template context variables
SchrodingersGat May 16, 2024
7ce5188
Refactor report context documentation
SchrodingersGat May 16, 2024
e7b84ae
Documentation cleanup
SchrodingersGat May 16, 2024
9dc2122
Docs cleanup
SchrodingersGat May 16, 2024
42415e6
Include sample report files
SchrodingersGat May 16, 2024
3a15e34
Fix links
SchrodingersGat May 16, 2024
60ea32c
Link cleanup
SchrodingersGat May 16, 2024
7ad234f
Integrate plugin example code into docs
SchrodingersGat May 16, 2024
6ec2ee6
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 16, 2024
2dfce1f
Code cleanup
SchrodingersGat May 16, 2024
0489ac9
Fix type annotation
SchrodingersGat May 16, 2024
e63528b
Merge branch 'master' into pui-reports
SchrodingersGat May 17, 2024
9fb26c5
Revert deleted variable
SchrodingersGat May 17, 2024
836567e
remove templatetype
SchrodingersGat May 17, 2024
708b200
remove unused imports
SchrodingersGat May 17, 2024
0ceebea
extend context testing
matmair May 17, 2024
a3bf3d1
Merge branch 'pui-reports' of https://github.com/schrodingersgat/inve…
matmair May 17, 2024
d2616a8
test if plg can print
matmair May 17, 2024
c96f594
re-enable version check
matmair May 17, 2024
f3caa05
Merge branch 'pui-reports' of github.com:SchrodingersGat/InvenTree in…
SchrodingersGat May 19, 2024
51cf611
Merge branch 'master' into pui-reports
SchrodingersGat May 19, 2024
88d1803
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 20, 2024
b5b8224
Update unit tests
SchrodingersGat May 20, 2024
e938e37
Fix test
SchrodingersGat May 20, 2024
5d8cb2a
Adjust unit test
SchrodingersGat May 20, 2024
70e35f4
Add debug statement to test
SchrodingersGat May 20, 2024
99991a8
Fix unit test
SchrodingersGat May 20, 2024
421e973
Unit test update
SchrodingersGat May 20, 2024
31229e3
Unit test updates
SchrodingersGat May 20, 2024
f91f31f
Merge remote-tracking branch 'origin/master' into pui-reports
SchrodingersGat May 21, 2024
3b844f6
Test update
SchrodingersGat May 21, 2024
528c687
Patch fix for <PartColumn> component
SchrodingersGat May 21, 2024
79392a7
Fix ReportSerialierBase class
SchrodingersGat May 21, 2024
bc194b8
Fix unit test for sqlite
SchrodingersGat May 21, 2024
1da0b30
Fix kwargs for non-blocking label printing
SchrodingersGat May 21, 2024
aaeda32
Update playwright tests
SchrodingersGat May 21, 2024
07ca9a1
Tweak unit test
SchrodingersGat May 21, 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
7 changes: 6 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""InvenTree API version information."""

# InvenTree API version
INVENTREE_API_VERSION = 196
INVENTREE_API_VERSION = 197
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""

INVENTREE_API_TEXT = """

v197 - 2024-05-05 : https://github.com/inventree/InvenTree/pull/7074
- Major refactor of the report template / report printing interface
- This is a *breaking change* to the report template API
- All report printing has now been simplified to a single set of API endpoints

v196 - 2024-05-05 : https://github.com/inventree/InvenTree/pull/7160
- Adds "location" field to BuildOutputComplete API endpoint

Expand Down
10 changes: 9 additions & 1 deletion src/backend/InvenTree/InvenTree/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
obsolete = [
'InvenTree.tasks.delete_expired_sessions',
'stock.tasks.delete_old_stock_items',
'label.tasks.cleanup_old_label_outputs',
]

try:
Expand All @@ -83,7 +84,14 @@

# Remove any existing obsolete tasks
try:
Schedule.objects.filter(func__in=obsolete).delete()
obsolete_tasks = Schedule.objects.filter(func__in=obsolete)

if obsolete_tasks.exists():
logger.info(

Check warning on line 90 in src/backend/InvenTree/InvenTree/apps.py

View check run for this annotation

Codecov / codecov/patch

src/backend/InvenTree/InvenTree/apps.py#L90

Added line #L90 was not covered by tests
'Removing %s obsolete background tasks', obsolete_tasks.count()
)
obsolete_tasks.delete()

Check warning on line 93 in src/backend/InvenTree/InvenTree/apps.py

View check run for this annotation

Codecov / codecov/patch

src/backend/InvenTree/InvenTree/apps.py#L93

Added line #L93 was not covered by tests

except Exception:
logger.exception('Failed to remove obsolete tasks - database not ready')

Expand Down
10 changes: 10 additions & 0 deletions src/backend/InvenTree/InvenTree/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@

serializer_info = super().get_serializer_info(serializer)

# Look for any dynamic fields which were not available when the serializer was instantiated
for field_name in serializer.Meta.fields:
if field_name in serializer_info:
# Already know about this one
continue

if hasattr(serializer, field_name):
field = getattr(serializer, field_name)
serializer_info[field_name] = self.get_field_info(field)

Check warning on line 132 in src/backend/InvenTree/InvenTree/metadata.py

View check run for this annotation

Codecov / codecov/patch

src/backend/InvenTree/InvenTree/metadata.py#L131-L132

Added lines #L131 - L132 were not covered by tests

model_class = None

# Attributes to copy extra attributes from the model to the field (if they don't exist)
Expand Down
20 changes: 20 additions & 0 deletions src/backend/InvenTree/InvenTree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,26 @@
)


class InvenTreeReportMixin(models.Model):
"""A mixin class for adding report generation functionality to a model class.

In addition to exposing the model to the report generation interface,
this mixin provides a hook for providing extra context information to the reports.
"""

class Meta:
"""Metaclass options for this mixin."""

abstract = True

def report_context(self) -> dict:
"""Generate a dict of context data to provide to the reporting framework.

The default implementation returns an empty dict object.
"""
return {}

Check warning on line 1042 in src/backend/InvenTree/InvenTree/models.py

View check run for this annotation

Codecov / codecov/patch

src/backend/InvenTree/InvenTree/models.py#L1042

Added line #L1042 was not covered by tests


class InvenTreeBarcodeMixin(models.Model):
"""A mixin class for adding barcode functionality to a model class.

Expand Down
8 changes: 1 addition & 7 deletions src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
'common.apps.CommonConfig',
'company.apps.CompanyConfig',
'plugin.apps.PluginAppConfig', # Plugin app runs before all apps that depend on the isPluginRegistryLoaded function
'label.apps.LabelConfig',
'order.apps.OrderConfig',
'part.apps.PartConfig',
'report.apps.ReportConfig',
Expand Down Expand Up @@ -434,12 +433,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR.joinpath('templates'),
# Allow templates in the reporting directory to be accessed
MEDIA_ROOT.joinpath('report'),
MEDIA_ROOT.joinpath('label'),
],
'DIRS': [BASE_DIR.joinpath('templates'), MEDIA_ROOT.joinpath('report')],
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
Expand Down
3 changes: 1 addition & 2 deletions src/backend/InvenTree/InvenTree/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import build.api
import common.api
import company.api
import label.api
import machine.api
import order.api
import part.api
Expand Down Expand Up @@ -89,7 +88,7 @@
path('stock/', include(stock.api.stock_api_urls)),
path('build/', include(build.api.build_api_urls)),
path('order/', include(order.api.order_api_urls)),
path('label/', include(label.api.label_api_urls)),
path('label/', include(report.api.label_api_urls)),
path('report/', include(report.api.report_api_urls)),
path('machine/', include(machine.api.machine_api_urls)),
path('user/', include(users.api.user_urls)),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/InvenTree/build/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BuildResource(InvenTreeResource):
# TODO: 2022-05-12 - Need to investigate why this is the case!

class Meta:
"""Metaclass options"""
"""Metaclass options."""
models = Build
skip_unchanged = True
report_skipped = False
Expand Down
2 changes: 1 addition & 1 deletion src/backend/InvenTree/build/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BuildFilter(rest_filters.FilterSet):
"""Custom filterset for BuildList API endpoint."""

class Meta:
"""Metaclass options"""
"""Metaclass options."""
model = Build
fields = [
'parent',
Expand Down
1 change: 1 addition & 0 deletions src/backend/InvenTree/build/migrations/0043_buildline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Migration(migrations.Migration):
],
options={
'unique_together': {('build', 'bom_item')},
'verbose_name': 'Build Order Line Item',
},
),
]
45 changes: 41 additions & 4 deletions src/backend/InvenTree/build/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@
from plugin.events import trigger_event

import part.models
import report.mixins
import stock.models
import users.models


logger = logging.getLogger('inventree')


class Build(InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models.InvenTreeNotesMixin, InvenTree.models.MetadataMixin, InvenTree.models.PluginValidationMixin, InvenTree.models.ReferenceIndexingMixin, MPTTModel):
class Build(
report.mixins.InvenTreeReportMixin,
InvenTree.models.InvenTreeBarcodeMixin,
InvenTree.models.InvenTreeNotesMixin,
InvenTree.models.MetadataMixin,
InvenTree.models.PluginValidationMixin,
InvenTree.models.ReferenceIndexingMixin,
MPTTModel):
"""A Build object organises the creation of new StockItem objects from other existing StockItem objects.

Attributes:
Expand Down Expand Up @@ -139,6 +147,21 @@
'part': _('Build order part cannot be changed')
})

def report_context(self) -> dict:
"""Generate custom report context data."""

return {

Check warning on line 153 in src/backend/InvenTree/build/models.py

View check run for this annotation

Codecov / codecov/patch

src/backend/InvenTree/build/models.py#L153

Added line #L153 was not covered by tests
'build': self,
'part': self.part,
'build_outputs': self.build_outputs.all(),
'line_items': self.build_lines.all(),
'bom_items': self.part.get_bom_items(),
'reference': self.reference,
'quantity': self.quantity,
'title': str(self)
}


@staticmethod
def filterByDate(queryset, min_date, max_date):
"""Filter by 'minimum and maximum date range'.
Expand Down Expand Up @@ -1291,7 +1314,7 @@
build = models.ForeignKey(Build, on_delete=models.CASCADE, related_name='attachments')


class BuildLine(InvenTree.models.InvenTreeModel):
class BuildLine(report.mixins.InvenTreeReportMixin, InvenTree.models.InvenTreeModel):
"""A BuildLine object links a BOMItem to a Build.

When a new Build is created, the BuildLine objects are created automatically.
Expand All @@ -1308,7 +1331,8 @@
"""

class Meta:
"""Model meta options"""
"""Model meta options."""
verbose_name = _('Build Order Line Item')
unique_together = [
('build', 'bom_item'),
]
Expand All @@ -1318,6 +1342,19 @@
"""Return the API URL used to access this model"""
return reverse('api-build-line-list')

def report_context(self):
"""Generate custom report context for this BuildLine object."""

return {

Check warning on line 1348 in src/backend/InvenTree/build/models.py

View check run for this annotation

Codecov / codecov/patch

src/backend/InvenTree/build/models.py#L1348

Added line #L1348 was not covered by tests
'build_line': self,
'build': self.build,
'bom_item': self.bom_item,
'part': self.bom_item.sub_part,
'quantity': self.quantity,
'allocated_quantity': self.allocated_quantity,
'allocations': self.allocations,
}

build = models.ForeignKey(
Build, on_delete=models.CASCADE,
related_name='build_lines', help_text=_('Build object')
Expand Down Expand Up @@ -1384,7 +1421,7 @@
"""

class Meta:
"""Model meta options"""
"""Model meta options."""
unique_together = [
('build_line', 'stock_item', 'install_into'),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,7 @@ <h3>

{% if report_enabled %}
$('#print-build-report').click(function() {
printReports({
items: [{{ build.pk }}],
key: 'build',
url: '{% url "api-build-report-list" %}',
});
printReports('build', [{{ build.pk }}]);
});
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/InvenTree/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def update_news_feed():

# Fetch and parse feed
try:
feed = requests.get(settings.INVENTREE_NEWS_URL)
feed = requests.get(settings.INVENTREE_NEWS_URL, timeout=30)
d = feedparser.parse(feed.content)
except Exception: # pragma: no cover
logger.warning('update_news_feed: Error parsing the newsfeed')
Expand Down
Empty file.
Loading
Loading