mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Display adjustement col on closed delivery if order has adjustements
This commit is contained in:
parent
edc0a44857
commit
c020ec89fa
4 changed files with 37 additions and 3 deletions
|
@ -129,12 +129,19 @@ class Order(Base):
|
|||
ref = ref.ref
|
||||
self.products[ref] = value
|
||||
|
||||
def __iter__(self):
|
||||
yield from self.products.items()
|
||||
|
||||
def total(self, products):
|
||||
products = {p.ref: p for p in products}
|
||||
return round(
|
||||
sum(p.quantity * products[ref].price for ref, p in self.products.items()), 2
|
||||
)
|
||||
|
||||
@property
|
||||
def has_adjustments(self):
|
||||
return any(choice.adjustment for email, choice in self)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Delivery(Base):
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<th class="packing">Conditionnement</th>
|
||||
{% endif %}
|
||||
<th class="amount">Commande</th>
|
||||
{% if delivery.status != delivery.OPEN %}<th class="amount">Ajustement +/−</th>{% endif %}
|
||||
{% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments %}<th class="amount">Ajustement +/−</th>{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<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 %}
|
||||
<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.OPEN %}
|
||||
{% if delivery.status == delivery.ADJUSTMENT or order.has_adjustments %}
|
||||
<td class="with-input"><input type="number" name="adjustment:{{ product.ref }}" value="{{ order[product].adjustment }}" {% if not delivery.product_missing(product) %}readonly{% endif %}></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
|
@ -44,7 +44,9 @@
|
|||
<p>Commande soldée: <input type="checkbox" name="paid" {% if order.paid %}checked{% endif %}></p>
|
||||
{% endif %}
|
||||
<input type="hidden" name="email" value="{{ person.email }}">
|
||||
{% if delivery.status != delivery.CLOSED or request.user.is_staff %}
|
||||
<input type="submit" value="Enregistrer la commande">
|
||||
{% endif %}
|
||||
<a class="button" href="/livraison/{{ delivery.id }}/courriel?email={{ person.email }}">Envoyer par courriel</a>
|
||||
</form>
|
||||
</article>
|
||||
|
|
|
@ -87,6 +87,15 @@ def test_can_add_product_to_order():
|
|||
assert order.products["123"].wanted == 2
|
||||
|
||||
|
||||
def test_order_has_adjustments():
|
||||
order = Order()
|
||||
assert not order.has_adjustments
|
||||
order.products["123"] = ProductOrder(wanted=2)
|
||||
assert not order.has_adjustments
|
||||
order.products["123"] = ProductOrder(wanted=2, adjustment=1)
|
||||
assert order.has_adjustments
|
||||
|
||||
|
||||
def test_can_persist_delivery(delivery):
|
||||
delivery.persist()
|
||||
|
||||
|
|
|
@ -98,7 +98,8 @@ async def test_change_paid_status_when_placing_order(client, delivery):
|
|||
assert delivery.orders["foo@bar.org"].paid is True
|
||||
|
||||
|
||||
async def test_get_place_order_with_closed_subscription(client, delivery):
|
||||
async def test_get_place_order_with_closed_delivery(client, delivery, monkeypatch):
|
||||
monkeypatch.setattr("copanier.config.STAFF", ["someone@else.org"])
|
||||
delivery.order_before = datetime.now() - timedelta(days=1)
|
||||
delivery.orders["foo@bar.org"] = Order(products={"123": ProductOrder(wanted=1)})
|
||||
delivery.persist()
|
||||
|
@ -107,6 +108,7 @@ async def test_get_place_order_with_closed_subscription(client, delivery):
|
|||
doc = pq(resp.body)
|
||||
assert doc('[name="wanted:123"]').attr("readonly")
|
||||
assert not doc('[name="adjustment:123"]')
|
||||
assert not doc('input[type="submit"]')
|
||||
|
||||
|
||||
async def test_get_place_order_with_adjustment_status(client, delivery):
|
||||
|
@ -135,6 +137,20 @@ async def test_get_place_order_with_adjustment_status(client, delivery):
|
|||
assert doc('[name="adjustment:789"]')
|
||||
# Needs no adjustment.
|
||||
assert doc('[name="adjustment:789"]').attr("readonly")
|
||||
assert doc('input[type="submit"]')
|
||||
|
||||
|
||||
async def test_get_place_order_with_closed_delivery_but_adjustments(client, delivery):
|
||||
delivery.order_before = datetime.now() - timedelta(days=1)
|
||||
delivery.orders["foo@bar.org"] = Order(
|
||||
products={"123": ProductOrder(wanted=1, adjustment=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")
|
||||
assert doc('[name="adjustment:123"]')
|
||||
|
||||
|
||||
async def test_cannot_place_order_on_closed_delivery(client, delivery, monkeypatch):
|
||||
|
|
Loading…
Reference in a new issue