commit cff83d30e95eb9081e02d0538864b6bb1b2e44b2 Author: matze Date: Tue Dec 10 15:54:55 2024 +0100 removed cost calculation (do dynamically) diff --git a/config/install/asset.type.batch.yml b/config/install/asset.type.batch.yml new file mode 100644 index 0000000..458bae8 --- /dev/null +++ b/config/install/asset.type.batch.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: batch +label: Batch +description: 'Batch Asset' +name_pattern: 'Batch asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/asset.type.chemical.yml b/config/install/asset.type.chemical.yml new file mode 100644 index 0000000..53b7388 --- /dev/null +++ b/config/install/asset.type.chemical.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: chemical +label: Chemical +description: 'Chemical Asset' +name_pattern: 'Chemical asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/asset.type.ingredient.yml b/config/install/asset.type.ingredient.yml new file mode 100644 index 0000000..919eaad --- /dev/null +++ b/config/install/asset.type.ingredient.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: ingredient +label: Ingredient +description: 'Ingredient Asset' +name_pattern: 'Ingredient asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/asset.type.machine.yml b/config/install/asset.type.machine.yml new file mode 100644 index 0000000..1c55c2f --- /dev/null +++ b/config/install/asset.type.machine.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: machine +label: Machine +description: 'Machine Asset' +name_pattern: 'Machine asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/asset.type.patch.yml b/config/install/asset.type.patch.yml new file mode 100644 index 0000000..e007036 --- /dev/null +++ b/config/install/asset.type.patch.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: patch +label: Patch +description: 'Patch Asset' +name_pattern: 'Patch asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/asset.type.substance.yml b/config/install/asset.type.substance.yml new file mode 100644 index 0000000..d5bec1d --- /dev/null +++ b/config/install/asset.type.substance.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: substance +label: Substance +description: 'Substance Asset' +name_pattern: 'Substance asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/asset.type.usage_machine.yml b/config/install/asset.type.usage_machine.yml new file mode 100644 index 0000000..c97cf7c --- /dev/null +++ b/config/install/asset.type.usage_machine.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: usage_machine +label: MachineUsage +description: 'Machine Usage Asset' +name_pattern: 'MachineUsage asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/asset.type.usage_substance.yml b/config/install/asset.type.usage_substance.yml new file mode 100644 index 0000000..dbdc969 --- /dev/null +++ b/config/install/asset.type.usage_substance.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: usage_substance +label: SubstanceUsage +description: 'Substance Usage Asset' +name_pattern: 'SubstanceUsage asset [asset:id]' +workflow: asset_default +new_revision: true \ No newline at end of file diff --git a/config/install/log.type.field_work.yml b/config/install/log.type.field_work.yml new file mode 100644 index 0000000..6b75d84 --- /dev/null +++ b/config/install/log.type.field_work.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - farm_agrikern +id: field_work +label: FieldWork +description: 'Field work log' +name_pattern: 'Field work log [log:id]' +workflow: farm_log_workflow +new_revision: true diff --git a/farm_agrikern.info.yml b/farm_agrikern.info.yml new file mode 100644 index 0000000..1d3e7f6 --- /dev/null +++ b/farm_agrikern.info.yml @@ -0,0 +1,12 @@ +name: AgriKern +description: Customize the farmOS datamodel to fit a central european agriculture farm. +type: module +package: farmOS Contrib +core_version_requirement: ^10 +dependencies: + - farm:farm_entity + - farm:asset + - farm:log + - farm_land + - farm_season + - fraction \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/Batch.php b/src/Plugin/Asset/AssetType/Batch.php new file mode 100644 index 0000000..1a23084 --- /dev/null +++ b/src/Plugin/Asset/AssetType/Batch.php @@ -0,0 +1,43 @@ + [ + 'type' => 'entity_reference', + 'label' => $this->t('Substance'), + 'description' => $this->t('What substance was added?'), + 'target_type' => 'asset', + 'target_bundle' => 'substance', + 'multiple' => FALSE, + 'required' => TRUE, + ], + 'unit_price_field' => [ + 'type' => 'fraction', + 'label' => $this->t('Unit price'), + 'description' => $this->t('Price in Euro per unit of the substance. Price is positive if the batch was pruchased and is negative if the batch was produced.'), + 'required' => TRUE, + ], + ]; + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/Chemical.php b/src/Plugin/Asset/AssetType/Chemical.php new file mode 100644 index 0000000..dda418f --- /dev/null +++ b/src/Plugin/Asset/AssetType/Chemical.php @@ -0,0 +1,23 @@ + [ + 'type' => 'entity_reference', + 'label' => $this->t('Chemical'), + 'description' => $this->t('What chemical does the ingredient track?'), + 'target_type' => 'asset', + 'target_bundle' => 'chemical', + 'multiple' => FALSE, + 'required' => TRUE, + ], + 'amount_field' => [ + 'type' => 'fraction', + 'label' => $this->t('Amount'), + 'description' => $this->t('How much of the chemical is in the ingredient in g/l'), + 'required' => TRUE, + ], + ]; + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/Machine.php b/src/Plugin/Asset/AssetType/Machine.php new file mode 100644 index 0000000..2ae1e18 --- /dev/null +++ b/src/Plugin/Asset/AssetType/Machine.php @@ -0,0 +1,44 @@ + [ + 'type' => 'fraction', + 'label' => $this->t('Unit price'), + 'description' => $this->t('Price in Euro per unit of usage on the machine.'), + 'required' => TRUE, + ], + 'unit_field' => [ + 'type' => 'entity_reference', + 'label' => $this->t('Unit'), + 'description' => $this->t('What unit is used to track machine usage?'), + 'target_type' => 'taxonomy_term', + 'target_bundle' => 'unit', + 'auto_create' => TRUE, + 'multiple' => FALSE, + 'required' => TRUE, + ], + ]; + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/MachineUsage.php b/src/Plugin/Asset/AssetType/MachineUsage.php new file mode 100644 index 0000000..cd04c27 --- /dev/null +++ b/src/Plugin/Asset/AssetType/MachineUsage.php @@ -0,0 +1,37 @@ + [ + 'type' => 'entity_reference', + 'label' => $this->t('Machine'), + 'description' => $this->t('What machine was used?'), + 'target_type' => 'asset', + 'target_bundle' => 'machine', + 'multiple' => FALSE, + 'required' => TRUE, + ], + ]; + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/Patch.php b/src/Plugin/Asset/AssetType/Patch.php new file mode 100644 index 0000000..087ab1b --- /dev/null +++ b/src/Plugin/Asset/AssetType/Patch.php @@ -0,0 +1,66 @@ + [ + 'type' => 'entity_reference', + 'label' => $this->t('Land'), + 'description' => $this->t("At what Land asset is the patch located?"), + 'target_type' => 'asset', + 'target_bundle' => 'land', + 'required' => TRUE, + 'multiple' => FALSE, + ], + 'crop_field' => [ + 'type' => 'entity_reference', + 'label' => $this->t('Crop/variety'), + 'description' => $this->t("Enter this patch asset's crop/variety."), + 'target_type' => 'taxonomy_term', + 'target_bundle' => 'crop', + 'auto_create' => TRUE, + 'required' => TRUE, + 'multiple' => FALSE, + ], + 'season_field' => [ + 'type' => 'entity_reference', + 'label' => $this->t('Season'), + 'description' => $this->t('Assign this to a season for easier searching later.'), + 'target_type' => 'taxonomy_term', + 'target_bundle' => 'season', + 'auto_create' => TRUE, + 'multiple' => FALSE, + 'required' => TRUE, + ], + 'area_field' => [ + 'type' => 'fraction', + 'label' => $this->t('Area'), + 'description' => $this->t('What is the area of the patch in hectares (ha)?'), + 'required' => TRUE, + ], + ]; + + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/Substance.php b/src/Plugin/Asset/AssetType/Substance.php new file mode 100644 index 0000000..ae5b235 --- /dev/null +++ b/src/Plugin/Asset/AssetType/Substance.php @@ -0,0 +1,47 @@ + 'entity_reference', + 'label' => $this->t('Ingredients'), + 'description' => $this->t('What ingredients are in the substance?'), + 'target_type' => 'asset', + 'target_bundle' => 'ingredient', + 'multiple' => TRUE, + 'required' => FALSE, + ]; + $fields['ingredients_field'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options) + ->addConstraint('AgriKernSubstanceIngredients'); + + $options = [ + 'type' => 'entity_reference', + 'label' => $this->t('Unit'), + 'description' => $this->t('What unit is the substance measured in?'), + 'target_type' => 'taxonomy_term', + 'target_bundle' => 'unit', + 'auto_create' => TRUE, + 'multiple' => FALSE, + 'required' => TRUE, + ]; + $fields['unit_field'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options); + + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/SubstanceUsage.php b/src/Plugin/Asset/AssetType/SubstanceUsage.php new file mode 100644 index 0000000..8899bf0 --- /dev/null +++ b/src/Plugin/Asset/AssetType/SubstanceUsage.php @@ -0,0 +1,37 @@ + [ + 'type' => 'entity_reference', + 'label' => $this->t('Batch'), + 'description' => $this->t('What batch of the substance was used?'), + 'target_type' => 'asset', + 'target_bundle' => 'batch', + 'multiple' => FALSE, + 'required' => TRUE, + ], + ]; + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Asset/AssetType/Usage.php b/src/Plugin/Asset/AssetType/Usage.php new file mode 100644 index 0000000..e05f2f5 --- /dev/null +++ b/src/Plugin/Asset/AssetType/Usage.php @@ -0,0 +1,36 @@ + [ + 'type' => 'fraction', + 'label' => $this->t('Amount'), + 'description' => $this->t('How much was the quantiy used in the quantities unit of measurement?'), + 'required' => TRUE, + ], + // This field is automatically filled using LogEventSubscriber + 'cost_field' => [ + 'type' => 'fraction', + 'label' => $this->t('Cost'), + 'description' => $this->t('THIS FIELD IS GENERATED AUTOMATICALLY AND SHOULD NOT BE ADJUSTED!'), + 'required' => FALSE, + ], + ]; + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + return $fields; + } +} \ No newline at end of file diff --git a/src/Plugin/Log/LogType/FieldWork.php b/src/Plugin/Log/LogType/FieldWork.php new file mode 100644 index 0000000..e065d02 --- /dev/null +++ b/src/Plugin/Log/LogType/FieldWork.php @@ -0,0 +1,53 @@ + [ + 'type' => 'entity_reference', + 'label' => $this->t('Patch'), + 'description' => $this->t("What patch was the work done on?"), + 'target_type' => 'asset', + 'target_bundle' => 'patch', + 'required' => TRUE, + 'multiple' => FALSE, + ], + ]; + + foreach ($field_info as $name => $info) { + $fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info); + } + + $options = [ + 'type' => 'entity_reference', + 'label' => $this->t('Machine usages'), + 'description' => $this->t('What machines were used and how much?'), + 'target_type' => 'asset', + 'target_bundle' => 'usage_machine', + 'multiple' => TRUE, + 'required' => TRUE, + + ]; + $fields['machine_usages_field'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options) + ->addConstraint('AgriKernFieldWorkMachines'); + + return $fields; + } +} diff --git a/src/Plugin/Validation/Constraint/FieldWorkMachinesConstraint.php b/src/Plugin/Validation/Constraint/FieldWorkMachinesConstraint.php new file mode 100644 index 0000000..303c7e1 --- /dev/null +++ b/src/Plugin/Validation/Constraint/FieldWorkMachinesConstraint.php @@ -0,0 +1,27 @@ + $item) { + $machine_usage = \Drupal::entityTypeManager()->getStorage('asset')->load($item->target_id); + $machine_id = $machine_usage->machine_field->target_id; + if (isset($seen_machines[$machine_id])) { + $this->context->buildViolation($constraint->notUnique) + ->atPath($delta) + ->addViolation(); + } + $seen_machines[$machine_id] = true; + } + } + +} diff --git a/src/Plugin/Validation/Constraint/SubstanceIngredientsConstraint.php b/src/Plugin/Validation/Constraint/SubstanceIngredientsConstraint.php new file mode 100644 index 0000000..873c2e1 --- /dev/null +++ b/src/Plugin/Validation/Constraint/SubstanceIngredientsConstraint.php @@ -0,0 +1,27 @@ + $item) { + $ingredient = \Drupal::entityTypeManager()->getStorage('asset')->load($item->target_id); + $chemical_id = $ingredient->chemical_field->target_id; + if (isset($seen_quantities[$chemical_id])) { + $this->context->buildViolation($constraint->notUnique) + ->atPath($delta) + ->addViolation(); + } + $seen_quantities[$chemical_id] = true; + } + } +}