Skip to content

Commit

Permalink
Implemented: Homogenize displaying number with multiple format
Browse files Browse the repository at this point in the history
(OFBIZ-7532)

To display a number we had different possibilities :
 * on ftl use the template <@ofbizAmount and <@ofbizCurrency
 * by java call a function UtilFormatOut.formatAmount, UtilFormatOut.formatPrice, UtilFormatOut.formatQuantity, etc..
 * by form widget, use <display type=accounting-number for accounting but nothing for other

To simplify and homogenize all, I implemented a number type purpose :
   * default: display a number by default, use when no purpose is present
   * quantity: display a number as a quantity
   * amount: display a number as an amount (like price without currency)
   * spelled: litteral displaying for a number (use on <@ofbizAmount ftl only before)
   * percentage: display a number as a percentage
   * accounting: diplay a number for accounting specific

Each purpose can be associate to a number for displaying it :
   * on ftl <@ofbizNumber number=value format=purpose/>
   * on java UtilFormatOut.formatNumber(value, purpose, delegator, locale)
   * on form widget <display type=number format=purpose/>

The format use by a purpose is define on framework/common/config/number.properties with the template
    .displaying.format = ##0.00

With this, you can surchage a configuration, create your own purpose or surchage only one through entity SystemProperty.

Concerning the backware compatibility: 
 * For the ftl the template <@ofbizAmount is now a link to '<@ofbizNumber format=amount'
 * For java all previous function call UtilFormatOut.formatNumber with the matching purpose
 * For form xml accounting-number is managed as an exection

Last point, display a currency is different that a number, so I didn't refactoring some code for this case (only move properties from general to number for centralize de configuration on the same file)

Thanks Charles Steltzlen to start the refactoring

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1864832 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
nmalin committed Aug 9, 2019
1 parent b529900 commit 4a511be
Show file tree
Hide file tree
Showing 17 changed files with 332 additions and 279 deletions.
3 changes: 0 additions & 3 deletions applications/accounting/config/arithmetic.properties
Expand Up @@ -49,6 +49,3 @@ finaccount.roundingSimpleMethod = HalfUp
salestax.calc.decimals = 3
salestax.final.decimals = 2
salestax.rounding = ROUND_HALF_UP

# the default accounting-number format for negatives in parentheses
accounting-number.format = #,##0.00;(#,##0.00)
2 changes: 1 addition & 1 deletion applications/order/template/order/EditOrderItems.ftl
Expand Up @@ -175,7 +175,7 @@ under the License.
<td class="align-text" valign="top" nowrap="nowrap">
<#-- check for permission to modify price -->
<#if (allowPriceChange) && !("ITEM_CANCELLED" == orderItem.statusId || "ITEM_COMPLETED" == orderItem.statusId)>
<input type="text" size="8" name="ipm_${orderItem.orderItemSeqId}" value="<@ofbizAmount amount=orderItem.unitPrice/>"/>
<input type="text" size="8" name="ipm_${orderItem.orderItemSeqId}" value="<@ofbizNumber number=orderItem.unitPrice format="quantity"/>"/>
&nbsp;<input type="checkbox" name="opm_${orderItem.orderItemSeqId}" value="Y"/>
<#else>
<div><@ofbizCurrency amount=orderItem.unitPrice isoCode=currencyUomId/> / <@ofbizCurrency amount=orderItem.unitListPrice isoCode=currencyUomId/></div>
Expand Down
2 changes: 1 addition & 1 deletion applications/order/widget/ordermgr/FieldLookupForms.xml
Expand Up @@ -497,7 +497,7 @@ under the License.
</field>
<field name="requirementStartDate" title="${uiLabelMap.OrderRequirementStartDate}"><display/></field>
<field name="requiredByDate" title="${uiLabelMap.OrderRequirementByDate}"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display type="number" format="quantity"/></field>
</form>

<form name="LookupShoppingList" target="LookupShoppingList" title="" type="single"
Expand Down
8 changes: 4 additions & 4 deletions applications/order/widget/ordermgr/OrderEntryForms.xml
Expand Up @@ -189,11 +189,11 @@ under the License.
<field name="supplierProductId"><display/></field>
<field name="supplierProductName"><display/></field>
<field name="internalName"><display/></field>
<field name="lastPrice"><display/></field>
<field name="minimumOrderQuantity"><display/></field>
<field name="minimumStock"><display/></field>
<field name="lastPrice"><display type="number" format="amount"/></field>
<field name="minimumOrderQuantity"><display type="number" format="quantity"/></field>
<field name="minimumStock"><display type="number" format="quantity"/></field>
<field name="qohAtp" title="${uiLabelMap.ProductAtpQoh}"><display/></field>
<field name="quantityOnOrder"><display/></field>
<field name="quantityOnOrder"><display type="number" format="quantity"/></field>
<field name="quantity" title="${uiLabelMap.OrderQuantity}">
<text size="5" maxlength="10"/>
</field>
Expand Down
20 changes: 10 additions & 10 deletions applications/order/widget/ordermgr/QuoteForms.xml
Expand Up @@ -212,7 +212,7 @@ under the License.
</field>
<field name="workEffortId" title="${uiLabelMap.OrderOrderQuoteWorkEffortId}"></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"><display type="number" format="amount"/></field>
<field name="estimatedDeliveryDate" title="${uiLabelMap.OrderOrderQuoteEstimatedDeliveryDate}"></field>
<field name="productFeatureId"><hidden/></field>
<field name="skillTypeId"><hidden/></field>
Expand Down Expand Up @@ -267,8 +267,8 @@ under the License.
</drop-down>
</field>
<field name="workEffortId" title="${uiLabelMap.OrderOrderQuoteWorkEffortId}"></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display type="number" format="quantity"/></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"><display type="number" format="amount"/></field>
<field name="estimatedDeliveryDate" title="${uiLabelMap.OrderOrderQuoteEstimatedDeliveryDate}"></field>
<field name="comments" title="${uiLabelMap.CommonComments}"></field>
<!--
Expand Down Expand Up @@ -358,11 +358,11 @@ under the License.
<field name="productId" title="${uiLabelMap.ProductProductId}">
<display-entity entity-name="Product" key-field-name="productId" description="${productId} - ${internalName}"/>
</field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display/></field>
<field name="averageCost" title="${uiLabelMap.OrderOrderQuoteAverageCost}"><display/></field>
<field name="costToPriceMult" title="${uiLabelMap.OrderOrderQuoteCostToPrice}"><display/></field>
<field name="defaultQuoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteDefaultUnitPrice}"><display/></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display type="number" format="quantity"/></field>
<field name="averageCost" title="${uiLabelMap.OrderOrderQuoteAverageCost}"><display type="number" format="amount"/></field>
<field name="costToPriceMult" title="${uiLabelMap.OrderOrderQuoteCostToPrice}"><display type="number" format="amount"/></field>
<field name="defaultQuoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteDefaultUnitPrice}"><display type="number" format="amount"/></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"><display type="number" format="amount"/></field>
<field name="manualQuoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteManualUnitPrice}"><text/></field>
<field name="_rowSubmit" title="${uiLabelMap.CommonSelected}"><check/></field>
<field name="submitButton" title="${uiLabelMap.CommonSubmit}" use-when="quoteItemAndCostInfos!=[]" widget-style="smallSubmit"><submit/></field>
Expand Down Expand Up @@ -447,9 +447,9 @@ under the License.
<field name="productId" title="${uiLabelMap.ProductProductId}">
<display-entity entity-name="Product" key-field-name="productId" description="${productId} - ${internalName}"/>
</field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display type="number" format="quantity"/></field>
<field name="averageCost" title="${uiLabelMap.OrderOrderQuoteAverageCost}"><display/></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"><display/></field>
<field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"><display type="number" format="amount"/></field>
<field name="profit" title="${uiLabelMap.OrderOrderQuoteProfit}"><display/></field>
<field name="percProfit" title="${uiLabelMap.OrderOrderQuotePercProfit}"><display/></field>
</form>
Expand Down
34 changes: 17 additions & 17 deletions applications/order/widget/ordermgr/ReportForms.xml
Expand Up @@ -129,37 +129,37 @@ under the License.
<!-- list open order items -->
<form name="OpenOrderItemsList" type="list" list-name="orderItemList"
odd-row-style="alternate-row" default-table-style="basic-table hover-bar" paginate-target="OpenOrderItemsReport">
<field name="orderDate" title="${uiLabelMap.OrderDate}"><display/></field>
<field name="orderDate" title="${uiLabelMap.OrderDate}"><display type="date-time"/></field>
<field name="orderId" title="${uiLabelMap.OrderOrderId}" widget-style="buttontext">
<hyperlink description="${orderId}" target="orderview">
<parameter param-name="orderId"/>
</hyperlink>
</field>
<field name="productId" title="${uiLabelMap.ProductProduct}"><display/></field>
<field name="itemDescription" title="${uiLabelMap.CommonDescription}"><display/></field>
<field name="quantityOrdered" title="${uiLabelMap.ProductQuantity}"><display/></field>
<field name="quantityIssued" title="${uiLabelMap.OrderQtyShipped}"><display/></field>
<field name="quantityOpen" title="${uiLabelMap.ProductOpenQuantity}"><display/></field>
<field name="shipAfterDate" title="${uiLabelMap.OrderShipAfterDate}"><display/></field>
<field name="shipBeforeDate" title="${uiLabelMap.OrderShipBeforeDate}"><display/></field>
<field name="quantityOrdered" title="${uiLabelMap.ProductQuantity}"><display type="number" format="quantity"/></field>
<field name="quantityIssued" title="${uiLabelMap.OrderQtyShipped}"><display type="number" format="quantity"/></field>
<field name="quantityOpen" title="${uiLabelMap.ProductOpenQuantity}"><display type="number" format="quantity"/></field>
<field name="shipAfterDate" title="${uiLabelMap.OrderShipAfterDate}"><display type="date-time"/></field>
<field name="shipBeforeDate" title="${uiLabelMap.OrderShipBeforeDate}"><display type="date-time"/></field>
<field name="comments" title="${uiLabelMap.CommonComments}"><display/></field>
<field name="costPrice" title="${uiLabelMap.ProductCostPrice}"><display/></field>
<field name="listPrice" title="${uiLabelMap.ProductListPrice}"><display/></field>
<field name="retailPrice" title="${uiLabelMap.ProductRetailPrice}"><display/></field>
<field name="discount" title="${uiLabelMap.ProductDiscount}"><display/></field>
<field name="costPrice" title="${uiLabelMap.ProductCostPrice}"><display type="number" format="amount"/></field>
<field name="listPrice" title="${uiLabelMap.ProductListPrice}"><display type="number" format="amount"/></field>
<field name="retailPrice" title="${uiLabelMap.ProductRetailPrice}"><display type="number" format="amount"/></field>
<field name="discount" title="${uiLabelMap.ProductDiscount}"><display type="number" format="amount"/></field>
<field name="calculatedMarkup" title="${uiLabelMap.OrderCalculatedMarkup}"><display/></field>
<field name="percentMarkup" title="${uiLabelMap.OrderPercentageMarkup}"><display/></field>
</form>

<form name="OpenOrderItemsTotal" type="list" list-name="totalAmountList"
odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
<field name="total" title="${uiLabelMap.CommonTotal}"><display/></field>
<field name="totalQuantityOrdered"><display/></field>
<field name="totalQuantityOpen"><display/></field>
<field name="totalCostPrice"><display/></field>
<field name="totalListPrice"><display/></field>
<field name="totalRetailPrice"><display/></field>
<field name="totalDiscount"><display/></field>
<field name="total" title="${uiLabelMap.CommonTotal}"><display type="number" format="quantity"/></field>
<field name="totalQuantityOrdered"><display type="number" format="quantity"/></field>
<field name="totalQuantityOpen"><display type="number" format="quantity"/></field>
<field name="totalCostPrice"><display type="number" format="amount"/></field>
<field name="totalListPrice"><display type="number" format="amount"/></field>
<field name="totalRetailPrice"><display type="number" format="amount"/></field>
<field name="totalDiscount"><display type="number" format="amount"/></field>
<field name="totalMarkup"><display/></field>
<field name="totalPercentMarkup"><display/></field>
</form>
Expand Down
16 changes: 8 additions & 8 deletions applications/order/widget/ordermgr/RequirementForms.xml
Expand Up @@ -91,9 +91,9 @@ under the License.
</field>
<field name="requirementStartDate"><display/></field>
<field name="requiredByDate"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display/></field>
<field name="facilityQuantityOnHandTotal"><display/></field>
<field name="quantityOnHandTotal"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display type="number" format="quantity"/></field>
<field name="facilityQuantityOnHandTotal"><display type="number" format="quantity"/></field>
<field name="quantityOnHandTotal"><display type="number" format="quantity"/></field>
<field name="requestsLink" widget-style="buttontext">
<hyperlink description="${uiLabelMap.OrderRequests}" target="ListRequirementCustRequests">
<parameter param-name="requirementId"/>
Expand Down Expand Up @@ -249,7 +249,7 @@ under the License.
</field>
<field name="requirementStartDate"><display/></field>
<field name="requiredByDate"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display/></field>
<field name="quantity" title="${uiLabelMap.CommonQuantity}"><display type="number" format="quantity"/></field>
<field name="_rowSubmit" title="${uiLabelMap.CommonSelect}"><check/></field>
<field name="submitButton" title="${uiLabelMap.CommonSubmit}" widget-style="smallSubmit">
<submit/>
Expand Down Expand Up @@ -322,10 +322,10 @@ under the License.
<hyperlink description="${supplierProductId}" target="/catalog/control/EditProductSuppliers?productId=${productId}" target-type="inter-app"/>
</field>
<field name="idValue" title="${uiLabelMap.ProductUPCA}"><display/></field>
<field name="minimumOrderQuantity" widget-area-style="align-text"><display/></field>
<field name="minimumOrderQuantity" widget-area-style="align-text"><display type="number" format="quantity"/></field>
<field name="lastPrice" widget-area-style="align-text"><display type="currency" currency="${currencyUomId}"/></field>
<field name="requiredByDate"><display/></field>
<field name="quantity" widget-area-style="align-text"><display/></field>
<field name="quantity" widget-area-style="align-text"><display type="number" format="quantity"/></field>
<field name="comments"><display/></field>
</form>
<form name="ApprovedProductRequirements" type="multi" use-row-submit="true" target="quickPurchaseOrderEntry" title="" list-name="requirementsForSupplier"
Expand Down Expand Up @@ -353,7 +353,7 @@ under the License.
<field name="supplierCurrencyUomId" entry-name="parameters.supplierCurrencyUomId"><display/></field>
<field name="supplierProductId" title="${uiLabelMap.ProductSupplierProductId}"><display/></field>
<field name="idValue" title="${uiLabelMap.ProductUPCA}"><display/></field>
<field name="minimumOrderQuantity" title="${uiLabelMap.FormFieldTitle_minimumOrderQuantity}" widget-area-style="align-text"><display/></field>
<field name="minimumOrderQuantity" title="${uiLabelMap.FormFieldTitle_minimumOrderQuantity}" widget-area-style="align-text"><display type="number" format="quantity"/></field>
<field name="lastPrice" widget-area-style="align-text"><display type="currency" currency="${currencyUomId}"/></field>
<field name="requiredByDate"><display/></field>
<field name="atp" title="${uiLabelMap.ProductAtp}" widget-area-style="align-text"><display/></field>
Expand All @@ -373,7 +373,7 @@ under the License.
<form name="ApprovedProductRequirementsSummary" type="single" default-map-name="quantityReport" target="ApprovedProductRequirements"
header-row-style="header-row" default-table-style="basic-table">
<field name="distinctProductCount" title="${uiLabelMap.OrderRequirementNumberOfProducts}"><display/></field>
<field name="quantityTotal"><display/></field>
<field name="quantityTotal"><display type="number" format="quantity"/></field>
<field name="amountTotal"><display type="currency" currency="${currencyUomId}"/></field>
</form>
<form name="ApprovedProductRequirementsByVendor" type="list" use-row-submit="true" list-name="requirements" target="ApprovedProductRequirements" separate-columns="true"
Expand Down

0 comments on commit 4a511be

Please sign in to comment.