Problem/Motivation
Currently, stock transactions can be correlated to other transactions (i.e., supporting a sell transaction to its original receipt transaction) and to orders, but it's possible that a single order might generate multiple stock transactions even for the same product variation.
For example, if you are actually trying to correlate all sell transactions to previous receipt transactions, you might need multiple sell transactions to reference different original receipt transactions / unit costs. Right now you'd simply have to load any transaction related to the order and then group them by purchased entity ID.
Proposed resolution
Similar to the related_tid and related_oid columns in the commerce_stock_transaction table, add a related_oiid column to allow individual transactions to be correlated to order items.
Generally speaking, this would also deprecate the need for a related_oid field, but it's possible a site may choose one strategy over another or benefit from the more direct query here. No need to remove the order ID correlation unless it was just desirable for other reasons as of the next major version.
Comments
Comment #2
guy_schneerson commentedIt is a bit of a missed opportunity not using the related_oiid instead of related_oid.
I am open to the idea of adding it and possibly dropping related_oid in the next major release.
But I need a tiny bit more convincing, as the original plan was to use the data blob to hold any information the existing schema does not support. This will allow the querying of all transactions belonging to an order and programmatically matching them to items.
I suppose that will not help produce reports that are query-based and therefore do not solve the problem (lol, I just convinced myself).