Skip to content

Commit

Permalink
Merge branch 'master' into pui-add-startpage-to-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair authored Aug 26, 2024
2 parents 0228199 + d1c8354 commit 4e7fca7
Show file tree
Hide file tree
Showing 105 changed files with 3,974 additions and 1,924 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ permissions:
contents: read

jobs:
build:
synchronize-with-crowdin:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -39,16 +40,29 @@ jobs:
apt-dependency: gettext
- name: Make Translations
run: invoke translate
- name: Commit files
- name: Remove compiled static files
run: rm -rf src/backend/InvenTree/static
- name: Remove all local changes that are not *.po files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout -b l10_local
git add "*.po"
git commit -m "updated translation base"
- name: Push changes
uses: ad-m/github-push-action@d91a481090679876dfc4178fef17f286781251df # [email protected]
git add src/backend/InvenTree/locale/en/LC_MESSAGES/django.po src/frontend/src/locales/en/messages.po
git commit -m "add translations"
git reset --hard
git reset HEAD~
- name: crowdin action
uses: crowdin/github-action@6ed209d411599a981ccb978df3be9dc9b8a81699 # pin@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: l10
force: true
upload_sources: true
upload_translations: false
download_translations: true
localization_branch_name: l10_crowdin
create_pull_request: true
pull_request_title: 'New Crowdin updates'
pull_request_body: 'New Crowdin translations by [Crowdin GH Action](https://github.com/crowdin/github-action)'
pull_request_base_branch_name: 'l10'
pull_request_labels: 'translations'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
1 change: 1 addition & 0 deletions contrib/container/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gunicorn>=22.0.0
# LDAP required packages
django-auth-ldap # Django integration for ldap auth
python-ldap # LDAP auth support
django<5.0 # Force lower to match main project

# Upgraded python package installer
uv
315 changes: 154 additions & 161 deletions contrib/container/requirements.txt

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contrib/dev_reqs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ jc==1.25.3 \
--hash=sha256:ea17a8578497f2da92f73924d9d403f4563ba59422fbceff7bb4a16cdf84a54f \
--hash=sha256:fa3140ceda6cba1210d1362f363cd79a0514741e8a1dd6167db2b2e2d5f24f7b
# via -r contrib/dev_reqs/requirements.in
pygments==2.17.2 \
--hash=sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c \
--hash=sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367
pygments==2.18.0 \
--hash=sha256:786ff802f32e91311bff3889f6e9a86e81505fe99f2735bb6d60ae0c5004f199 \
--hash=sha256:b8e6aca0523f3ab76fee51799c488e38782ac06eafcf95e7ba832985c8e7b13a
# via jc
pyyaml==6.0.2 \
--hash=sha256:01179a4a8559ab5de078078f37e5c1a30d76bb88519906844fd7bdea1b7729ff \
Expand Down
6 changes: 6 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Configuration file for Crowdin project integration
# See: https://crowdin.com/project/inventree

"commit_message": "Fix: New translations %original_file_name% from Crowdin"
"append_commit_message": false
"preserve_hierarchy": true

files:
- source: /src/backend/InvenTree/locale/en/LC_MESSAGES/django.po
dest: /%original_path%/%original_file_name%
translation: /src/backend/InvenTree/locale/%two_letters_code%/LC_MESSAGES/%original_file_name%
- source: /src/frontend/src/locales/en/messages.po
dest: /%original_path%/%original_file_name%
translation: /src/frontend/src/locales/%two_letters_code%/%original_file_name%
15 changes: 15 additions & 0 deletions docs/docs/concepts/custom_states.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Custom States
---

## Custom States

Several models within InvenTree support the use of custom states. The custom states are display only - the business logic is not affected by the state.

States can be added in the Admin Center under the "Custom States" section. Each state has a name, label and a color that are used to display the state in the user interface. Changes to these settings will only be reflected in the user interface after a full reload of the interface.

States need to be assigned to a model, state (for example status on a StockItem) and a logical key - that will be used for business logic. These 3 values combined need to be unique throughout the system.

Custom states can be used in the following models:
- StockItem
- Orders (PurchaseOrder, SalesOrder, ReturnOrder, ReturnOrderLine)
8 changes: 5 additions & 3 deletions docs/docs/extend/machines/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ If you want to create your own machine type, please also take a look at the alre

```py
from django.utils.translation import gettext_lazy as _

from generic.states import ColorEnum
from plugin.machine import BaseDriver, BaseMachineType, MachineStatus

class ABCBaseDriver(BaseDriver):
Expand All @@ -72,9 +74,9 @@ class ABCMachine(BaseMachineType):
base_driver = ABCBaseDriver

class ABCStatus(MachineStatus):
CONNECTED = 100, _('Connected'), 'success'
STANDBY = 101, _('Standby'), 'success'
PRINTING = 110, _('Printing'), 'primary'
CONNECTED = 100, _('Connected'), ColorEnum.success
STANDBY = 101, _('Standby'), ColorEnum.success
PRINTING = 110, _('Printing'), ColorEnum.primary

MACHINE_STATUS = ABCStatus
default_machine_status = ABCStatus.DISCONNECTED
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/order/purchase_order.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Refer to the source code for the Purchase Order status codes:
show_source: True
members: []

Purchase Order Status supports [custom states](../concepts/custom_states.md).

### Purchase Order Currency

The currency code can be specified for an individual purchase order. If not specified, the default currency specified against the [supplier](./company.md#suppliers) will be used.
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/order/return_order.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Refer to the source code for the Return Order status codes:
show_source: True
members: []

Return Order Status supports [custom states](../concepts/custom_states.md).

## Create a Return Order

From the Return Order index, click on <span class='badge inventree add'><span class='fas fa-plus-circle'></span> New Return Order</span> which opens the "Create Return Order" form.
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/order/sales_order.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Refer to the source code for the Sales Order status codes:
show_source: True
members: []

Sales Order Status supports [custom states](../concepts/custom_states.md).

### Sales Order Currency

The currency code can be specified for an individual sales order. If not specified, the default currency specified against the [customer](./company.md#customers) will be used.
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/stock/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Certain stock item status codes will restrict the availability of the stock item

Below is the list of available stock status codes and their meaning:

| Status | Description | Available |
| Status | Description | Available |
| ----------- | ----------- | --- |
| <span class='badge inventree success'>OK</span> | Stock item is healthy, nothing wrong to report | <span class='badge inventree success'>Yes</span> |
| <span class='badge inventree warning'>Attention needed</span> | Stock item hasn't been checked or tested yet | <span class='badge inventree success'>Yes</span> |
Expand Down Expand Up @@ -38,6 +38,8 @@ Refer to the source code for the Stock status codes:
show_source: True
members: []

Stock Status supports [custom states](../concepts/custom_states.md).

### Default Status Code

The default status code for any newly created Stock Item is <span class='badge inventree success'>OK</span>
Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ nav:
- Core Concepts:
- Terminology: concepts/terminology.md
- Physical Units: concepts/units.md
- Custom States: concepts/custom_states.md
- Development:
- Contributing: develop/contributing.md
- Devcontainer: develop/devcontainer.md
Expand Down
16 changes: 15 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
"""InvenTree API version information."""

# InvenTree API version
INVENTREE_API_VERSION = 245
INVENTREE_API_VERSION = 249

"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""


INVENTREE_API_TEXT = """
v249 - 2024-08-23 : https://github.com/inventree/InvenTree/pull/7978
- Sort status enums
v248 - 2024-08-23 : https://github.com/inventree/InvenTree/pull/7965
- Small adjustments to labels for new custom status fields
v247 - 2024-08-22 : https://github.com/inventree/InvenTree/pull/7956
- Adjust "attachment" field on StockItemTestResult serializer
- Allow null values for attachment
v246 - 2024-08-21 : https://github.com/inventree/InvenTree/pull/7862
- Adds custom status fields to various serializers
- Adds endpoints to admin custom status fields
v245 - 2024-08-21 : https://github.com/inventree/InvenTree/pull/7520
- Documented pagination fields (no functional changes)
Expand Down
9 changes: 6 additions & 3 deletions src/backend/InvenTree/InvenTree/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""Provides extra global data to all templates."""

import InvenTree.email
import InvenTree.ready
import InvenTree.status
from generic.states import StatusCode
from InvenTree.helpers import inheritors
from generic.states.custom import get_custom_classes
from users.models import RuleSet, check_user_role


Expand Down Expand Up @@ -53,7 +53,10 @@ def status_codes(request):
return {}

request._inventree_status_codes = True
return {cls.__name__: cls.template_context() for cls in inheritors(StatusCode)}
get_custom = InvenTree.ready.isRebuildingData() is False
return {
cls.__name__: cls.template_context() for cls in get_custom_classes(get_custom)
}


def user_roles(request):
Expand Down
14 changes: 11 additions & 3 deletions src/backend/InvenTree/InvenTree/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,15 @@ def get_target(self, obj):
Inheritors_T = TypeVar('Inheritors_T')


def inheritors(cls: type[Inheritors_T]) -> set[type[Inheritors_T]]:
"""Return all classes that are subclasses from the supplied cls."""
def inheritors(
cls: type[Inheritors_T], subclasses: bool = True
) -> set[type[Inheritors_T]]:
"""Return all classes that are subclasses from the supplied cls.
Args:
cls: The class to search for subclasses
subclasses: Include subclasses of subclasses (default = True)
"""
subcls = set()
work = [cls]

Expand All @@ -963,7 +970,8 @@ def inheritors(cls: type[Inheritors_T]) -> set[type[Inheritors_T]]:
for child in parent.__subclasses__():
if child not in subcls:
subcls.add(child)
work.append(child)
if subclasses:
work.append(child)
return subcls


Expand Down
10 changes: 9 additions & 1 deletion src/backend/InvenTree/InvenTree/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def get_field_info(self, field):
field_info['type'] = 'related field'
field_info['model'] = model._meta.model_name

# Special case for 'user' model
# Special case for special models
if field_info['model'] == 'user':
field_info['api_url'] = '/api/user/'
elif field_info['model'] == 'contenttype':
Expand All @@ -381,6 +381,14 @@ def get_field_info(self, field):
if field_info['type'] == 'dependent field':
field_info['depends_on'] = field.depends_on

# Extend field info if the field has a get_field_info method
if (
not field_info.get('read_only')
and hasattr(field, 'get_field_info')
and callable(field.get_field_info)
):
field_info = field.get_field_info(field, field_info)

return field_info


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 4.2.14 on 2024-08-07 22:40

import django.core.validators
from django.db import migrations

import generic.states.fields
import InvenTree.status_codes


class Migration(migrations.Migration):

dependencies = [
("build", "0051_delete_buildorderattachment"),
]

operations = [
migrations.AddField(
model_name="build",
name="status_custom_key",
field=generic.states.fields.ExtraInvenTreeCustomStatusModelField(
blank=True,
default=None,
help_text="Additional status information for this item",
null=True,
verbose_name="Custom status key",
),
),
migrations.AlterField(
model_name="build",
name="status",
field=generic.states.fields.InvenTreeCustomStatusModelField(
choices=InvenTree.status_codes.BuildStatus.items(),
default=10,
help_text="Build status code",
validators=[django.core.validators.MinValueValidator(0)],
verbose_name="Build Status",
),
),
]
3 changes: 2 additions & 1 deletion src/backend/InvenTree/build/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import report.mixins
import stock.models
import users.models
import generic.states


logger = logging.getLogger('inventree')
Expand Down Expand Up @@ -315,7 +316,7 @@ def get_absolute_url(self):
help_text=_('Number of stock items which have been completed')
)

status = models.PositiveIntegerField(
status = generic.states.fields.InvenTreeCustomStatusModelField(
verbose_name=_('Build Status'),
default=BuildStatus.PENDING.value,
choices=BuildStatus.items(),
Expand Down
Loading

0 comments on commit 4e7fca7

Please sign in to comment.