Issue #3220623: Split Sale/Purchase/Price bundles out to contrib
This commit is contained in:
parent
c48e380295
commit
89996482be
|
@ -218,6 +218,9 @@ farmOS 1.x an Activity log was `farm_activity`, and in farmOS 2.x it is simply
|
|||
Additionally, the "Soil test" and "Water test" log types have been merged into
|
||||
a single "Lab test" log type.
|
||||
|
||||
Also note that "Sale" and "Purchase" logs have been moved out of farmOS core to
|
||||
a new [farmOS Ledger](https://drupal.org/project/farm_ledger) module.
|
||||
|
||||
Below is the full list of log types in farmOS 1.x and their new names in 2.x:
|
||||
|
||||
- `farm_activity` -> `activity`
|
||||
|
@ -226,8 +229,6 @@ Below is the full list of log types in farmOS 1.x and their new names in 2.x:
|
|||
- `farm_maintenance` -> `maintenance`
|
||||
- `farm_medical` -> `medical`
|
||||
- `farm_observation` -> `observation`
|
||||
- `farm_purchase` -> `purchase`
|
||||
- `farm_sale` -> `sale`
|
||||
- `farm_seeding` -> `seeding`
|
||||
- `farm_soil_test` -> `lab_test`
|
||||
- `farm_transplanting` -> `transplanting`
|
||||
|
|
|
@ -18,8 +18,6 @@ included with farmOS define the following Log types:
|
|||
- Lab test
|
||||
- Maintenance
|
||||
- Medical
|
||||
- Purchase
|
||||
- Sale
|
||||
- Seeding
|
||||
- Transplanting
|
||||
|
||||
|
@ -286,22 +284,6 @@ Medical Logs have the following additional attributes:
|
|||
|
||||
- Veterinarian (string)
|
||||
|
||||
#### Purchase Logs
|
||||
|
||||
Purchase Logs have the following additional attributes:
|
||||
|
||||
- Invoice number (string)
|
||||
- Seller (string)
|
||||
- Lot number (string)
|
||||
|
||||
#### Sale Logs
|
||||
|
||||
Sale Logs have the following additional attributes:
|
||||
|
||||
- Customer (string)
|
||||
- Invoice number (string)
|
||||
- Lot number (string)
|
||||
|
||||
#### Seeding Logs
|
||||
|
||||
Seeding Logs have the following additional attributes:
|
||||
|
|
|
@ -18,7 +18,6 @@ their module is enabled. The modules included with farmOS define the following
|
|||
Quantity types:
|
||||
|
||||
- Standard
|
||||
- Price
|
||||
|
||||
## ID
|
||||
|
||||
|
@ -127,11 +126,3 @@ above, some types add additional type-specific fields. These include:
|
|||
#### Standard Quantities
|
||||
|
||||
Standard Quantities do not define any type-specific fields.
|
||||
|
||||
#### Price Quantities
|
||||
|
||||
Price Quantities have additional "Unit Price" and "Unit Quantity" attributes,
|
||||
alongside the standard "Value" attribute. When these are used, the "Value"
|
||||
attribute is considered to be the total value ("Unit Price" multiplied by
|
||||
"Unit Quantity"). The "Units" of a Price Quantity will generally be a
|
||||
currency code such as "USD" or "EUR".
|
||||
|
|
|
@ -52,8 +52,6 @@ function farm_modules() {
|
|||
'farm_lab_test' => t('Lab test logs'),
|
||||
'farm_birth' => t('Birth logs'),
|
||||
'farm_medical' => t('Medical logs'),
|
||||
'farm_purchase' => t('Purchase logs'),
|
||||
'farm_sale' => t('Sale logs'),
|
||||
'farm_kml' => t('KML export features'),
|
||||
'farm_import_kml' => t('KML asset importer'),
|
||||
],
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- farm_migrate
|
||||
- farm_purchase
|
||||
id: farm_migrate_log_purchase
|
||||
label: 'Logs (Purchases)'
|
||||
migration_group: farm_migrate_log
|
||||
migration_tags:
|
||||
- 'Drupal 7'
|
||||
- 'farmOS 1.x'
|
||||
class: Drupal\migrate\Plugin\Migration
|
||||
field_plugin_method: null
|
||||
cck_plugin_method: null
|
||||
source:
|
||||
plugin: d7_farm_log
|
||||
bundle: farm_purchase
|
||||
destination:
|
||||
plugin: 'entity:log'
|
||||
process:
|
||||
# Hard-code the bundle.
|
||||
type:
|
||||
plugin: default_value
|
||||
default_value: purchase
|
||||
# Maintain the log ID.
|
||||
id:
|
||||
plugin: get
|
||||
source: id
|
||||
# Get the price quantity units.
|
||||
_units:
|
||||
plugin: migration_lookup
|
||||
migration: farm_migrate_taxonomy_unit
|
||||
source: field_farm_quantity_units
|
||||
# Create a price quantity.
|
||||
quantity/0:
|
||||
# First collect all of the price data.
|
||||
-
|
||||
plugin: get
|
||||
source:
|
||||
- field_farm_quantity_units
|
||||
- field_farm_total_price
|
||||
- field_farm_quantity_value
|
||||
- field_farm_unit_price
|
||||
# Flatten the arrays to one dimension.
|
||||
-
|
||||
plugin: flatten
|
||||
# Check if any values were provided.
|
||||
-
|
||||
plugin: null_coalesce
|
||||
# Skip if no price data was provided.
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: process
|
||||
# Create a single price quantity.
|
||||
-
|
||||
plugin: create_quantity
|
||||
default_values:
|
||||
type: 'price'
|
||||
measure: 'value'
|
||||
values:
|
||||
uid: '@uid'
|
||||
created: '@created'
|
||||
changed: '@changed'
|
||||
value: field_farm_total_price
|
||||
units: '@_units'
|
||||
unit_quantity: field_farm_quantity_value
|
||||
unit_price: field_farm_unit_price
|
||||
# Purchase specific fields.
|
||||
invoice_number:
|
||||
plugin: get
|
||||
source: field_farm_invoice_number
|
||||
seller:
|
||||
plugin: get
|
||||
source: field_farm_seller
|
||||
lot_number:
|
||||
plugin: get
|
||||
source: field_farm_lot_number
|
||||
migration_dependencies:
|
||||
required: { }
|
||||
optional: { }
|
|
@ -1,82 +0,0 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- farm_migrate
|
||||
- farm_sale
|
||||
id: farm_migrate_log_sale
|
||||
label: 'Logs (Sales)'
|
||||
migration_group: farm_migrate_log
|
||||
migration_tags:
|
||||
- 'Drupal 7'
|
||||
- 'farmOS 1.x'
|
||||
class: Drupal\migrate\Plugin\Migration
|
||||
field_plugin_method: null
|
||||
cck_plugin_method: null
|
||||
source:
|
||||
plugin: d7_farm_log
|
||||
bundle: farm_sale
|
||||
destination:
|
||||
plugin: 'entity:log'
|
||||
process:
|
||||
# Hard-code the bundle.
|
||||
type:
|
||||
plugin: default_value
|
||||
default_value: sale
|
||||
# Maintain the log ID.
|
||||
id:
|
||||
plugin: get
|
||||
source: id
|
||||
# Get the price quantity units.
|
||||
_units:
|
||||
plugin: migration_lookup
|
||||
migration: farm_migrate_taxonomy_unit
|
||||
source: field_farm_quantity_units
|
||||
# Create a price quantity.
|
||||
quantity/0:
|
||||
# First collect all of the price data.
|
||||
-
|
||||
plugin: get
|
||||
source:
|
||||
- field_farm_quantity_units
|
||||
- field_farm_total_price
|
||||
- field_farm_quantity_value
|
||||
- field_farm_unit_price
|
||||
# Flatten the arrays to one dimension.
|
||||
-
|
||||
plugin: flatten
|
||||
# Check if any values were provided.
|
||||
-
|
||||
plugin: null_coalesce
|
||||
# Skip if no price data was provided.
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: process
|
||||
# Create a single price quantity.
|
||||
-
|
||||
plugin: create_quantity
|
||||
default_values:
|
||||
type: 'price'
|
||||
measure: 'value'
|
||||
values:
|
||||
uid: '@uid'
|
||||
created: '@created'
|
||||
changed: '@changed'
|
||||
value: field_farm_total_price
|
||||
units: '@_units'
|
||||
unit_quantity: field_farm_quantity_value
|
||||
unit_price: field_farm_unit_price
|
||||
# Sale specific fields.
|
||||
customer:
|
||||
plugin: get
|
||||
source: field_farm_customer
|
||||
invoice_number:
|
||||
plugin: get
|
||||
source: field_farm_invoice_number
|
||||
lot_number:
|
||||
plugin: get
|
||||
source: field_farm_lot_number
|
||||
migration_dependencies:
|
||||
required: { }
|
||||
optional: { }
|
|
@ -1,17 +0,0 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- farm_log_quantity
|
||||
enforced:
|
||||
module:
|
||||
- farm_purchase
|
||||
id: purchase
|
||||
label: Purchase
|
||||
description: ''
|
||||
name_pattern: 'Purchase log [log:id]'
|
||||
workflow: log_default
|
||||
new_revision: true
|
||||
third_party_settings:
|
||||
farm_log_quantity:
|
||||
default_quantity_type: price
|
|
@ -1,8 +0,0 @@
|
|||
name: Purchase log
|
||||
description: Adds a Purchase log type.
|
||||
type: module
|
||||
package: farmOS Logs
|
||||
core_version_requirement: ^9
|
||||
dependencies:
|
||||
- farm:farm_entity
|
||||
- farm:farm_quantity_price
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_purchase\Plugin\Log\LogType;
|
||||
|
||||
use Drupal\farm_entity\Plugin\Log\LogType\FarmLogType;
|
||||
|
||||
/**
|
||||
* Provides the purchase log type.
|
||||
*
|
||||
* @LogType(
|
||||
* id = "purchase",
|
||||
* label = @Translation("Purchase"),
|
||||
* )
|
||||
*/
|
||||
class Purchase extends FarmLogType {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildFieldDefinitions() {
|
||||
$fields = parent::buildFieldDefinitions();
|
||||
|
||||
// Invoice number.
|
||||
$options = [
|
||||
'type' => 'string',
|
||||
'label' => $this->t('Invoice number'),
|
||||
'weight' => [
|
||||
'form' => 20,
|
||||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['invoice_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Seller.
|
||||
$options = [
|
||||
'type' => 'string',
|
||||
'label' => $this->t('Seller'),
|
||||
'weight' => [
|
||||
'form' => 20,
|
||||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['seller'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Lot number.
|
||||
$options = [
|
||||
'type' => 'string',
|
||||
'label' => $this->t('Lot number'),
|
||||
'weight' => [
|
||||
'form' => 20,
|
||||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['lot_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- farm_log_quantity
|
||||
enforced:
|
||||
module:
|
||||
- farm_sale
|
||||
id: sale
|
||||
label: Sale
|
||||
description: ''
|
||||
name_pattern: 'Sale log [log:id]'
|
||||
workflow: log_default
|
||||
new_revision: true
|
||||
third_party_settings:
|
||||
farm_log_quantity:
|
||||
default_quantity_type: price
|
|
@ -1,8 +0,0 @@
|
|||
name: Sale log
|
||||
description: Adds a Sale log type.
|
||||
type: module
|
||||
package: farmOS Logs
|
||||
core_version_requirement: ^9
|
||||
dependencies:
|
||||
- farm:farm_entity
|
||||
- farm:farm_quantity_price
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_sale\Plugin\Log\LogType;
|
||||
|
||||
use Drupal\farm_entity\Plugin\Log\LogType\FarmLogType;
|
||||
|
||||
/**
|
||||
* Provides the sale log type.
|
||||
*
|
||||
* @LogType(
|
||||
* id = "sale",
|
||||
* label = @Translation("Sale"),
|
||||
* )
|
||||
*/
|
||||
class Sale extends FarmLogType {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildFieldDefinitions() {
|
||||
$fields = parent::buildFieldDefinitions();
|
||||
|
||||
// Customer.
|
||||
$options = [
|
||||
'type' => 'string',
|
||||
'label' => $this->t('Customer'),
|
||||
'weight' => [
|
||||
'form' => 20,
|
||||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['customer'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Invoice number.
|
||||
$options = [
|
||||
'type' => 'string',
|
||||
'label' => $this->t('Invoice number'),
|
||||
'weight' => [
|
||||
'form' => 20,
|
||||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['invoice_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Lot number.
|
||||
$options = [
|
||||
'type' => 'string',
|
||||
'label' => $this->t('Lot number'),
|
||||
'weight' => [
|
||||
'form' => 20,
|
||||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['lot_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
enforced:
|
||||
module:
|
||||
- farm_quantity_price
|
||||
id: price
|
||||
label: Price
|
||||
description: 'Price quantity type.'
|
||||
new_revision: true
|
|
@ -1,8 +0,0 @@
|
|||
name: Price quantity
|
||||
description: Provides a price quantity type.
|
||||
type: module
|
||||
package: farmOS Quantities
|
||||
core_version_requirement: ^9
|
||||
dependencies:
|
||||
- farm:farm_entity
|
||||
- farm:quantity
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Farm_quantity_price module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function farm_quantity_price_theme() {
|
||||
return [
|
||||
'quantity__price' => [
|
||||
'render element' => 'elements',
|
||||
'base hook' => 'quantity',
|
||||
],
|
||||
];
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides Views data for farm_quantity_price.module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data_alter().
|
||||
*/
|
||||
function farm_quantity_price_views_data_alter(array &$data) {
|
||||
|
||||
// Create unit price field, filter, and sort using fraction decimal handlers.
|
||||
$fraction_fields = [
|
||||
'numerator' => 'unit_price_numerator',
|
||||
'denominator' => 'unit_price_denominator',
|
||||
];
|
||||
$data['quantity__unit_price']['unit_price_value'] = [
|
||||
'title' => t('Unit price'),
|
||||
'help' => t('Value of the unit price, in decimal format.'),
|
||||
'real field' => 'unit_price_numerator',
|
||||
'field' => [
|
||||
'id' => 'fraction',
|
||||
'additional fields' => $fraction_fields,
|
||||
'click sortable' => TRUE,
|
||||
],
|
||||
'sort' => [
|
||||
'id' => 'fraction',
|
||||
'additional fields' => $fraction_fields,
|
||||
],
|
||||
'filter' => [
|
||||
'id' => 'fraction',
|
||||
'additional fields' => $fraction_fields,
|
||||
],
|
||||
];
|
||||
|
||||
// Create unit quantity field, filter, and sort using fraction decimal
|
||||
// handlers.
|
||||
$fraction_fields = [
|
||||
'numerator' => 'unit_quantity_numerator',
|
||||
'denominator' => 'unit_quantity_denominator',
|
||||
];
|
||||
$data['quantity__unit_quantity']['unit_quantity_value'] = [
|
||||
'title' => t('Unit quantity'),
|
||||
'help' => t('Value of the unit quantity, in decimal format.'),
|
||||
'real field' => 'unit_quantity_numerator',
|
||||
'field' => [
|
||||
'id' => 'fraction',
|
||||
'additional fields' => $fraction_fields,
|
||||
'click sortable' => TRUE,
|
||||
],
|
||||
'sort' => [
|
||||
'id' => 'fraction',
|
||||
'additional fields' => $fraction_fields,
|
||||
],
|
||||
'filter' => [
|
||||
'id' => 'fraction',
|
||||
'additional fields' => $fraction_fields,
|
||||
],
|
||||
];
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_quantity_price\Plugin\Quantity\QuantityType;
|
||||
|
||||
use Drupal\farm_entity\Plugin\Quantity\QuantityType\FarmQuantityType;
|
||||
|
||||
/**
|
||||
* Provides the price quantity type.
|
||||
*
|
||||
* @QuantityType(
|
||||
* id = "price",
|
||||
* label = @Translation("Price"),
|
||||
* )
|
||||
*/
|
||||
class Price extends FarmQuantityType {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildFieldDefinitions() {
|
||||
|
||||
// Inherit default quantity fields.
|
||||
$fields = parent::buildFieldDefinitions();
|
||||
|
||||
// Add unit_quantity and unit_price fraction fields.
|
||||
$field_info = [
|
||||
'unit_quantity' => [
|
||||
'type' => 'fraction',
|
||||
'label' => $this->t('Unit quantity'),
|
||||
'description' => $this->t('How many were purchased?'),
|
||||
'weight' => [
|
||||
'form' => 3,
|
||||
],
|
||||
'view_display_options' => [
|
||||
'label' => 'hidden',
|
||||
'type' => 'fraction_decimal',
|
||||
'settings' => [
|
||||
'precision' => 0,
|
||||
'auto_precision' => TRUE,
|
||||
'separator' => '/',
|
||||
'prefix_suffix' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
'unit_price' => [
|
||||
'type' => 'fraction',
|
||||
'label' => $this->t('Unit price'),
|
||||
'weight' => [
|
||||
'form' => 3,
|
||||
],
|
||||
'view_display_options' => [
|
||||
'label' => 'hidden',
|
||||
'type' => 'fraction_decimal',
|
||||
'settings' => [
|
||||
'precision' => 0,
|
||||
'auto_precision' => TRUE,
|
||||
'separator' => '/',
|
||||
'prefix_suffix' => FALSE,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
foreach ($field_info as $name => $info) {
|
||||
$fields[$name] = $this->farmFieldFactory->bundleFieldDefinition($info);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
{#
|
||||
/**
|
||||
* @file quantity--price.html.twig
|
||||
*
|
||||
* This template is used when viewing price quantity entities.
|
||||
*
|
||||
*
|
||||
* Available variables:
|
||||
* - quantity: The quantity entity.
|
||||
* - content: A list of content items. Use 'content' to print all content, or
|
||||
* - attributes: HTML attributes for the container element.
|
||||
*
|
||||
* @see template_preprocess_quantity()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('quantity') }}>
|
||||
{% if content %}
|
||||
{% if content.label %}<strong>{{ content.label }}</strong>{% endif %}
|
||||
<span>{{ content.value }}</span>
|
||||
<span>({{ content.unit_quantity }} {{ content.units }} x {{ content.unit_price }})</span>
|
||||
{% endif %}
|
||||
</div>
|
Loading…
Reference in New Issue