Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : wrong value in VolumeUnits steps when creating a new rule #4889

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions assets/css/utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ li > a.text-danger // very specific selector for bootstrap dropdown
-ms-user-select: none; /* IE 10 and IE 11 */
user-select: none; /* Standard syntax */
}

/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button.no-number-input-arrow,
input::-webkit-inner-spin-button.no-number-input-arrow {
-webkit-appearance: none;
margin: 0;
}

/* Firefox */
input[type=number].no-number-input-arrow {
-moz-appearance: textfield;
}
56 changes: 29 additions & 27 deletions js/app/components/PriceRangeEditor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react'
import React, { useState, useRef, useEffect } from 'react'
import { getCurrencySymbol } from '../i18n'
import { useTranslation } from 'react-i18next'

Expand Down Expand Up @@ -75,22 +75,30 @@ export default ({ defaultValue, onChange }) => {

const stepEl = useRef(null)
const thresholdEl = useRef(null)
const initialLoad = useRef(true)

useEffect(() => {
if (!initialLoad.current) {
onChange({
attribute,
price: price,
step,
threshold,
})
} else {
initialLoad.current = false
}
}, [price, threshold, attribute, step])

return (
<div>
<label className="mr-2">
<input type="number" size="4"
defaultValue={ price / 100 } min="0" step=".001"
className="form-control d-inline-block"
className="form-control d-inline-block no-number-input-arrow"
style={{ width: '80px' }}
onChange={ e => {
setPrice(e.target.value * 100)
onChange({
attribute,
price: e.target.value * 100,
step,
threshold,
})
}} />
<span className="ml-2">{ getCurrencySymbol() }</span>
</label>
Expand All @@ -102,26 +110,26 @@ export default ({ defaultValue, onChange }) => {
style={{ width: '80px' }}
onChange={ e => {
setStep(multiplyIfNeeded(e.target.value, unit))
onChange({
attribute,
price,
step: multiplyIfNeeded(e.target.value, unit),
threshold: multiplyIfNeeded(thresholdEl.current.value, e.target.value),
})
}} />
<select
className="form-control d-inline-block align-top ml-2"
style={{ width: '70px' }}
defaultValue={ attributeToUnit(attribute) }
onChange={ e => {
setUnit(e.target.value)
setAttribute(unitToAttribute(e.target.value))
onChange({
attribute: unitToAttribute(e.target.value),
price,
step: multiplyIfNeeded(stepEl.current.value, e.target.value),
threshold: multiplyIfNeeded(thresholdEl.current.value, e.target.value),
})

const newUnit = e.target.value
const prevUnit = unit

if (newUnit === 'vu' && prevUnit !== 'vu') {
setStep(step / 1000)
setThreshold(threshold / 1000)
} else if (newUnit !== 'vu' && prevUnit === 'vu') {
setStep(step * 1000)
setThreshold(threshold * 1000)
}

setUnit(e.target.value)
}}>
<option value="km">km</option>
<option value="kg">kg</option>
Expand All @@ -136,12 +144,6 @@ export default ({ defaultValue, onChange }) => {
style={{ width: '80px' }}
onChange={ e => {
setThreshold(multiplyIfNeeded(e.target.value, unit))
onChange({
attribute,
price,
step,
threshold: multiplyIfNeeded(e.target.value, unit),
})
}} />
<span className="ml-2">
<UnitLabel unit={ unit } />
Expand Down
4 changes: 3 additions & 1 deletion src/Doctrine/EventSubscriber/TaskSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private function handleStateChangesForTasks(EntitymanagerInterface $em, array $t
continue;
}

// if all tasks of a delivery are cancelled, cancel the linked order
$tasks = $delivery->getTasks();
$cancelOrder = true;
foreach ($tasks as $task) {
Expand All @@ -233,7 +234,8 @@ private function handleStateChangesForTasks(EntitymanagerInterface $em, array $t
}
}

if ($cancelOrder && $order->getState() !== OrderInterface::STATE_CANCELLED) {
// do not cancel order if order is "refused"
if ($cancelOrder && $order->getState() !== OrderInterface::STATE_CANCELLED && $order->getState() !== OrderInterface::STATE_REFUSED) {
$this->orderManager->cancel($order, 'All tasks were cancelled');
$em->flush();
}
Expand Down
Loading