2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 19:20:55 +00:00

Company reports (#9817)

* Support report generation against company

* Add "print report" to Company table

* Add printing button to Company detail page

* Bump API version
This commit is contained in:
Oliver
2025-06-20 17:52:07 +10:00
committed by GitHub
parent 6229d2e8c8
commit 499e48cdd8
6 changed files with 41 additions and 5 deletions

View File

@ -69,6 +69,7 @@ Templates (whether for generating [reports](./report.md) or [labels](./labels.md
| Model Type | Description | | Model Type | Description |
| --- | --- | | --- | --- |
| company | A Company instance |
| [build](#build-order) | A [Build Order](../manufacturing/build.md) instance | | [build](#build-order) | A [Build Order](../manufacturing/build.md) instance |
| [buildline](#build-line) | A [Build Order Line Item](../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 | | [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 | | [stocklocation](#stock-location) | A [StockLocation](../stock/index.md#stock-location) instance |
| [part](#part) | A [Part](../part/index.md) 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 ### Build Order
When printing a report or label against a [Build Order](../manufacturing/build.md) object, the following context variables are available: When printing a report or label against a [Build Order](../manufacturing/build.md) object, the following context variables are available:

View File

@ -1,11 +1,14 @@
"""InvenTree API version information.""" """InvenTree API version information."""
# InvenTree API version # 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.""" """Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """ 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 v355 -> 2025-06-20 : https://github.com/inventree/InvenTree/pull/9811
- Removes legacy "PartScheduling" API endpoints - Removes legacy "PartScheduling" API endpoints

View File

@ -21,14 +21,12 @@ from taggit.managers import TaggableManager
import common.currency import common.currency
import common.models import common.models
import common.settings
import InvenTree.conversion import InvenTree.conversion
import InvenTree.fields
import InvenTree.helpers import InvenTree.helpers
import InvenTree.models import InvenTree.models
import InvenTree.ready import InvenTree.ready
import InvenTree.tasks
import InvenTree.validators import InvenTree.validators
import report.mixins
from common.currency import currency_code_default from common.currency import currency_code_default
from InvenTree.fields import InvenTreeURLField, RoundingDecimalField from InvenTree.fields import InvenTreeURLField, RoundingDecimalField
from order.status_codes import PurchaseOrderStatusGroups from order.status_codes import PurchaseOrderStatusGroups
@ -56,9 +54,21 @@ def rename_company_image(instance, filename):
return os.path.join(base, fn) 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( class Company(
InvenTree.models.InvenTreeAttachmentMixin, InvenTree.models.InvenTreeAttachmentMixin,
InvenTree.models.InvenTreeNotesMixin, InvenTree.models.InvenTreeNotesMixin,
report.mixins.InvenTreeReportMixin,
InvenTree.models.InvenTreeMetadataModel, InvenTree.models.InvenTreeMetadataModel,
): ):
"""A Company object represents an external company. """A Company object represents an external company.
@ -102,6 +112,10 @@ class Company(
"""Return the API URL associated with the Company model.""" """Return the API URL associated with the Company model."""
return reverse('api-company-list') 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( name = models.CharField(
max_length=100, max_length=100,
blank=False, blank=False,

View File

@ -368,7 +368,7 @@ class PartManager(TreeManager):
class PartReportContext(report.mixins.BaseReportContext): class PartReportContext(report.mixins.BaseReportContext):
"""Context for the part model. """Report context for the Part model.
Attributes: Attributes:
bom_items: Query set of all BomItem objects associated with the Part bom_items: Query set of all BomItem objects associated with the Part

View File

@ -19,6 +19,7 @@ import { ModelType } from '@lib/enums/ModelType';
import { UserRoles } from '@lib/enums/Roles'; import { UserRoles } from '@lib/enums/Roles';
import { apiUrl } from '@lib/functions/Api'; import { apiUrl } from '@lib/functions/Api';
import AdminButton from '../../components/buttons/AdminButton'; import AdminButton from '../../components/buttons/AdminButton';
import { PrintingActions } from '../../components/buttons/PrintingActions';
import { import {
type DetailsField, type DetailsField,
DetailsTable DetailsTable
@ -290,6 +291,11 @@ export default function CompanyDetail(props: Readonly<CompanyDetailProps>) {
const companyActions = useMemo(() => { const companyActions = useMemo(() => {
return [ return [
<AdminButton model={ModelType.company} id={company.pk} />, <AdminButton model={ModelType.company} id={company.pk} />,
<PrintingActions
modelType={ModelType.company}
items={[company.pk]}
enableReports
/>,
<OptionsActionDropdown <OptionsActionDropdown
tooltip={t`Company Actions`} tooltip={t`Company Actions`}
actions={[ actions={[

View File

@ -169,6 +169,8 @@ export function CompanyTable({
tableFilters: tableFilters, tableFilters: tableFilters,
tableActions: tableActions, tableActions: tableActions,
enableDownload: true, enableDownload: true,
enableSelection: true,
enableReports: true,
rowActions: rowActions rowActions: rowActions
}} }}
/> />