# Create asset upon purchase?

**URL:** <https://farmos.discourse.group/t/create-asset-upon-purchase/207>\
**Category:** Using farmOS\
**Created:** [January 27, 2020, 7:25am UTC](https://farmos.discourse.group/t/create-asset-upon-purchase/207 "2020-01-27T07:25:56Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [January 27, 2020, 3:25pm UTC](https://farmos.discourse.group/t/create-asset-upon-purchase/207/2 "2020-01-27T15:25:25Z")

</div>

There is a module for Drupal called Rules which may be able to help with this: [https://drupal.org/project/rules](https://drupal.org/project/rules) - it allows you to configure trigger/event logic via the UI - no coding required.

See my comment in this related issue for more information: [Schedule a log based on a quantity value](https://farmos.discourse.group/t/schedule-a-log-based-on-a-quantity-value/115/4)

I’ve decided NOT to include Rules in farmOS 1.x because it does not have an automated upgrade path to Drupal 8, so it would add a hurdle to our upgrade process. If you self-host farmOS you are welcome to install it and play around - just know that it may need to be redone when we migrate to farmOS 2.x

Alternatively, it would be relatively simple to code this in a custom module using `hook_entity_insert()`: [https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook\_entity\_insert/7.x](https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_insert/7.x)

Something like:

```php
/**
 * Implements hook_entity_insert().
 */
function mymodule_entity_insert($entity, $type) {

  // If this is a purchase log, create an asset.
  if ($type == 'log' && $entity->type = 'farm_purchase') {
    
    $asset = array(
      'name' => 'My Asset',
      'type' => 'equipment',
    );
    farm_asset_save($asset);
  }
}

```

---

_[View the full topic](https://farmos.discourse.group/t/create-asset-upon-purchase/207)._
