2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-14 19:15:41 +00:00

[Pricing] Add option to convert received items currency (#8970)

* Add new global setting

* Convert to base currency on receipt

* Fix total price rendering in PO table

* Fix for tasks.py

* Update .gitignore

- Ignore auto-generated files

* Update docs

Improved documentation for pricing/currency support

* Updates

* Fix caching for default currency

- Now managed better by session caching

* Add unit test for new feature

* Playwright test fixes

* Validate copying of media files

* Validate media files

* Adjust playwright setup

* Allow multiple attempts to fetch release information

* Tweak unit tests

* Revert changes to .gitignore file

- Just trying stuff at this point

* Add debug msg

* Try hard-coded paths

* Remove debug prints

* Abs path for database

* More debug

* Fix typos

* Revert change to db name

* Remove debug statements (again)

* Cleanup playwright tests

* More test tweaks

---------

Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
Oliver
2025-02-03 18:34:15 +11:00
committed by GitHub
parent a760d00c96
commit d363c408f8
29 changed files with 250 additions and 134 deletions

View File

@ -0,0 +1,65 @@
---
title: Pricing Support
---
## Pricing
Pricing is an inherently complex topic, often subject to the particular requirements of the user. InvenTree attempts to provide a comprehensive pricing architecture which is useful without being proscriptive.
InvenTree provides support for multiple currencies, allowing pricing information to be stored with base currency rates.
!!! warning "Raw Data Only"
InvenTree stores raw pricing data, as provided by the user. Any calculations or decisions based on this data must take into consideration the context in which the data are entered.
InvenTree uses the [django-money](https://github.com/django-money/django-money) library, which in turn uses the [py-moneyed library](https://py-moneyed.readthedocs.io/en/latest/index.html). `py-moneyed` supports any currency which is defined in the [ISO 3166 standard](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) standard.
### Terminology
Throughout this documentation (and within InvenTree) the concepts of *cost* and *price* are separated as follows:
| Term | Description |
| --- | --- |
| Price | The theoretical amount of money required to pay for something. |
| Cost | The actual amount of money paid. |
## Currency Support
InvenTree supports pricing data in multiple currencies, allowing integration with suppliers and customers using different currency systems.
### Default Currency
Many of the pricing operations are performed in reference to a *Default Currency* (which can be selected for the particular InvenTree installation).
The default currency is user configurable in the InvenTree settings.
!!! warning "Setting Default Currency"
Changing the default currency once the system in use may have unintended consequences. It is recommended to set the default currency during the initial setup of the InvenTree instance.
## Conversion Rates
To facilitate conversion between different currencies, exchange rate information is stored in the InvenTree database.
### Currency Codes
The list of support currency codes is user configurable in the InvenTree settings. It is recommended to select only the currencies which are relevant to the user.
While InvenTree can support any of the currencies defined in the ISO 3166 standard, the list of supported currencies can be limited to only those which are relevant to the user. The supported currencies are used to populate the currency selection dropdowns throughout the InvenTree interface.
### Exchange Rate Data
The exchange rate data is provided by a [currency plugin](../extend/plugins/currency.md) which fetches exchange rate data from an external source.
InvenTree includes a default currency plugin which fetches exchange rate data from the [frankfurter](https://frankfurter.dev/) API, which is an open source currency API made freely available.
However, the user can configure a custom currency plugin to fetch exchange rate data from a different source. 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.
### Exchange Rate Updates
Currency exchange rates are updated periodically, using the configured currency plugin. The update frequency can be configured in the InvenTree settings.
## Pricing Settings
Refer to the [global settings](../settings/global.md#pricing-and-currency) documentation for more information on available currency settings.

View File

@ -113,8 +113,18 @@ def get_release_data():
while 1:
url = f'https://api.github.com/repos/inventree/inventree/releases?page={page}&per_page=150'
response = requests.get(url, timeout=30)
assert response.status_code == 200
attempts = 5
while attempts > 0:
attempts -= 1
response = requests.get(url, timeout=30)
if response.status_code == 200:
break
assert response.status_code == 200, (
f'Failed to fetch release data: {response.status_code} - {url}'
)
data = json.loads(response.text)

View File

@ -42,7 +42,14 @@ 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.
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. Additionally, the currency can be specified separately for each line item.
So, when determining the cost of each line item in the purchase order, the following order of precedence is used:
1. Line item currency
2. Purchase order currency
3. Supplier currency
4. Default (base) currency
## Create Purchase Order
@ -77,11 +84,11 @@ It is possible to upload an exported purchase order from the supplier instead of
!!! info "Supported Formats"
This process only supports tabular data and the following formats are supported: CSV, TSV, XLS, XLSX, JSON and YAML
### Issue Order
## Issue Order
Once all the line items were added, click on the <span class='fas fa-paper-plane'></span> button on the main purchase order detail panel and confirm the order has been submitted.
### Receive Line Items
## Receive Line Items
After receiving all the items from the order, the purchase order will convert the line items into stock items / inventory.
@ -107,6 +114,12 @@ Each item marked as "received" is automatically converted into a stock item.
To see the list of stock items created from the purchase order, click on the <span class="badge inventree nav side"><span class='fas fa-sign-in-alt'></span> Received Items</span> tab.
### Item Value Currency
The unit cost of the purchase order line item is transferred across to the created stock item. By default, the same currency is used for the stock item as was used for the purchase order line item.
However, if the [Convert Currency](#purchase-order-settings) setting is enabled, the currency of the stock item will be converted to the [default currency](../concepts/pricing.md#default-currency) of the system. This may be useful when ordering stock in a different currency, to ensure that the unit cost of the stock item is converted to the base currency at the time of receipt.
## Complete Order
Once the quantity of all __received__ items is equal or above the quantity of all line items, the order will be automatically marked as __complete__.
@ -174,5 +187,6 @@ The following [global settings](../settings/global.md) are available for purchas
| ---- | ----------- | ------- | ----- |
{{ globalsetting("PURCHASEORDER_REFERENCE_PATTERN") }}
{{ globalsetting("PURCHASEORDER_REQUIRE_RESPONSIBLE") }}
{{ globalsetting("PURCHASEORDER_CONVERT_CURRENCY") }}
{{ globalsetting("PURCHASEORDER_EDIT_COMPLETED_ORDERS") }}
{{ globalsetting("PURCHASEORDER_AUTO_COMPLETE") }}

View File

@ -2,23 +2,10 @@
title: Pricing
---
## Pricing
## Part Pricing
Pricing is an inherently complex topic, often subject to the particular requirements of the user. InvenTree attempts to provide a comprehensive pricing architecture which is useful without being proscriptive.
!!! warning "Raw Data Only"
InvenTree stores raw pricing data, as provided by the user. Any calculations or decisions based on this data must take into consideration the context in which the data are entered.
### Terminology
Throughout this documentation (and within InvenTree) the concepts of *cost* and *price* are separated as follows:
| Term | Description |
| --- | --- |
| Price | The theoretical amount of money required to pay for something. |
| Cost | The actual amount of money paid. |
### Pricing Sources
!!! info "Pricing Support"
Refer to the [Pricing Support](../concepts/pricing.md) documentation for more information on pricing support in InvenTree.
Pricing information can be determined from multiple sources:
@ -42,26 +29,6 @@ Additionally, the following information is stored for each part, in relation to
| Sale Price | How much a salable item is sold for (with price-breaks) | [Part](../part/part.md) |
| Sale Cost | How much an item was sold for | [Sales Order](../order/sales_order.md) |
### Currency Support
InvenTree supports pricing data in multiple currencies, allowing integration with suppliers and customers using different currency systems.
Supported currencies can be configured in the [InvenTree settings](../settings/currency.md).
!!! info "Currency Support"
InvenTree provides multi-currency pricing support via the [django-money](https://django-money.readthedocs.io/en/latest/) library.
#### Default Currency
Many of the pricing operations are performed in reference to a *Default Currency* (which can be selected for the particular InvenTree installation).
#### Conversion Rates
To facilitate conversion between different currencies, exchange rate data is provided via the [exchangerate.host](https://exchangerate.host/#/) API. Currency exchange rates are updated once per day.
!!! tip "Custom Exchange Rates"
Custom exchange rates or databases can be used if desired.
## Pricing Tab
The pricing tab for a given Part provides all available pricing information for that part. It shows all price ranges and provides tools to calculate them.
@ -81,7 +48,7 @@ At the top of the pricing tab, an *Overview* section shows a synopsis of the ava
This overview tab provides information on the *range* of pricing data available within each category. If pricing data is not available for a given category, it is marked as *No data*.
Each price range is calculated in the [Default Currency](#default-currency), independent of the currency in which the original pricing information is stored. This is necessary for operations such as data sorting, price comparison, etc. Note that while the *overview* information is calculated in a single currency, the original pricing information is still available in the original currency.
Each price range is calculated in the [Default Currency](../concepts/pricing.md#default-currency), independent of the currency in which the original pricing information is stored. This is necessary for operations such as data sorting, price comparison, etc. Note that while the *overview* information is calculated in a single currency, the original pricing information is still available in the original currency.
Price range data is [cached in the database](#price-data-caching) when underlying pricing information changes.
@ -167,7 +134,7 @@ Pricing calculations (and conversions) can be expensive to perform. This can mak
For this reason, all information displayed in the [pricing overview](#pricing-overview) section is pre-calculated and *cached* in the database. This ensures that when it needs to be retrieved (e.g. viewing pricing for an entire BOM) it can be accessed immediately.
Pricing data is cached in the [default currency](#default-currency), which ensures that pricing can be compared across multiple parts in a consistent format.
Pricing data is cached in the [default currency](../concepts/pricing.md/#default-currency), which ensures that pricing can be compared across multiple parts in a consistent format.
#### Data Updates

View File

@ -1,31 +0,0 @@
---
title: Currency Support
---
## Currency Support
InvenTree provides support for multiple currencies, allowing pricing information to be stored with base currency rates.
### Supported Currencies
InvenTree uses the [django-money](https://github.com/django-money/django-money) library, which in turn uses the [py-moneyed library](https://py-moneyed.readthedocs.io/en/latest/index.html). `py-moneyed` supports any currency which is defined in the [ISO 3166 standard](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) standard.
### Currency Conversion
Currency conversion is provided via the `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
Refer to the [global settings](./global.md#pricing-and-currency) documentation for more information on available currency settings.
#### Supported Currencies
While InvenTree can support any of the currencies defined in the ISO 3166 standard, the list of supported currencies can be limited to only those which are relevant to the user. The supported currencies are used to populate the currency selection dropdowns throughout the InvenTree interface.

View File

@ -101,11 +101,18 @@ Configuration of pricing data and currency support:
| ---- | ----------- | ------- | ----- |
{{ globalsetting("INVENTREE_DEFAULT_CURRENCY") }}
{{ globalsetting("CURRENCY_CODES") }}
{{ globalsetting("PART_INTERNAL_PRICE") }}
{{ globalsetting("PART_BOM_USE_INTERNAL_PRICE") }}
{{ globalsetting("PRICING_DECIMAL_PLACES_MIN") }}
{{ globalsetting("PRICING_DECIMAL_PLACES") }}
{{ globalsetting("PRICING_UPDATE_DAYS") }}
#### Part Pricing
Configuration of part pricing:
| Name | Description | Default | Units |
| ---- | ----------- | ------- | ----- |
{{ globalsetting("PART_INTERNAL_PRICE") }}
{{ globalsetting("PART_BOM_USE_INTERNAL_PRICE") }}
{{ globalsetting("PRICING_USE_SUPPLIER_PRICING") }}
{{ globalsetting("PRICING_PURCHASE_HISTORY_OVERRIDES_SUPPLIER") }}
{{ globalsetting("PRICING_USE_STOCK_PRICING") }}

View File

@ -78,6 +78,7 @@ nav:
- Terminology: concepts/terminology.md
- Physical Units: concepts/units.md
- Custom States: concepts/custom_states.md
- Pricing: concepts/pricing.md
- Development:
- Contributing: develop/contributing.md
- Devcontainer: develop/devcontainer.md
@ -157,7 +158,6 @@ nav:
- Single Sign on: settings/SSO.md
- Multi Factor Authentication: settings/MFA.md
- Email: settings/email.md
- Currency Support: settings/currency.md
- Export Data: settings/export.md
- Import Data: settings/import.md
- Operations: