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

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m.stenta created an issue. See original summary.

paul121 made their first commit to this issue’s fork.

paul121’s picture

Status: Active » Needs work

I've got the price quantity working, just need to add the migration.

paul121’s picture

Status: Needs work » Needs review

Migration 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 the log.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.

paul121’s picture

Oh 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.

paul121’s picture

Just force-pushed this branch to include the latest quantity_types changes.

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..

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...

  • m.stenta committed 3d44f06 on 2.x
    Issue #3196836 by paul121, m.stenta: Price quantities
    
m.stenta’s picture

Status: Needs review » Fixed

Works great @paul121 - thanks! Merged.

I made two changes/additions:

  1. When creating new quantities for sale/purchase logs, I set the "Measure" to "Value" instead of "Count".
  2. I added a third-party setting to logs for specifying what the default quantity type should be, and made "Price" the default for Sale/Purchase logs. It defaults to "Standard" otherwise. This will also come in handy in #3196834: Material assets, types, quantities, inventory, and filtering.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.