Matched invoice posting with wrong precision based on transaction currency instead of schema currency
Description
Environment
Attachments
Activity

Elaine Tan November 27, 2020 at 12:12 PM
The two issues above are related to . The issue for this ticket has been resolved.
Michael Powacht November 11, 2020 at 6:13 AM
@Elaine, PO prices in the 4 lines are:
PO Line 1 Product A Unit Price/Price=0.3023
PO Line 2 Product B Unit Price/Price=0.1971
PO Line 3 Product C Unit Price/Price=0.1875
PO Line 4 Product D Unit Price/Price=0.3742
Michael Powacht November 4, 2020 at 2:29 AM
We found some concerns regarding the GL postings in the local schema (THB):
Issue 1: Unnecessary realized gain/loss postings
Here is the scenario:
PO in USD (foreign currency and primary schema) with partial Material Receipt and single Invoice in same accounting period July 2020:
Rate USD/THB=30.870771861909
Primary schema currency=USD
Local schema currency=THB
PO Qty=1200, Price in USD =0.3742
Invoice Qty=1200
Invoice GL postings: DR Inventory Clearing THB 13862.21=>OK
MR1: Partial Qty=1,156
MR GL posting:
CR NIR THB 13354.08=>OK
Matched Invoice 1 GL posting:
DR NIR THB 13354.08=>OK NIR is now zero
CR Inventory Clearing THB 13353.93 (based on percentage proration for qty 1156/1200) => OK
CR Product Inventory (+cost adjustment) THB 0.15 => OK
The total amount of NIR and Inventory is zero at this point=>OK
These following 2 additional posting lines seem unnecessary:
DR Inventory Clearing THB 0.15
CR Realized Gain THB 0.15
MR2: Partial Qty=44
MR GL posting:
CR NIR THB 508.13=>OK
Matched Invoice 2 GL posting:
DR NIR THB 508.13=>OK NIR is now zero
CR Inventory Clearing THB 508.28 (based on percentage proration for qty 44/1200) => OK
DR Product Inventory (+cost adjustment) THB 0.15 => OK
The total amount of NIR and Inventory is zero at this point=>OK
These following 2 additional posting lines seem unnecessary:
CR Inventory Clearing THB 0.15
DR Realized Loss THB 0.15
Alternatively, instead of posting realized gains/losses in every partial receipt, please consider to only make an Inventory Clearing adjustment in the final partial receipt, preferrably again against Product Inventory (+ cost update),
not into the P/L as realized gains/losses. My reasoning for that is that it's enough and correct to just capitalize the minor variances between NIR and Inventory Clearing into product inventory rather than taking the
extra step of moving it to the P/L as realized gains/losses.
Issue 2: Inventory Clearing not zero at product-level
Here is the scenario:
PO in USD (foreign currency and primary schema) with 4 PO lines with partial receipts in all 4 lines.
Rate USD/THB=30.870771861909
Primary schema currency=USD
Local schema currency=THB
PO Line 1 Product A Qty=2
PO Line 2 Prodduct B Qty=42
PO Line 3 Product C Qty=2
PO Line 4 Product D Qty=45
Single Invoice with 4 lines, Qty=2, 42, 2, 45
MR1 with 4 lines, Qty=1, 41, 1, 44
MR GL postings=>OK
Please refer to attached spreadsheet showing inventory clearing balances by Product and you will notice that Inventory Clearing is not zero within Product C (Balance=-0.01) and Product D (Balance=0.01).
Michael Powacht October 23, 2020 at 11:53 AM
Will be tested within next week.

Elaine Tan October 23, 2020 at 3:20 AM
Patches:
0001-IDEMPIERE-4128-Matched-invoice-posting-with-wrong-pr.patch
0002-IDEMPIERE-4128-Matched-invoice-posting-with-wrong-pr.patch
Matched invoice document is posted with incorrect precision based on the standard precision of the transaction currency instead of the schema currency. The issue becomes only visible if the transaction currency has a different standard precision (e.g. the Japanese Yen JPY with a standard precision of 0) than the schema currency (e.g. USD with a standard precision of 2).
The following scenario can be used to simulate the incorrect matched invoice posting:
Transaction currency=JPY, Standard Precision: 0
Schema currency=USD, Standard Precision: 2
1 JPY = 0.277582 USD (Multiply rate)
1. Create Purchase order with qty=3, unit price=2400 JPY
2. Create MR qty=3, Posting: DR Inventory/CR NIR USD 1,998.59
3. Create Invoice qty=3, Posting: DR Inventory Clearing USD 1,998.59
4. Matched Invoice posting=DR NIR/CR Inventory Clearing USD 1,999.00 INCORRECT, this should be 1,998.59
The problem seems to be with function FactLine.java=>setAmtAcct(C_Currency_ID,.....) which gets called by updateReverseLine(...) with the transaction C_Currency_ID instead of the schema C_Currency_ID.