Does this exist: Save values as "presets" on assets to apply to logs associated with them

I’m coming upon something and want to know if others have thought of it, or if there’s a generalized solution.

There are times when, usually an asset, contains a value that is saved and often needs to be applied to things which are associated with that asset. Think of it like a ‘preset’ or ‘auto-fill’ value. Here are the cases I have had, or have - it’s easier to see through examples.

Examples:

  1. A seed asset contains a seeding rate. When a plant asset is created using that seed asset, the seeding rate is copied in as a quantity.
  2. (this is my real, today problem) A field has a ‘bed_width’. When a planting is seeding or transplanted into that field, the seeding or transplanting log gets the bed_width quantity added.
  3. A tractor asset contains ‘miles_per_gallon’. I add a plowing log associated with that tractor, and the plowing log gets a quantity ‘miles_per_gallon’. With my entered odometer readings, it can calculate the estimated energy usage.

I vaguely remember a kind of ‘calculate’ feature (wrong name I think…) which allows you to do some math and generate another value on a log or asset. Perhaps this is just a calculate type function?

Curious of any thoughts/opinions or if this is something other people experience with other examples.

1 Like

Ideally this information would be stored on the plant_type taxonomy term, which is shared by both plant and seed assets.

Probably makes sense for this to just be some bespoke event subscriber logic in a custom module. Sounds like a convention (with some additional data model requirements) that would be well suited for a small module.

This particular example probably makes more sense as a “computed” value than a strict miles_per_gallon property on the tractor asset. Instead, I would probably develop a convention with two logs:

  1. tractor use, which records start/end odometer readings
  2. tractor fuel tank fills, which records how much fuel was added

After collecting some data, you can calculate a crude average fuel consumption rate. This could be shown in a report or a little widget on the tractor asset itself.

Drupal has a concept of a “computed” field, which does not store a static value in the database but instead can run PHP logic to figure out a value on-the-fly (and cache it).

(That link seems to be a good source of info… searching for “drupal computed field” is less useful because it returns info about an old contrib module, but what I’m talking about it Drupal core functionality.)

We use computed fields in farmOS for “current location” of an asset, among some other things.

1 Like