Problem/Motivation
Follow-up to: #3196825: Quantity types
In farmOS 1.x, the Sale and Purchase logs have 4 "pseudo-quantity" fields on them:
- Quantity (
quantity_value
) - Units (
quantity_units
) - Unit price (
unit_price
) - Total price (
total_price
)
We need to migrate this data to 2.x.
Proposed resolution
Provide a new "Price" Quantity type with two additional fields: "Unit Quantity" and "Unit Price". Migrate the 4 pseudo-quantity fields on Sale/Purchase logs to a "Price Quantity" entity linked to the log.
Remaining tasks
TBD
User interface changes
Additional "Price Quantity" option when adding a Quantity to a Log.
API changes
Additional quantity--price
JSON:API resource type.
Data model changes
Additional "Price Quantity" type.
Issue fork farm-3196836
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
paul121 CreditAttribution: paul121 commentedI've got the price quantity working, just need to add the migration.
Comment #4
paul121 CreditAttribution: paul121 commentedMigration is done.
I tested with a few random purchase and sale logs I made. I thought one issue we might have is that the
quantity.value
field is required, while thelog.total_price
field was not. I tested this with a sample log w/o a total price, and the quantity value is populated as "0".Also tested reverting the Purchase + Sale log migrations. Their quantities are indeed removed via our farm_entity LogEventSubsriber.
Comment #5
paul121 CreditAttribution: paul121 commentedOh shoot - I forgot the other edge case I wanted to test: purchase and sale logs that have NO "price" info. We shouldn't create a price quantity unless we absolutely need to.. maybe this can be a follow up?
Seems like it will just require some migrate process wizardry to check if any of the "price quantity" field values were populated, and only create the price quantity if so? Hopefully it isn't more complicated than that.
Comment #6
paul121 CreditAttribution: paul121 commentedJust force-pushed this branch to include the latest quantity_types changes.
I also got this working! The migration checks to see if any of the previous "price" fields were populated and only creates a new quantity if at least one of the fields were populated. I tested this with a few edge cases (purchase log with no price data, purchase log with all price data and purchase log with only one price field populated) and it is working well.
This article was helpful in figuring some of this out: https://www.freelock.com/blog/john-locke/2017-12/slick-migration-trick-c...
Comment #8
m.stentaWorks great @paul121 - thanks! Merged.
I made two changes/additions: