2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +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 |
| --- | --- |
| 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:

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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<CompanyDetailProps>) {
const companyActions = useMemo(() => {
return [
<AdminButton model={ModelType.company} id={company.pk} />,
<PrintingActions
modelType={ModelType.company}
items={[company.pk]}
enableReports
/>,
<OptionsActionDropdown
tooltip={t`Company Actions`}
actions={[

View File

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