Wrong Product Cost Quantity if receipt quantity <> invoiced quantity


Costing method=Average PO

Product=>Costs=>Current Quantity is wrongly updated if the (matched PO) MR quantity does not exactly match with the (matched PO) invoiced quantity.
Below are 2 example scenarios:


Purchase Order Order Qty=100
Vendor Invoice(1) Qty=100
Partial MR(1) Qty=40
Partial MR(2) Qty=60

3 matched Purchase orders are created:
1.) Invoice Line Qty=100, Receipt Line=null (not posted because no MR assigned)
2.) Receipt Line Qty=40, Invoice Line=null (posted)
3.) Receipt Line Qty=60, Invoice Line=null (posted)

There are 3 issues here:

1.) When performing MR(1) with Qty=40, product cost quantity gets updated to 140 (100+40) instead of 40. When performing MR(2) with qty=60, product cost quantity gets updated to 200 (100+40+60) instead of 100.
2.) The system does not create matched invoices/receipts when recording MR(1) and MR(2)
3.) In the matched PO, the system does not allocate invoice lines to receipt lines. The system should assign a receipt line to the invoice line after each MR (according to matched invoice posting in 2.) which would look like this at the end:
Matched PO 1: Invoice Line1, Receipt Line1 Qty=40
Matched PO 2: Invoice Line1, Receipt Line2 Qty=60

Purchase Order Qty=100
Vendor Invoice(1) Qty=40
Vendor Invoice(2) Qty=60
Partial MR(1) Qty=40
Partial MR(2) Qty=60

When performing MR(1) with qty=40, product cost quantity gets updated to 100 (40+60) instead of 40.

There are many more combinations causing the above issues.




Soo Fang Lee
February 27, 2018, 1:55 PM

The update qty to product cost can be done, however the update the Invoice Line to Matched PO cannot be done. There is a checking qty between Matched PO with the qty of assigned Invoice in the MMatchPO.java. For the qty update product cost resolve in my repository (https://bitbucket.org/soofang/idempiere3) . You may test it.

Michael Powacht
February 28, 2018, 2:46 AM

Thanks Soo Fang, will be testing asap and get back.

Michael Powacht
March 1, 2018, 6:28 AM

Hello Soo Fang, the patch works as expected as far as the costing quantities are concerned.
Please find my test document attached.

Refer to test scenario 1 and 2 in my test document, there is 1 remaining issue for consideration: If the invoice qty > MR qty, it doesn't automatically create a matched invoice/receipt document for the MR quantity, which requires manual matching using Matching PO-Receipt-Invoice.
In contrast, if MR is recorded BEFORE the invoice and invoice qty > MR qty, it does create a matched invoice/receipt document automatically.

Please let me know what you think.


Heng Sin Low
April 5, 2018, 4:20 AM


Commited with some adjustment, please verify.

Michael Powacht
April 11, 2018, 8:46 AM

Thanks Hengsin, I successfully re-ran my test scripts.


Soo Fang Lee


Michael Powacht



Tested By



Fix versions

Affects versions