Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/inventree/InvenTree
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair committed Oct 11, 2023
2 parents b83cf8d + 0c519c6 commit 6631538
Show file tree
Hide file tree
Showing 118 changed files with 2,845 additions and 1,292 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ HTML and javascript files are passed through the django templating engine. Trans
```
## Github use
### Tags
The tags describe issues and PRs in multiple areas:
| Area | Name | Description |
| --- | --- | --- |
| Triage Labels | | |
Expand Down
3 changes: 3 additions & 0 deletions contrib/container/docker.dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ INVENTREE_DB_PASSWORD=pgpassword

# Enable custom plugins?
INVENTREE_PLUGINS_ENABLED=True

# Auto run migrations?
INVENTREE_AUTO_UPDATE=False
3 changes: 3 additions & 0 deletions contrib/container/production/.env
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ INVENTREE_GUNICORN_TIMEOUT=90
# Enable custom plugins?
INVENTREE_PLUGINS_ENABLED=False

# Run migrations automatically?
INVENTREE_AUTO_UPDATE=False

# Image tag that should be used
INVENTREE_TAG=stable

Expand Down
Binary file added docs/docs/assets/images/settings/currency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/docs/extend/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Supported mixin classes are:
| [APICallMixin](./plugins/api.md) | Perform calls to external APIs |
| [AppMixin](./plugins/app.md) | Integrate additional database tables |
| [BarcodeMixin](./plugins/barcode.md) | Support custom barcode actions |
| [CurrencyExchangeMixin](./plugins/currency.md) | Custom interfaces for currency exchange rates |
| [EventMixin](./plugins/event.md) | Respond to events |
| [LabelPrintingMixin](./plugins/label.md) | Custom label printing support |
| [LocateMixin](./plugins/locate.md) | Locate and identify stock items |
Expand Down
45 changes: 45 additions & 0 deletions docs/docs/extend/plugins/currency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Currency Exchange Mixin
---

## CurrencyExchangeMixin

The `CurrencyExchangeMixin` class enabled plugins to provide custom backends for updating currency exchange rate information.

Any implementing classes must provide the `update_exchange_rates` method. A simple example is shown below (with fake data).

```python

from plugin import InvenTreePlugin
from plugin.mixins import CurrencyExchangeMixin

class MyFirstCurrencyExchangePlugin(CurrencyExchangeMixin, InvenTreePlugin):
"""Sample currency exchange plugin"""

...

def update_exchange_rates(self, base_currency: str, symbols: list[str]) -> dict:
"""Update currency exchange rates.
This method *must* be implemented by the plugin class.
Arguments:
base_currency: The base currency to use for exchange rates
symbols: A list of currency symbols to retrieve exchange rates for
Returns:
A dictionary of exchange rates, or None if the update failed
Raises:
Can raise any exception if the update fails
"""

rates = {
'base_currency': 1.00
}

for sym in symbols:
rates[sym] = random.randrange(5, 15) * 0.1

return rates
```
2 changes: 1 addition & 1 deletion docs/docs/extend/plugins/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from report.models import PurchaseOrderReport
class SampleReportPlugin(ReportMixin, InvenTreePlugin):
"""Sample plugin which provides extra context data to a report"""

NAME = "Report Plugin"
NAME = "Sample Report Plugin"
SLUG = "reportexample"
TITLE = "Sample Report Plugin"
DESCRIPTION = "A sample plugin which provides extra context data to a report"
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/report/context_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Each report has access to a number of context variables by default. The followin
| --- | --- |
| date | Current date, represented as a Python datetime.date object |
| datetime | Current datetime, represented as a Python datetime object |
| default_page_size | InvenTree default page size variable |
| page_size | The specified page size for this report, e.g. `A4` or `Letter landscape` |
| report_template | The report template model instance |
| report_name | Name of the report template |
| report_description | Description of the report template |
| report_revision | Revision of the report template |
Expand Down
31 changes: 31 additions & 0 deletions docs/docs/settings/currency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Currency Support
---

## Currency Support

InvenTree provides support for multiple currencies, allowing pricing information to be stored with base currency rates.

### Configuration

To specify which currencies are supported, refer to the [currency configuration](../start/config.md#supported-currencies) section

### Currency Conversion

Currency conversion is provided via the [django-money](https://github.com/django-money/django-money) library. Pricing data can be converted seamlessly between the available currencies.

### Currency Rate Updates

Currency conversion rates are periodically updated, via an external currency exchange server. Out of the box, InvenTree uses the [frankfurter.app](https://www.frankfurter.app/) service, which is an open source currency API made freely available.

#### Custom Rate Updates

If a different currency exchange backend is needed, or a custom implementation is desired, the currency exchange framework can be extended [via plugins](../extend/plugins/currency.md). Plugins which implement custom currency exchange frameworks can be easily integrated into the InvenTree framework.

### Currency Settings

In the [settings screen](./global.md), under the *Pricing* section, the following currency settings are available:

{% with id="currency-settings", url="settings/currency.png", description="Currency Exchange Settings" %}
{% include 'img.html' %}
{% endwith %}
11 changes: 9 additions & 2 deletions docs/docs/start/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,20 @@ The following email settings are available:
The "sender" email address is the address from which InvenTree emails are sent (by default) and must be specified for outgoing emails to function:

!!! info "Fallback"
If `INVENTREE_EMAIL_SENDER` is not provided, the system will fall back to `INVENTREE_EMAIL_USERNAME` (if the username is a valid email address)
If `INVENTREE_EMAIL_SENDER` is not provided, the system will fall back to `INVENTREE_EMAIL_USERNAME` (if the username is a valid email address)

## Supported Currencies

The currencies supported by InvenTree must be specified in the [configuration file](#configuration-file).

A list of currency codes (e.g. *AUD*, *CAD*, *JPY*, *USD*) can be specified using the `currencies` variable.
A list of currency codes (e.g. *AUD*, *CAD*, *JPY*, *USD*) can be specified using the `currencies` variable (or using the `INVENTREE_CURRENCIES` environment variable).

| Environment Variable | Configuration File | Description | Default |
| --- | --- | --- | --- |
| INVENTREE_CURRENCIES | currencies | List of supported currencies| `AUD`, `CAD`, `CNY`, `EUR`, `GBP`, `JPY`, `NZD`, `USD` |

!!! tip "More Info"
Read the [currencies documentation](../settings/currency.md) for more information on currency support in InvenTree

## Allowed Hosts / CORS

Expand Down
2 changes: 2 additions & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ nav:
- Error Logs: settings/logs.md
- Email: settings/email.md
- Background Tasks: settings/tasks.md
- Currency Support: settings/currency.md
- App:
- InvenTree App: app/app.md
- Connect: app/connect.md
Expand Down Expand Up @@ -202,6 +203,7 @@ nav:
- API Mixin: extend/plugins/api.md
- App Mixin: extend/plugins/app.md
- Barcode Mixin: extend/plugins/barcode.md
- Currency Mixin: extend/plugins/currency.md
- Event Mixin: extend/plugins/event.md
- Label Printing Mixin: extend/plugins/label.md
- Locate Mixin: extend/plugins/locate.md
Expand Down
34 changes: 33 additions & 1 deletion src/backend/InvenTree/InvenTree/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from djmoney.contrib.exchange.admin import RateAdmin
from djmoney.contrib.exchange.models import Rate
from import_export.exceptions import ImportExportError
from import_export.resources import ModelResource


Expand All @@ -15,8 +16,39 @@ class InvenTreeResource(ModelResource):
Ref: https://owasp.org/www-community/attacks/CSV_Injection
"""

MAX_IMPORT_ROWS = 1000
MAX_IMPORT_COLS = 100

def import_data_inner(
self,
dataset,
dry_run,
raise_errors,
using_transactions,
collect_failed_rows,
rollback_on_validation_errors=None,
**kwargs
):
"""Override the default import_data_inner function to provide better error handling"""

if len(dataset) > self.MAX_IMPORT_ROWS:
raise ImportExportError(f"Dataset contains too many rows (max {self.MAX_IMPORT_ROWS})")

if len(dataset.headers) > self.MAX_IMPORT_COLS:
raise ImportExportError(f"Dataset contains too many columns (max {self.MAX_IMPORT_COLS})")

return super().import_data_inner(
dataset,
dry_run,
raise_errors,
using_transactions,
collect_failed_rows,
rollback_on_validation_errors=rollback_on_validation_errors,
**kwargs
)

def export_resource(self, obj):
"""Custom function to override default row export behaviour.
"""Custom function to override default row export behavior.
Specifically, strip illegal leading characters to prevent formula injection
"""
Expand Down
14 changes: 11 additions & 3 deletions src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@


# InvenTree API version
INVENTREE_API_VERSION = 136
INVENTREE_API_VERSION = 138

"""
Increment this API version number whenever there is a significant change to the API that any clients need to know about
v138 -> 2023-10-11 : https://github.com/inventree/InvenTree/pull/5679
- Settings keys are no longer case sensitive
- Include settings units in API serializer
v137 -> 2023-10-04 : https://github.com/inventree/InvenTree/pull/5588
- Adds StockLocationType API endpoints
- Adds custom_icon, location_type to StockLocation endpoint
v136 -> 2023-09-23 : https://github.com/inventree/InvenTree/pull/5595
- Adds structural to StockLocation and PartCategory tree endpoints
Expand Down Expand Up @@ -85,7 +93,7 @@
- Adds API endpoints for scrapping a build output
v112 -> 2023-05-13: https://github.com/inventree/InvenTree/pull/4741
- Adds flag use_pack_size to the stock addition API, which allows addings packs
- Adds flag use_pack_size to the stock addition API, which allows adding packs
v111 -> 2023-05-02 : https://github.com/inventree/InvenTree/pull/4367
- Adds tags to the Part serializer
Expand Down Expand Up @@ -165,7 +173,7 @@
v89 -> 2023-01-25 : https://github.com/inventree/InvenTree/pull/4214
- Adds updated field to SupplierPart API
- Adds API date orddering for supplier part list
- Adds API date ordering for supplier part list
v88 -> 2023-01-17: https://github.com/inventree/InvenTree/pull/4225
- Adds 'priority' field to Build model and api endpoints
Expand Down
3 changes: 2 additions & 1 deletion src/backend/InvenTree/InvenTree/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def ready(self):
return

if canAppAccessDatabase() or settings.TESTING_ENV:
InvenTree.tasks.check_for_migrations(worker=False)

self.remove_obsolete_tasks()

Expand All @@ -49,6 +48,8 @@ def ready(self):

if not isInTestMode(): # pragma: no cover
self.update_exchange_rates()
# Let the background worker check for migrations
InvenTree.tasks.offload_task(InvenTree.tasks.check_for_migrations)

self.collect_notification_methods()

Expand Down
Loading

0 comments on commit 6631538

Please sign in to comment.