Skip to content

[Report] Generate single report against selected items #9423

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

Open
SchrodingersGat opened this issue Mar 31, 2025 · 9 comments · May be fixed by #9532
Open

[Report] Generate single report against selected items #9423

SchrodingersGat opened this issue Mar 31, 2025 · 9 comments · May be fixed by #9532
Labels
enhancement This is an suggested enhancement or new feature feature report Report/Label generation
Milestone

Comments

@SchrodingersGat
Copy link
Member

Discussed in #9408

Originally posted by tristanle22 March 30, 2025
I want to select a few stock items and generate a report. In the report, I want to have a table, with each row for each stock item. I can't find a context variable that represents a list of selected stock items.

I'm aware of the built-in "Inventree Test Report" generates a new page for each selected item.

Feature Description

Instead of generating a separate report for each individually selected item (e.g. stock item / order / part), add an option to pass all selected items through to the report context, and then generate a single report from that.

Implementation Ideas

  • Add a "merge" (or similar named) field to the "ReportTemplate" model
  • This allows the report template creator to decide whether the report is generated against a single output, or against all selected outputs

The ReportTemplate model has an existing print method which could be overloaded:

def print(self, items: list, request=None, output=None, **kwargs) -> DataOutput:

Simply replace this iterator:

for instance in items:

@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature feature report Report/Label generation labels Mar 31, 2025
@SchrodingersGat SchrodingersGat added this to the 1.0.0 milestone Mar 31, 2025
@SchrodingersGat
Copy link
Member Author

@tristanle22 FYI

@tristanle22
Copy link

I'm working on this feature. Just have a dump question as I'm not very familiar with the matter :). Currently I'm adding the "merge" field as a Boolean. If the user want to set this field (or any other field) to True in the report template, how would they do it?

@SchrodingersGat
Copy link
Member Author

@tristanle22 great question. Here's a rough sequence of required steps:

  1. Add new field to ReportTemplate model

class ReportTemplate(TemplateUploadMixin, ReportTemplateBase):

  1. Run database migrations (to actually add the new field)

invoke migrate

  1. Expose new field to the API

Add the new field name to the Meta.fields attribute of the ReportTemplateSerializer class

class ReportTemplateSerializer(ReportSerializerBase):

This will ensure that the new field is exposed to the API

  1. Add the new field to the frontend form

Add your new field name to the additionalFormFields attribute of the ReportTemplateTable component:

That should be sufficient to allow the user to edit this new field. LMK how you go!

@tristanle22
Copy link

Thanks @SchrodingersGat for the instructions! I have followed your steps above. After making the changes, I ran debug with vscode, however, the new field doesn't show up. Is anything else I need to do before running?

From a quick search, this autogenerated field is missing the new field: src/backend/InvenTree/report/migrations/0022_reporttemplate.py. Not sure if it has any signficance.

@SchrodingersGat
Copy link
Member Author

I ran debug with vscode

In vscode you'll need two processes running:

Backend Server

invoke dev.server

Frontend Dev Server (with auto-reload)

invoke dev.frontend-server

And then access at http://localhost:5173

@tristanle22
Copy link

Ah I see. Thanks for your help! I can see the changes in the front end now.

@tristanle22
Copy link

After running dev.setup-test to load the sample dataset, I was able to login to http://localhost:8000 with user 'admin' and pw 'inventree'. However, the same credentials didn't work on http://localhost:5173. Do you have any idea why? @SchrodingersGat

@SchrodingersGat
Copy link
Member Author

Probably due to CORS issues - have a look at the network response in your browser when you try to login.

By default the devcontainer setup should work seamlessly with the localhost:5173 - have you done anything "non-standard" in your setup?

@tristanle22
Copy link

No I didn't do anything "non-standard", beside having to manually install psycopg since it was missing from src/backend/requirements.txt. After restarting the devcontainer docker image, I was able to login to localhost:5173.

@tristanle22 tristanle22 linked a pull request Apr 18, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an suggested enhancement or new feature feature report Report/Label generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants