From cd53f21120adbbdfdf5c2b1e757f2b0a95bda803 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 19 Apr 2024 13:59:07 +1000 Subject: [PATCH] Fix currency rendering in order tables (#7066) * Add "currency" to CompanyBriefSerializer * Fix nav.js bug - potential illegal chars in panel name * Update CUI tables * Update PUI tables * Bump API version --- src/backend/InvenTree/InvenTree/api_version.py | 5 ++++- src/backend/InvenTree/company/serializers.py | 4 +++- src/backend/InvenTree/templates/js/dynamic/nav.js | 5 ++++- .../templates/js/translated/purchase_order.js | 2 +- .../templates/js/translated/return_order.js | 4 ++-- .../templates/js/translated/sales_order.js | 4 ++-- .../src/tables/purchasing/PurchaseOrderTable.tsx | 15 ++++++++++++--- .../src/tables/sales/ReturnOrderTable.tsx | 15 ++++++++++++--- src/frontend/src/tables/sales/SalesOrderTable.tsx | 15 ++++++++++++--- 9 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index b0fde97af8..7db9dc01fb 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,11 +1,14 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 188 +INVENTREE_API_VERSION = 189 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v189 - 2024-04-19 : https://github.com/inventree/InvenTree/pull/7066 + - Adds "currency" field to CompanyBriefSerializer class + v188 - 2024-04-16 : https://github.com/inventree/InvenTree/pull/6970 - Adds session authentication support for the API - Improvements for login / logout endpoints for better support of React web interface diff --git a/src/backend/InvenTree/company/serializers.py b/src/backend/InvenTree/company/serializers.py index f94333aca8..7e3f86da78 100644 --- a/src/backend/InvenTree/company/serializers.py +++ b/src/backend/InvenTree/company/serializers.py @@ -42,7 +42,9 @@ class CompanyBriefSerializer(InvenTreeModelSerializer): """Metaclass options.""" model = Company - fields = ['pk', 'url', 'name', 'description', 'image', 'thumbnail'] + fields = ['pk', 'url', 'name', 'description', 'image', 'thumbnail', 'currency'] + + read_only_fields = ['currency'] url = serializers.CharField(source='get_absolute_url', read_only=True) diff --git a/src/backend/InvenTree/templates/js/dynamic/nav.js b/src/backend/InvenTree/templates/js/dynamic/nav.js index 8ce792648b..f207bf110d 100644 --- a/src/backend/InvenTree/templates/js/dynamic/nav.js +++ b/src/backend/InvenTree/templates/js/dynamic/nav.js @@ -21,12 +21,15 @@ function activatePanel(label, panel_name, options={}) { $('.panel-visible').hide(); $('.panel-visible').removeClass('panel-visible'); + // Remove illegal chars + panel_name = panel_name.replace('/', ''); + // Find the target panel var panel = `#panel-${panel_name}`; var select = `#select-${panel_name}`; // Check that the selected panel (and select) exist - if ($(panel).length && $(select).length) { + if ($(panel).exists() && $(panel).length && $(select).length) { // Yep, both are displayed } else { // Either the select or the panel are not displayed! diff --git a/src/backend/InvenTree/templates/js/translated/purchase_order.js b/src/backend/InvenTree/templates/js/translated/purchase_order.js index 47379dc2a3..c829fed140 100644 --- a/src/backend/InvenTree/templates/js/translated/purchase_order.js +++ b/src/backend/InvenTree/templates/js/translated/purchase_order.js @@ -1755,7 +1755,7 @@ function loadPurchaseOrderTable(table, options) { sortable: true, formatter: function(value, row) { return formatCurrency(value, { - currency: row.order_currency, + currency: row.order_currency ?? row.supplier_detail?.currency, }); }, }, diff --git a/src/backend/InvenTree/templates/js/translated/return_order.js b/src/backend/InvenTree/templates/js/translated/return_order.js index b699bd8422..5163b9696d 100644 --- a/src/backend/InvenTree/templates/js/translated/return_order.js +++ b/src/backend/InvenTree/templates/js/translated/return_order.js @@ -300,7 +300,7 @@ function loadReturnOrderTable(table, options={}) { return '{% trans "Invalid Customer" %}'; } - return imageHoverIcon(row.customer_detail.image) + renderLink(row.customer_detail.name, `/company/${row.customer}/sales-orders/`); + return imageHoverIcon(row.customer_detail.image) + renderLink(row.customer_detail.name, `/company/${row.customer}/?display=sales-orders/`); } }, { @@ -384,7 +384,7 @@ function loadReturnOrderTable(table, options={}) { visible: false, formatter: function(value, row) { return formatCurrency(value, { - currency: row.order_currency + currency: row.order_currency ?? row.customer_detail?.currency, }); } } diff --git a/src/backend/InvenTree/templates/js/translated/sales_order.js b/src/backend/InvenTree/templates/js/translated/sales_order.js index 7f8ece3137..53085cf180 100644 --- a/src/backend/InvenTree/templates/js/translated/sales_order.js +++ b/src/backend/InvenTree/templates/js/translated/sales_order.js @@ -788,7 +788,7 @@ function loadSalesOrderTable(table, options) { return '{% trans "Invalid Customer" %}'; } - return imageHoverIcon(row.customer_detail.image) + renderLink(row.customer_detail.name, `/company/${row.customer}/sales-orders/`); + return imageHoverIcon(row.customer_detail.image) + renderLink(row.customer_detail.name, `/company/${row.customer}/?display=sales-orders/`); } }, { @@ -857,7 +857,7 @@ function loadSalesOrderTable(table, options) { sortable: true, formatter: function(value, row) { return formatCurrency(value, { - currency: row.order_currency, + currency: row.order_currency ?? row.customer_detail?.currency, }); } } diff --git a/src/frontend/src/tables/purchasing/PurchaseOrderTable.tsx b/src/frontend/src/tables/purchasing/PurchaseOrderTable.tsx index 2901da0458..c16c5642d5 100644 --- a/src/frontend/src/tables/purchasing/PurchaseOrderTable.tsx +++ b/src/frontend/src/tables/purchasing/PurchaseOrderTable.tsx @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom'; import { AddItemButton } from '../../components/buttons/AddItemButton'; import { Thumbnail } from '../../components/images/Thumbnail'; +import { formatCurrency } from '../../defaults/formatters'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; import { UserRoles } from '../../enums/Roles'; @@ -21,8 +22,7 @@ import { ReferenceColumn, ResponsibleColumn, StatusColumn, - TargetDateColumn, - TotalPriceColumn + TargetDateColumn } from '../ColumnRenderers'; import { AssignedToMeFilter, @@ -92,7 +92,16 @@ export function PurchaseOrderTable({ ProjectCodeColumn(), CreationDateColumn(), TargetDateColumn(), - TotalPriceColumn(), + { + accessor: 'total_price', + title: t`Total Price`, + sortable: true, + render: (record: any) => { + return formatCurrency(record.total_price, { + currency: record.order_currency ?? record.supplier_detail?.currency + }); + } + }, ResponsibleColumn() ]; }, []); diff --git a/src/frontend/src/tables/sales/ReturnOrderTable.tsx b/src/frontend/src/tables/sales/ReturnOrderTable.tsx index 2c007848b5..0da8649b53 100644 --- a/src/frontend/src/tables/sales/ReturnOrderTable.tsx +++ b/src/frontend/src/tables/sales/ReturnOrderTable.tsx @@ -3,6 +3,7 @@ import { useCallback, useMemo } from 'react'; import { AddItemButton } from '../../components/buttons/AddItemButton'; import { Thumbnail } from '../../components/images/Thumbnail'; +import { formatCurrency } from '../../defaults/formatters'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; import { UserRoles } from '../../enums/Roles'; @@ -18,8 +19,7 @@ import { ReferenceColumn, ResponsibleColumn, StatusColumn, - TargetDateColumn, - TotalPriceColumn + TargetDateColumn } from '../ColumnRenderers'; import { AssignedToMeFilter, @@ -81,7 +81,16 @@ export function ReturnOrderTable({ params }: { params?: any }) { CreationDateColumn(), TargetDateColumn(), ResponsibleColumn(), - TotalPriceColumn() + { + accessor: 'total_price', + title: t`Total Price`, + sortable: true, + render: (record: any) => { + return formatCurrency(record.total_price, { + currency: record.order_currency ?? record.customer_detail?.currency + }); + } + } ]; }, []); diff --git a/src/frontend/src/tables/sales/SalesOrderTable.tsx b/src/frontend/src/tables/sales/SalesOrderTable.tsx index de516eda0e..52fc55d5ac 100644 --- a/src/frontend/src/tables/sales/SalesOrderTable.tsx +++ b/src/frontend/src/tables/sales/SalesOrderTable.tsx @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom'; import { AddItemButton } from '../../components/buttons/AddItemButton'; import { Thumbnail } from '../../components/images/Thumbnail'; +import { formatCurrency } from '../../defaults/formatters'; import { ApiEndpoints } from '../../enums/ApiEndpoints'; import { ModelType } from '../../enums/ModelType'; import { UserRoles } from '../../enums/Roles'; @@ -21,8 +22,7 @@ import { ReferenceColumn, ShipmentDateColumn, StatusColumn, - TargetDateColumn, - TotalPriceColumn + TargetDateColumn } from '../ColumnRenderers'; import { AssignedToMeFilter, @@ -117,7 +117,16 @@ export function SalesOrderTable({ CreationDateColumn(), TargetDateColumn(), ShipmentDateColumn(), - TotalPriceColumn() + { + accessor: 'total_price', + title: t`Total Price`, + sortable: true, + render: (record: any) => { + return formatCurrency(record.total_price, { + currency: record.order_currency ?? record.customer_detail?.currency + }); + } + } ]; }, []);