Problem/Motivation

The "Quantity" field is a field collection with two sub-fields: "Value" (fraction field) and "Units" (taxonomy term reference field), which is available on many log types in farmOS.

Currently, Quantity field instances only allow a single quantity to be entered.

It is very easy to allow multiple quantities, simply by changing the field instance's "Number of values" setting to "Unlimited". This will allow users to click "Add another" to add multiple quantities to a log.

However, with only "Value" and "Units" as sub-fields, there is no clear way to differentiate the different quantities entered. Intuitively it may be possible, but not programatically.

Proposed resolution

The proposed resolution is to add two additional sub-fields to the Quantity field collection, in addition to making it a multi-value field:

  • Measure - A dropdown list of specific forms of measurement (Count, Length, Weight, etc)
  • Label - An arbitrary textfield that allows the quantity measurement to be labelled, for further differentiation

Both of these sub-fields would be optional. The "Units" field would also be made optional - so it will be up to the user to decide which fields they need for a proper measurement. This will allow a lot of flexibility in data capture.

Below is the initial list of "Measure" options that we will start with. More can be identified/added in the future.

  • Count
  • Length
  • Weight
  • Volume
  • Time
  • Temperature
  • Water content
  • Value
  • Rating
  • Ratio
  • Probability

Remaining tasks

  • Add a Measure field to Quantities.
  • Add a function that defines the available options for the Measure field.
  • Update Quantity field instance descriptions to include Measure.
  • Add a Label field to Quantities.
  • Allow multiple quantities to be entered on each log. Hide initial form and require user to add first item.
  • Make "Units" field not required.
  • ...

User interface changes

  • New Quantity sub-fields: Measure and Label
  • Click "Add additional item" to add Quantity field collections to logs.

API changes

None

Data model changes

  • New Quantity sub-fields: Measure and Label

Comments

m.stenta created an issue. See original summary.

m.stenta’s picture

Title: Add Quantity Measure and Label fields » Enable multiple quantity measurements per log
Issue summary: View changes

Changed the title to reflect that the primary motivation for doing this is to accommodate multi-value quantity fields. Without a "Measure" and/or "Label", it will be impossible to tell multiple quantities apart.

Also added template sections with initial content for the "Problem/Motivation" and "Proposed resolution" sections.

m.stenta’s picture

Issue summary: View changes

Filled in "User interface changes", "API changes", and "Data model changes".

m.stenta’s picture

One big thing that we'll need to figure out is how to handle this on import/export. We use Feeds to provide a CSV importer for each log type, and Views Data Export to provide a CSV export for all lists. Currently there is just two CSV columns that map to the single quantity field that exists currently: "Quantity Value" and "Quantity Units". CSVs are inherently flat, so supporting multi-value fields is a bit tricky. It's been done before in Drupal, but we'll have to review approaches and decide what will work best in farmOS.

To start, it may make sense to only allow a single quantity to be imported via CSV.

Exports are a little trickier. I recently separated the "Quantity" column into "Quantity Value" and "Quantity Units" columns, for easier export.

Ultimately, I think we are going to want a more focused "Quantity Report Generator" that can slice/dice the data and provide more specific CSV exports based on what you want.

m.stenta’s picture

Issue summary: View changes
m.stenta’s picture

Issue summary: View changes

Added the initial list of "Measure" options.

  • m.stenta committed d228918 on 7.x-1.x
    Issue #2912520: Enable multiple quantity measurements per log
    
m.stenta’s picture

Status: Active » Fixed

Done!

Status: Fixed » Closed (fixed)

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

farmOS Eastern’s picture

Can I ask for this topic has been resolved on farmOS v1?
I am currently importing .csv log_farm_input_template with no idea how to add "multiple quantity measurements per log" as @m.stenta mention on this topic.
My manager request test on farmOS with real data on-premise (which installed by our technical team already).
I'm a foreigner with far distance from US agriculture way so, there something need to adjustable to close GAP.

Thanks, looking for improvement on Drupal
(The last version Drupal our team has work in for a customer who run their business at Sport field (for national organization: Singapore)

m.stenta’s picture

@farmOS Eastern: This issue was closed in 2017, and was specifically about enabling multiple quantities at the data model level in farmOS 1.x. If you have questions the best place to ask is in the community forum (https://farmOS.discourse.group) or chat room (https://app.element.io/#/room/#farmOS:matrix.org).