diff --git a/docs/docs/report/context_variables.md b/docs/docs/report/context_variables.md index ddd8a8d8d0..af38d594dc 100644 --- a/docs/docs/report/context_variables.md +++ b/docs/docs/report/context_variables.md @@ -69,6 +69,7 @@ Templates (whether for generating [reports](./report.md) or [labels](./labels.md | Model Type | Description | | --- | --- | +| company | A Company instance | | [build](#build-order) | A [Build Order](../manufacturing/build.md) instance | | [buildline](#build-line) | A [Build Order Line Item](../manufacturing/build.md) instance | | [salesorder](#sales-order) | A [Sales Order](../sales/sales_order.md) instance | @@ -78,6 +79,16 @@ Templates (whether for generating [reports](./report.md) or [labels](./labels.md | [stocklocation](#stock-location) | A [StockLocation](../stock/index.md#stock-location) instance | | [part](#part) | A [Part](../part/index.md) instance | +### Company + +When printing a report or label against a Company instance, the following context variables are available: + +{{ report_context("models", "company") }} + +::: company.models.Company.report_context + options: + show_source: True + ### Build Order When printing a report or label against a [Build Order](../manufacturing/build.md) object, the following context variables are available: diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index bb726466ea..93ef2a40cb 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,11 +1,14 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 355 +INVENTREE_API_VERSION = 356 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v356 -> 2025-06-20 : https://github.com/inventree/InvenTree/pull/9817 + - Enable generation of reports against the Company model type + v355 -> 2025-06-20 : https://github.com/inventree/InvenTree/pull/9811 - Removes legacy "PartScheduling" API endpoints diff --git a/src/backend/InvenTree/company/models.py b/src/backend/InvenTree/company/models.py index edf94415d9..333eeb2c36 100644 --- a/src/backend/InvenTree/company/models.py +++ b/src/backend/InvenTree/company/models.py @@ -21,14 +21,12 @@ from taggit.managers import TaggableManager import common.currency import common.models -import common.settings import InvenTree.conversion -import InvenTree.fields import InvenTree.helpers import InvenTree.models import InvenTree.ready -import InvenTree.tasks import InvenTree.validators +import report.mixins from common.currency import currency_code_default from InvenTree.fields import InvenTreeURLField, RoundingDecimalField from order.status_codes import PurchaseOrderStatusGroups @@ -56,9 +54,21 @@ def rename_company_image(instance, filename): return os.path.join(base, fn) +class CompanyReportContext(report.mixins.BaseReportContext): + """Report context for the Company model. + + Attributes: + name: The name of the Company + primary_address: The primary address associated with the Company + """ + + name: str + + class Company( InvenTree.models.InvenTreeAttachmentMixin, InvenTree.models.InvenTreeNotesMixin, + report.mixins.InvenTreeReportMixin, InvenTree.models.InvenTreeMetadataModel, ): """A Company object represents an external company. @@ -102,6 +112,10 @@ class Company( """Return the API URL associated with the Company model.""" return reverse('api-company-list') + def report_context(self) -> CompanyReportContext: + """Generate a dict of context data to provide to the reporting framework.""" + return {'name': self.name} + name = models.CharField( max_length=100, blank=False, diff --git a/src/backend/InvenTree/part/models.py b/src/backend/InvenTree/part/models.py index f97f7a519a..fbfb38ee95 100644 --- a/src/backend/InvenTree/part/models.py +++ b/src/backend/InvenTree/part/models.py @@ -368,7 +368,7 @@ class PartManager(TreeManager): class PartReportContext(report.mixins.BaseReportContext): - """Context for the part model. + """Report context for the Part model. Attributes: bom_items: Query set of all BomItem objects associated with the Part diff --git a/src/frontend/src/pages/company/CompanyDetail.tsx b/src/frontend/src/pages/company/CompanyDetail.tsx index 224ecd78c8..c44515ef3c 100644 --- a/src/frontend/src/pages/company/CompanyDetail.tsx +++ b/src/frontend/src/pages/company/CompanyDetail.tsx @@ -19,6 +19,7 @@ import { ModelType } from '@lib/enums/ModelType'; import { UserRoles } from '@lib/enums/Roles'; import { apiUrl } from '@lib/functions/Api'; import AdminButton from '../../components/buttons/AdminButton'; +import { PrintingActions } from '../../components/buttons/PrintingActions'; import { type DetailsField, DetailsTable @@ -290,6 +291,11 @@ export default function CompanyDetail(props: Readonly) { const companyActions = useMemo(() => { return [ , + ,