Skip to content

Commit

Permalink
- Reinstated the order on demand feature, with additional setting to …
Browse files Browse the repository at this point in the history
…turn it on and off via the system configuration
  • Loading branch information
24198 committed Jul 7, 2021
1 parent 30cd7f3 commit 5391c9c
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function getConfigTreeBuilder()
],
'balance_threshold_percentage' => [
'value' => 0.20
],
'inventory_on_demand' => [
'value' => false
]
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ system_configuration:
title: marello.inventory.system_configuration.groups.inventory.balacing.general.label
inventory_balancing_strategy:
title: marello.inventory.system_configuration.groups.inventory.balacing.strategy.label

inventory_on_demand:
title: marello.inventory.system_configuration.groups.inventory.on_demand.title
icon: fa-cog
inventory_on_demand_general:
title: marello.inventory.system_configuration.groups.inventory.on_demand.general.label
fields:
marello_inventory.balance_threshold_percentage:
data_type: percent
Expand All @@ -30,6 +34,13 @@ system_configuration:
constraints:
- NotBlank: ~

marello_inventory.inventory_on_demand:
data_type: boolean
type: Oro\Bundle\ConfigBundle\Form\Type\ConfigCheckbox
options:
label: marello.inventory.system_configuration.fields.inventory_on_demand.label
required: false

tree:
system_configuration:
marello:
Expand All @@ -44,3 +55,8 @@ system_configuration:
inventory_balancing_strategy:
children:
- marello_inventory.balancing_strategy
inventory_on_demand:
children:
inventory_on_demand_general:
children:
- marello_inventory.inventory_on_demand
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ services:

marello_inventory.form.inventory_order_on_demand_validator:
class: 'Marello\Bundle\InventoryBundle\Validator\InventoryOrderOnDemandValidator'
calls:
- [setConfigManager, ['@oro_config.manager']]
tags:
- { name: validator.constraint_validator, alias: marello_inventory.order_on_demand_validator }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,13 @@ marello:
back_pre_orders:
title: Backorders/Pre-orders
general.label: General
on_demand:
title: Inventory On Demand
general.label: General
fields:
balancing_strategy.label: Strategy
balance_threshold_percentage.label: Threshold Percentage
inventory_on_demand.label: Use Purchase Order with inventory on demand
messages:
success:
warehouse.saved: Warehouse has been saved successfully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ marello:

inventoryitem:
desired_should_be_greater_than_purchase_inventory: Desired Inventory needs to be greater than or equal to the Purchase Inventory
order_on_demand_not_allowed_supplier: Order On Demand can't be allowed if Product has no Supplier
order_on_demand_not_allowed_backorder: Order On Demand can't be allowed if Backorder allowed
order_on_demand_not_allowed_preorder: Order On Demand can't be allowed if Pre-Order allowed
order_on_demand_not_allowed_supplier: Order On Demand is not allowed if Product has no Supplier configured
order_on_demand_not_allowed_backorder: Order On Demand is not allowed if Backorder allowed
order_on_demand_not_allowed_preorder: Order On Demand is not allowed if Pre-Order allowed
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@
}
] %}

{% set orderOnDemandAllowed = oro_config_value('marello_inventory.inventory_on_demand') %}
{% if orderOnDemandAllowed %}
{% set dataBlocks = dataBlocks|merge([{
'title': 'marello.inventory.inventoryitem.section.orderondemand.label'|trans,
'useSpan': false,
'subblocks': [
{ 'data' : [orderOnDemandInfoWidget] }
]
}])
%}
{% endif %}

{% set data = {
'formErrors': form_errors(form)? form_errors(form) : null,
'dataBlocks': dataBlocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@
}]
}])
%}
{% set orderOnDemandAllowed = oro_config_value('marello_inventory.inventory_on_demand') %}
{% if orderOnDemandAllowed %}
{% set dataBlocks = dataBlocks|merge([{
'title': 'marello.inventory.inventoryitem.section.orderondemand.label'|trans,
'useSpan': false,
'subblocks': [
{ 'data' : [orderOnDemandInfoWidget] }
]
}])
%}
{% endif %}

{% set data = { 'dataBlocks': dataBlocks } %}
{{ parent() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

use Oro\Bundle\ConfigBundle\Config\ConfigManager;

use Marello\Bundle\InventoryBundle\Entity\InventoryItem;

class InventoryOrderOnDemandValidator extends ConstraintValidator
{
/** @var ConfigManager $configManager */
private $configManager;

/**
* Checks if the passed entity is unique in collection.
* @param mixed $entity
Expand All @@ -22,11 +27,13 @@ public function validate($entity, Constraint $constraint)
return;
}
$product = $entity->getProduct();
if ($entity->isOrderOnDemandAllowed() &&
(!$product->getPreferredSupplier() || $product->getSuppliers()->count() === 0)) {
$this->context->buildViolation($constraint->message)
->atPath('orderOnDemandAllowed')
->addViolation();
if ($this->configManager->get('marello_inventory.inventory_on_demand')) {
if ($entity->isOrderOnDemandAllowed() &&
(!$product->getPreferredSupplier() || $product->getSuppliers()->count() === 0)) {
$this->context->buildViolation($constraint->message)
->atPath('orderOnDemandAllowed')
->addViolation();
}
}
if ($entity->isOrderOnDemandAllowed() && $entity->isBackorderAllowed()) {
$this->context
Expand All @@ -45,4 +52,12 @@ public function validate($entity, Constraint $constraint)
->addViolation();
}
}

/**
* @param ConfigManager $configManager
*/
public function setConfigManager(ConfigManager $configManager)
{
$this->configManager = $configManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostFlushEventArgs;

use Oro\Bundle\ConfigBundle\Config\ConfigManager;

use Marello\Bundle\InventoryBundle\Entity\Warehouse;
use Marello\Bundle\InventoryBundle\Entity\WarehouseChannelGroupLink;
use Marello\Bundle\InventoryBundle\Provider\AvailableInventoryProvider;
Expand All @@ -30,6 +33,9 @@ class PurchaseOrderOnOrderOnDemandCreationListener
*/
private $availableInventoryProvider;

/** @var ConfigManager $configManager */
private $configManager;

/**
* @param AvailableInventoryProvider $availableInventoryProvider
*/
Expand All @@ -47,6 +53,10 @@ public function postPersist(LifecycleEventArgs $args)
if (!$entity instanceof Order) {
return;
}
if (!$this->configManager->get('marello_inventory.inventory_on_demand')) {
return;
}

$orderOnDemandItems = [];
$salesChannel = $entity->getSalesChannel();
foreach ($entity->getItems() as $item) {
Expand Down Expand Up @@ -210,4 +220,12 @@ private function getLinkedWarehouse(Order $order, EntityManager $manager)

return !empty($linkedWarehouses) ? reset($linkedWarehouses) : null;
}

/**
* @param ConfigManager $configManager
*/
public function setConfigManager(ConfigManager $configManager)
{
$this->configManager = $configManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ services:
class: Marello\Bundle\PurchaseOrderBundle\EventListener\Doctrine\PurchaseOrderOnOrderOnDemandCreationListener
arguments:
- '@marello_inventory.provider.available_inventory_provider'
calls:
- ['setConfigManager', ['@oro_config.manager']]
tags:
- { name: doctrine.event_listener, event: postPersist }
- { name: doctrine.event_listener, event: postFlush }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function executeAction($context)
$this->handleInventoryUpdate($item, $inventoryUpdateQty, $purchaseOrder);
$updatedItems[] = ['qty' => $inventoryUpdateQty, 'item' => $item];

// both cases are independant of the qty that has been received
// both cases are independent of the qty that has been received
if ($product = $item->getProduct()) {
/** @var InventoryItem $inventoryItem */
$inventoryItem = $product->getInventoryItems()->first();
Expand Down

0 comments on commit 5391c9c

Please sign in to comment.