Cards de movimentações
1 - Modelo do Rotation agora conta com novas propriedades para calcular o tempo de movimentação. 2 - ListView da Movimentações filtra e separa rotações em aberto para serem mostradas em Card 3 - O template rotation_home inclui _active_rotation_card para exibir as informações das Movimentações em aberto
This commit is contained in:
1 parent
ed31a1a3da
commit
cf91224602
4 files changed
+64
-5
No files matched your search
@@ -1,4 +1,5 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
class Rotation(models.Model):
|
||||
is_active = models.BooleanField(default=True)
|
||||
@@ -13,3 +14,23 @@ class Rotation(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f"Movimentação {self.id} - Lote {self.batch.identifier}"
|
||||
|
||||
@property
|
||||
def duration(self):
|
||||
end = self.exit_date or timezone.now()
|
||||
return end - self.entry_date
|
||||
|
||||
@property
|
||||
def duration_display_day(self):
|
||||
end = self.exit_date or timezone.now()
|
||||
delta = end - self.entry_date
|
||||
|
||||
days = delta.days
|
||||
|
||||
if days == 0:
|
||||
return "Hoje"
|
||||
|
||||
if days == 1:
|
||||
return "1"
|
||||
|
||||
return f"{days}"
|
||||
@@ -1,6 +1,21 @@
|
||||
<div class="active_rotaiton_card">
|
||||
<h4>Movimentação {rotation.id}</h4>
|
||||
<p>Lote {lote.name} atualmente no piquete {paddock.number} a {rotation.duration} atrás</p>
|
||||
<p>var = {{var}}</p>
|
||||
<div class="active-rotation-card">
|
||||
<div class="identification">
|
||||
<p>{{ obj.batch.identifier }} em piquete {{ obj.paddock.paddock_number }}</p>
|
||||
</div>
|
||||
|
||||
<div class="duration">
|
||||
<p>Há {{ obj.duration_display_day }} dias, desde {{ obj.entry_date|date:"d/m/Y" }}</p>
|
||||
</div>
|
||||
|
||||
<div class="animals">
|
||||
<p>Animais: {{ obj.animal_count }}</p>
|
||||
</div>
|
||||
|
||||
<div class="livestock">
|
||||
<p>UGM: {{ obj.livestock_unit }}</p>
|
||||
</div>
|
||||
|
||||
<div class="details">
|
||||
<a href="#vermais">Ver mais</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2,7 +2,18 @@
|
||||
{% load custom_tags %}
|
||||
|
||||
{% block before_table %}
|
||||
<p>Essas informações aparecem antes da tabela apenas para a tela de movimentações</p>
|
||||
<p>Movimentações em aberto</p>
|
||||
<div class="open-rotations-container" style="display: flex; flex-direction: row; gap: 30px;"> <!-- TIRAR O STYLE DAQUI DEPOIS -->
|
||||
{% if not open_rotations %}
|
||||
<p>Nenhuma movimentação em aberto</p>
|
||||
{% else %}
|
||||
|
||||
{% for obj in open_rotations %}
|
||||
{% include "_active_rotation_card.html" %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block table %}
|
||||
|
||||
@@ -25,4 +25,16 @@ class RotationListView(BaseListView):
|
||||
filter_fields = ["id", "batch", "paddock"]
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
self.open_rotations = queryset.filter(exit_date__isnull=True, paddock__farm=self.selected_farm)
|
||||
|
||||
return super().get_queryset().filter(is_active=True, paddock__farm=self.selected_farm)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context.update({
|
||||
"open_rotations": self.open_rotations,
|
||||
})
|
||||
|
||||
return context
|
||||
Reference in new issue
Block a user