mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Allow to force ajustment on closed deliveries
This is useful for deliveries with missing products to adjust totals before sending
This commit is contained in:
parent
2aeceeca3c
commit
bd2fb3958e
4 changed files with 28 additions and 5 deletions
|
@ -346,9 +346,13 @@ async def place_order(request, response, id):
|
||||||
response.redirect = f"/livraison/{delivery.id}"
|
response.redirect = f"/livraison/{delivery.id}"
|
||||||
else:
|
else:
|
||||||
order = delivery.orders.get(email) or Order()
|
order = delivery.orders.get(email) or Order()
|
||||||
|
force_adjustment = "adjust" in request.query and user and user.is_staff
|
||||||
response.html(
|
response.html(
|
||||||
"place_order.html",
|
"place_order.html",
|
||||||
{"delivery": delivery, "person": Person(email=email), "order": order},
|
delivery=delivery,
|
||||||
|
person=Person(email=email),
|
||||||
|
order=order,
|
||||||
|
force_adjustment=force_adjustment,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,8 @@ input[type=submit] {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
input[type=submit],
|
input[type=submit],
|
||||||
input[type=submit] + a.button {
|
input[type=submit] + a.button,
|
||||||
|
a.button + a.button {
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<th class="packing">Conditionnement</th>
|
<th class="packing">Conditionnement</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<th class="amount">Commande</th>
|
<th class="amount">Commande</th>
|
||||||
{% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments %}<th class="amount">Ajustement +/−</th>{% endif %}
|
{% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments or force_adjustment %}<th class="amount">Ajustement +/−</th>{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -32,8 +32,8 @@
|
||||||
<td{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}>{{ product.packing or "—" }}{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} (−{{ delivery.product_missing(product) }}){% endif %}</td>
|
<td{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} class="missing" title="Les commandes individuelles ne correspondent pas aux conditionnements"{% endif %}>{{ product.packing or "—" }}{% if delivery.status == delivery.ADJUSTMENT and delivery.product_missing(product) %} (−{{ delivery.product_missing(product) }}){% endif %}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="with-input"><input {% if delivery.status != delivery.OPEN %}type="text" readonly{% else%}type="number"{% endif%} min=0 name="wanted:{{ product.ref }}" value="{{ order[product].wanted }}"></td>
|
<td class="with-input"><input {% if delivery.status != delivery.OPEN %}type="text" readonly{% else%}type="number"{% endif%} min=0 name="wanted:{{ product.ref }}" value="{{ order[product].wanted }}"></td>
|
||||||
{% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments %}
|
{% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments or force_adjustment %}
|
||||||
<td class="with-input"><input type="number" name="adjustment:{{ product.ref }}" value="{{ order[product].adjustment }}" {% if not delivery.product_missing(product) %}readonly{% endif %}></td>
|
<td class="with-input"><input type="number" name="adjustment:{{ product.ref }}" value="{{ order[product].adjustment }}" {% if not (delivery.product_missing(product) or force_adjustment) %}readonly{% endif %}></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -48,6 +48,9 @@
|
||||||
<input type="submit" value="Enregistrer la commande" class="primary">
|
<input type="submit" value="Enregistrer la commande" class="primary">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a class="button" href="/livraison/{{ delivery.id }}/courriel?email={{ person.email }}">Envoyer par courriel</a>
|
<a class="button" href="/livraison/{{ delivery.id }}/courriel?email={{ person.email }}">Envoyer par courriel</a>
|
||||||
|
{% if request.user.is_staff and delivery.status == delivery.CLOSED %}
|
||||||
|
<a class="button danger" href="/livraison/{{ delivery.id }}/commander?email={{ person.email }}&adjust">Ajuster</a>
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
|
@ -154,6 +154,21 @@ async def test_get_place_order_with_closed_delivery_but_adjustments(client, deli
|
||||||
assert doc('[name="adjustment:123"]')
|
assert doc('[name="adjustment:123"]')
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_place_order_with_closed_delivery_but_force(client, delivery):
|
||||||
|
delivery.order_before = datetime.now() - timedelta(days=1)
|
||||||
|
delivery.orders["foo@bar.org"] = Order(products={"123": ProductOrder(wanted=1)})
|
||||||
|
delivery.persist()
|
||||||
|
assert delivery.status == delivery.CLOSED
|
||||||
|
resp = await client.get(f"/livraison/{delivery.id}/commander")
|
||||||
|
doc = pq(resp.body)
|
||||||
|
assert doc('[name="wanted:123"]').attr("readonly") is not None
|
||||||
|
assert not doc('[name="adjustment:123"]')
|
||||||
|
resp = await client.get(f"/livraison/{delivery.id}/commander?adjust")
|
||||||
|
doc = pq(resp.body)
|
||||||
|
assert doc('[name="wanted:123"]').attr("readonly") is not None
|
||||||
|
assert doc('[name="adjustment:123"]')
|
||||||
|
|
||||||
|
|
||||||
async def test_cannot_place_order_on_closed_delivery(client, delivery, monkeypatch):
|
async def test_cannot_place_order_on_closed_delivery(client, delivery, monkeypatch):
|
||||||
monkeypatch.setattr("copanier.config.STAFF", ["someone@else.org"])
|
monkeypatch.setattr("copanier.config.STAFF", ["someone@else.org"])
|
||||||
delivery.order_before = datetime.now() - timedelta(days=1)
|
delivery.order_before = datetime.now() - timedelta(days=1)
|
||||||
|
|
Loading…
Reference in a new issue