Separate M_MatchPO matching POs vs invoices and receipts
Description
The design of the table M_MatchPO is to match lines from purchase orders, invoices and material receipts.
All the matches happen on the same record and that creates some impossible situations, like the situation described in ticket IDEMPIERE-3016.
Invoicing a different quantity than ordered and then a different than received would create two different records in MatchPO (it used to happen before the validations were added) and creates a mess of matching that was too hard to fix.
I think the problem lies on the design of trying to combine in one single record the matching of three tables that can have different quantities each other. The common matching is: PO=100 Invoice=100 Receipt=100 - and that's described in one record with the three lines filled
Now we have more complex cases PO=100 Invoice=50 Receipt=25 - and the system tries to create one record to match the PO with the invoice (50) - and then another record to match the PO+Invoice+Receipt with 25 - that would lead to wrong quantity matched.
I think the solution would be to create two different records and keep the matches separated:
records that matches PO and Invoice (m_inoutline_id null)
records that matches PO and Receipt (m_invoiceline_id null)
Note that records that matches Invoice and Receipt (c_orderline_id null) are not allowed in database as the column is not null - but it seems this match is not required to keep track.
This will double the number of records in M_MatchPO table, but I think is the correct way to get the real numbers matched.
The design of the table M_MatchPO is to match lines from purchase orders, invoices and material receipts.
All the matches happen on the same record and that creates some impossible situations, like the situation described in ticket IDEMPIERE-3016.
Invoicing a different quantity than ordered and then a different than received would create two different records in MatchPO (it used to happen before the validations were added) and creates a mess of matching that was too hard to fix.
I think the problem lies on the design of trying to combine in one single record the matching of three tables that can have different quantities each other.
The common matching is:
PO=100 Invoice=100 Receipt=100 - and that's described in one record with the three lines filled
Now we have more complex cases
PO=100 Invoice=50 Receipt=25 - and the system tries to create one record to match the PO with the invoice (50) - and then another record to match the PO+Invoice+Receipt with 25 - that would lead to wrong quantity matched.
I think the solution would be to create two different records and keep the matches separated:
records that matches PO and Invoice (m_inoutline_id null)
records that matches PO and Receipt (m_invoiceline_id null)
Note that records that matches Invoice and Receipt (c_orderline_id null) are not allowed in database as the column is not null - but it seems this match is not required to keep track.
This will double the number of records in M_MatchPO table, but I think is the correct way to get the real numbers matched.
Other ideas? WDYT?