diff --git a/Dockerfile b/Dockerfile index 55940667..dd6f8e07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,17 +5,18 @@ WORKDIR /sge ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 -RUN apt update && apt -y install cron && apt -y install nano - -COPY . . +RUN apt update && apt -y install cron && apt -y install vim +# COPY ./application . +COPY ./application/requirements.txt /requirements.txt RUN pip install --upgrade pip -RUN pip install -r requirements.txt +RUN pip install -r /requirements.txt -COPY ./cron /etc/cron.d/cron -RUN chmod 0644 /etc/cron.d/cron -RUN crontab /etc/cron.d/cron +# COPY ./application/cron /etc/cron.d/cron +# RUN chmod 0644 /etc/cron.d/cron +# RUN crontab /etc/cron.d/cron EXPOSE 8000 CMD cron ; python manage.py migrate && python manage.py runserver 0.0.0.0:8000 +#CMD tail -f /dev/null diff --git a/.env.example b/application/.env.example similarity index 100% rename from .env.example rename to application/.env.example diff --git a/.flake8 b/application/.flake8 similarity index 100% rename from .flake8 rename to application/.flake8 diff --git a/ai/__init__.py b/application/ai/__init__.py similarity index 100% rename from ai/__init__.py rename to application/ai/__init__.py diff --git a/ai/admin.py b/application/ai/admin.py similarity index 100% rename from ai/admin.py rename to application/ai/admin.py diff --git a/ai/agent.py b/application/ai/agent.py similarity index 100% rename from ai/agent.py rename to application/ai/agent.py diff --git a/ai/apps.py b/application/ai/apps.py similarity index 100% rename from ai/apps.py rename to application/ai/apps.py diff --git a/ai/management/__init__.py b/application/ai/management/__init__.py similarity index 100% rename from ai/management/__init__.py rename to application/ai/management/__init__.py diff --git a/ai/management/commands/__init__.py b/application/ai/management/commands/__init__.py similarity index 100% rename from ai/management/commands/__init__.py rename to application/ai/management/commands/__init__.py diff --git a/ai/management/commands/sge_agent_invoke.py b/application/ai/management/commands/sge_agent_invoke.py similarity index 100% rename from ai/management/commands/sge_agent_invoke.py rename to application/ai/management/commands/sge_agent_invoke.py diff --git a/ai/migrations/0001_initial.py b/application/ai/migrations/0001_initial.py similarity index 100% rename from ai/migrations/0001_initial.py rename to application/ai/migrations/0001_initial.py diff --git a/ai/migrations/__init__.py b/application/ai/migrations/__init__.py similarity index 100% rename from ai/migrations/__init__.py rename to application/ai/migrations/__init__.py diff --git a/ai/models.py b/application/ai/models.py similarity index 100% rename from ai/models.py rename to application/ai/models.py diff --git a/ai/prompts.py b/application/ai/prompts.py similarity index 100% rename from ai/prompts.py rename to application/ai/prompts.py diff --git a/app/__init__.py b/application/app/__init__.py similarity index 100% rename from app/__init__.py rename to application/app/__init__.py diff --git a/app/asgi.py b/application/app/asgi.py similarity index 100% rename from app/asgi.py rename to application/app/asgi.py diff --git a/app/metrics.py b/application/app/metrics.py similarity index 100% rename from app/metrics.py rename to application/app/metrics.py diff --git a/app/settings.py b/application/app/settings.py similarity index 99% rename from app/settings.py rename to application/app/settings.py index 4f61d79b..4919c6da 100644 --- a/app/settings.py +++ b/application/app/settings.py @@ -54,6 +54,7 @@ 'inflows', 'outflows', 'ai', + 'costumers', ] LOGIN_URL = 'login' diff --git a/app/templates/base.html b/application/app/templates/base.html similarity index 100% rename from app/templates/base.html rename to application/app/templates/base.html diff --git a/app/templates/components/_ai_result.html b/application/app/templates/components/_ai_result.html similarity index 100% rename from app/templates/components/_ai_result.html rename to application/app/templates/components/_ai_result.html diff --git a/app/templates/components/_footer.html b/application/app/templates/components/_footer.html similarity index 100% rename from app/templates/components/_footer.html rename to application/app/templates/components/_footer.html diff --git a/app/templates/components/_header.html b/application/app/templates/components/_header.html similarity index 100% rename from app/templates/components/_header.html rename to application/app/templates/components/_header.html diff --git a/app/templates/components/_pagination.html b/application/app/templates/components/_pagination.html similarity index 100% rename from app/templates/components/_pagination.html rename to application/app/templates/components/_pagination.html diff --git a/app/templates/components/_product_metrics.html b/application/app/templates/components/_product_metrics.html similarity index 100% rename from app/templates/components/_product_metrics.html rename to application/app/templates/components/_product_metrics.html diff --git a/app/templates/components/_sales_metrics.html b/application/app/templates/components/_sales_metrics.html similarity index 100% rename from app/templates/components/_sales_metrics.html rename to application/app/templates/components/_sales_metrics.html diff --git a/app/templates/components/_sidebar.html b/application/app/templates/components/_sidebar.html similarity index 91% rename from app/templates/components/_sidebar.html rename to application/app/templates/components/_sidebar.html index f81e145c..07e4b76d 100644 --- a/app/templates/components/_sidebar.html +++ b/application/app/templates/components/_sidebar.html @@ -21,6 +21,14 @@ {% endif %} + {% if perms.costumers.view_costumer %} +
  • + + + Clientes + +
  • + {% endif %} {% if perms.brands.view_brand %}
  • diff --git a/app/templates/home.html b/application/app/templates/home.html similarity index 100% rename from app/templates/home.html rename to application/app/templates/home.html diff --git a/app/templates/registration/login.html b/application/app/templates/registration/login.html similarity index 100% rename from app/templates/registration/login.html rename to application/app/templates/registration/login.html diff --git a/app/urls.py b/application/app/urls.py similarity index 94% rename from app/urls.py rename to application/app/urls.py index 40fd1019..24bb047c 100644 --- a/app/urls.py +++ b/application/app/urls.py @@ -14,6 +14,7 @@ path('', views.home, name='home'), path('', include('suppliers.urls')), + path('', include('costumers.urls')), path('', include('brands.urls')), path('', include('categories.urls')), path('', include('products.urls')), diff --git a/app/views.py b/application/app/views.py similarity index 100% rename from app/views.py rename to application/app/views.py diff --git a/app/wsgi.py b/application/app/wsgi.py similarity index 100% rename from app/wsgi.py rename to application/app/wsgi.py diff --git a/authentication/__init__.py b/application/authentication/__init__.py similarity index 100% rename from authentication/__init__.py rename to application/authentication/__init__.py diff --git a/authentication/apps.py b/application/authentication/apps.py similarity index 100% rename from authentication/apps.py rename to application/authentication/apps.py diff --git a/authentication/migrations/__init__.py b/application/authentication/migrations/__init__.py similarity index 100% rename from authentication/migrations/__init__.py rename to application/authentication/migrations/__init__.py diff --git a/authentication/urls.py b/application/authentication/urls.py similarity index 100% rename from authentication/urls.py rename to application/authentication/urls.py diff --git a/brands/__init__.py b/application/brands/__init__.py similarity index 100% rename from brands/__init__.py rename to application/brands/__init__.py diff --git a/brands/admin.py b/application/brands/admin.py similarity index 100% rename from brands/admin.py rename to application/brands/admin.py diff --git a/brands/apps.py b/application/brands/apps.py similarity index 100% rename from brands/apps.py rename to application/brands/apps.py diff --git a/brands/forms.py b/application/brands/forms.py similarity index 100% rename from brands/forms.py rename to application/brands/forms.py diff --git a/brands/migrations/0001_initial.py b/application/brands/migrations/0001_initial.py similarity index 100% rename from brands/migrations/0001_initial.py rename to application/brands/migrations/0001_initial.py diff --git a/brands/migrations/__init__.py b/application/brands/migrations/__init__.py similarity index 100% rename from brands/migrations/__init__.py rename to application/brands/migrations/__init__.py diff --git a/brands/models.py b/application/brands/models.py similarity index 100% rename from brands/models.py rename to application/brands/models.py diff --git a/brands/serializers.py b/application/brands/serializers.py similarity index 100% rename from brands/serializers.py rename to application/brands/serializers.py diff --git a/brands/templates/brand_create.html b/application/brands/templates/brand_create.html similarity index 100% rename from brands/templates/brand_create.html rename to application/brands/templates/brand_create.html diff --git a/brands/templates/brand_delete.html b/application/brands/templates/brand_delete.html similarity index 100% rename from brands/templates/brand_delete.html rename to application/brands/templates/brand_delete.html diff --git a/brands/templates/brand_detail.html b/application/brands/templates/brand_detail.html similarity index 100% rename from brands/templates/brand_detail.html rename to application/brands/templates/brand_detail.html diff --git a/brands/templates/brand_list.html b/application/brands/templates/brand_list.html similarity index 100% rename from brands/templates/brand_list.html rename to application/brands/templates/brand_list.html diff --git a/brands/templates/brand_update.html b/application/brands/templates/brand_update.html similarity index 100% rename from brands/templates/brand_update.html rename to application/brands/templates/brand_update.html diff --git a/brands/urls.py b/application/brands/urls.py similarity index 100% rename from brands/urls.py rename to application/brands/urls.py diff --git a/brands/views.py b/application/brands/views.py similarity index 100% rename from brands/views.py rename to application/brands/views.py diff --git a/categories/__init__.py b/application/categories/__init__.py similarity index 100% rename from categories/__init__.py rename to application/categories/__init__.py diff --git a/categories/admin.py b/application/categories/admin.py similarity index 100% rename from categories/admin.py rename to application/categories/admin.py diff --git a/categories/apps.py b/application/categories/apps.py similarity index 100% rename from categories/apps.py rename to application/categories/apps.py diff --git a/categories/forms.py b/application/categories/forms.py similarity index 100% rename from categories/forms.py rename to application/categories/forms.py diff --git a/categories/migrations/0001_initial.py b/application/categories/migrations/0001_initial.py similarity index 100% rename from categories/migrations/0001_initial.py rename to application/categories/migrations/0001_initial.py diff --git a/categories/migrations/__init__.py b/application/categories/migrations/__init__.py similarity index 100% rename from categories/migrations/__init__.py rename to application/categories/migrations/__init__.py diff --git a/categories/models.py b/application/categories/models.py similarity index 100% rename from categories/models.py rename to application/categories/models.py diff --git a/categories/serializers.py b/application/categories/serializers.py similarity index 100% rename from categories/serializers.py rename to application/categories/serializers.py diff --git a/categories/templates/category_create.html b/application/categories/templates/category_create.html similarity index 100% rename from categories/templates/category_create.html rename to application/categories/templates/category_create.html diff --git a/categories/templates/category_delete.html b/application/categories/templates/category_delete.html similarity index 100% rename from categories/templates/category_delete.html rename to application/categories/templates/category_delete.html diff --git a/categories/templates/category_detail.html b/application/categories/templates/category_detail.html similarity index 100% rename from categories/templates/category_detail.html rename to application/categories/templates/category_detail.html diff --git a/categories/templates/category_list.html b/application/categories/templates/category_list.html similarity index 100% rename from categories/templates/category_list.html rename to application/categories/templates/category_list.html diff --git a/categories/templates/category_update.html b/application/categories/templates/category_update.html similarity index 100% rename from categories/templates/category_update.html rename to application/categories/templates/category_update.html diff --git a/categories/urls.py b/application/categories/urls.py similarity index 100% rename from categories/urls.py rename to application/categories/urls.py diff --git a/categories/views.py b/application/categories/views.py similarity index 100% rename from categories/views.py rename to application/categories/views.py diff --git a/inflows/__init__.py b/application/costumers/__init__.py similarity index 100% rename from inflows/__init__.py rename to application/costumers/__init__.py diff --git a/application/costumers/admin.py b/application/costumers/admin.py new file mode 100644 index 00000000..8c70a9ad --- /dev/null +++ b/application/costumers/admin.py @@ -0,0 +1,10 @@ +from django.contrib import admin +from . import models + + +class CostumerAdmin(admin.ModelAdmin): + list_display = ('name', 'mail', 'phone', 'document_id', 'social_media','address', 'city' , 'state' , 'zip_code') + search_fields = ('name',) + + +admin.site.register(models.Costumer, CostumerAdmin) diff --git a/application/costumers/apps.py b/application/costumers/apps.py new file mode 100644 index 00000000..cc1b8f20 --- /dev/null +++ b/application/costumers/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CostumersConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'costumers' diff --git a/application/costumers/forms.py b/application/costumers/forms.py new file mode 100644 index 00000000..8c289c2d --- /dev/null +++ b/application/costumers/forms.py @@ -0,0 +1,31 @@ +from django import forms +from . import models + + +class CostumerForm(forms.ModelForm): + + class Meta: + model = models.Costumer + fields = ['name', 'mail', 'phone', 'document_id', 'social_media', 'address', 'city' , 'state' , 'zip_code'] + widgets = { + 'name': forms.TextInput(attrs={'class': 'form-control'}), + 'mail': forms.TextInput(attrs={'class': 'form-control'}), + 'phone': forms.TextInput(attrs={'class': 'form-control'}), + 'document_id': forms.TextInput(attrs={'class': 'form-control'}), + 'social_media': forms.TextInput(attrs={'class': 'form-control'}), + 'address': forms.TextInput(attrs={'class': 'form-control'}), + 'city': forms.TextInput(attrs={'class': 'form-control'}), + 'state': forms.TextInput(attrs={'class': 'form-control', 'maxlength': '2'}), + 'zip_code': forms.TextInput(attrs={'class': 'form-control'}), + } + labels = { + 'name': 'Nome', + 'mail': 'E-mail', + 'phone': 'Telefone', + 'document_id': 'CPF/CNPJ', + 'social_media': 'Site/MediaSocial', + 'address': 'Endereço', + 'city': 'Cidade', + 'state': 'Estado', + 'zip_code': 'CEP', + } diff --git a/application/costumers/migrations/0001_initial.py b/application/costumers/migrations/0001_initial.py new file mode 100644 index 00000000..336d80a9 --- /dev/null +++ b/application/costumers/migrations/0001_initial.py @@ -0,0 +1,34 @@ +# Generated by Django 5.0.1 on 2025-11-08 13:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Costumer', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ('mail', models.TextField(blank=True, null=True)), + ('phone', models.CharField(blank=True, max_length=15)), + ('document_id', models.CharField(blank=True, max_length=15)), + ('address', models.CharField(blank=True, max_length=300)), + ('city', models.CharField(blank=True, max_length=100)), + ('state', models.CharField(blank=True, max_length=2)), + ('zip_code', models.CharField(blank=True, max_length=10)), + ('active', models.BooleanField(default=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + options={ + 'ordering': ['name'], + }, + ), + ] diff --git a/application/costumers/migrations/0002_costumer_social_media.py b/application/costumers/migrations/0002_costumer_social_media.py new file mode 100644 index 00000000..bfdf86f9 --- /dev/null +++ b/application/costumers/migrations/0002_costumer_social_media.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.1 on 2025-11-08 15:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('costumers', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='costumer', + name='social_media', + field=models.CharField(blank=True, max_length=15), + ), + ] diff --git a/application/costumers/migrations/0003_alter_costumer_social_media.py b/application/costumers/migrations/0003_alter_costumer_social_media.py new file mode 100644 index 00000000..95130210 --- /dev/null +++ b/application/costumers/migrations/0003_alter_costumer_social_media.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.1 on 2025-11-08 15:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('costumers', '0002_costumer_social_media'), + ] + + operations = [ + migrations.AlterField( + model_name='costumer', + name='social_media', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/inflows/migrations/__init__.py b/application/costumers/migrations/__init__.py similarity index 100% rename from inflows/migrations/__init__.py rename to application/costumers/migrations/__init__.py diff --git a/application/costumers/models.py b/application/costumers/models.py new file mode 100644 index 00000000..a2d158e4 --- /dev/null +++ b/application/costumers/models.py @@ -0,0 +1,22 @@ +from django.db import models + + +class Costumer(models.Model): + name = models.CharField(max_length=50) + mail = models.TextField(null=True, blank=True) + phone = models.CharField(max_length=15, blank=True) + document_id = models.CharField(max_length=15, blank=True) + social_media = models.CharField(max_length=100, blank=True) + address = models.CharField(max_length=300, blank=True) + city = models.CharField(max_length=100, blank=True) + state = models.CharField(max_length=2, blank=True) + zip_code = models.CharField(max_length=10, blank=True) + active = models.BooleanField(default=True) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + class Meta: + ordering = ['name'] + + def __str__(self): + return self.name diff --git a/application/costumers/serializers.py b/application/costumers/serializers.py new file mode 100644 index 00000000..f778ddc6 --- /dev/null +++ b/application/costumers/serializers.py @@ -0,0 +1,9 @@ +from rest_framework import serializers +from costumers.models import Costumer + + +class CostumerSerializer(serializers.ModelSerializer): + + class Meta: + model = Costumer + fields = '__all__' diff --git a/application/costumers/templates/costumer_create.html b/application/costumers/templates/costumer_create.html new file mode 100644 index 00000000..2b9c38b5 --- /dev/null +++ b/application/costumers/templates/costumer_create.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} + +{% block content %} +
    +

    Cadastrar Cliente

    + +
    +
    +
    + {% csrf_token %} + {{ form.as_p }} + +
    +
    +
    +
    Cancelar e Voltar para a Lista de Clientes +
    +{% endblock %} diff --git a/application/costumers/templates/costumer_delete.html b/application/costumers/templates/costumer_delete.html new file mode 100644 index 00000000..621ede1c --- /dev/null +++ b/application/costumers/templates/costumer_delete.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block content %} +
    +

    Deletar Cliente

    + +
    +
    +

    Tem certeza de que deseja excluir o fornecedor {{ object.name }}?

    + +
    + {% csrf_token %} + +
    + + Cancelar e Voltar para a Lista de Clientes +
    +
    +
    +{% endblock %} diff --git a/application/costumers/templates/costumer_detail.html b/application/costumers/templates/costumer_detail.html new file mode 100644 index 00000000..b51f1521 --- /dev/null +++ b/application/costumers/templates/costumer_detail.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} + +{% block content %} +
    +

    Detalhes do Cliente

    + +
    +
    +

    {{ object.name }}

    +

    {{ object.mail }}

    +

    {{ object.phone }}

    +

    {{ object.document_id }}

    +

    {{ object.address }}

    +

    {{ object.city }}

    +

    {{ object.state }}

    +

    {{ object.zip_code }}

    +
    +
    + + Voltar para a Lista de Clientes +
    +{% endblock %} diff --git a/application/costumers/templates/costumer_list.html b/application/costumers/templates/costumer_list.html new file mode 100644 index 00000000..430dd0e7 --- /dev/null +++ b/application/costumers/templates/costumer_list.html @@ -0,0 +1,87 @@ +{% extends 'base.html' %} + +{% block title %} +SGE - Clientes +{% endblock %} + +{% block content %} + +
    +
    +
    +
    + + +
    +
    +
    + {% if perms.costumers.add_costumer %} + + {% endif %} +
    + +
    + + + + + + + + + + + + + + + + + {% for costumer in costumers %} + + + + + + + + + + + + + {% endfor %} + +
    IDNomeE-mailTelefoneSite/MediaSocialCPF/CNPJEndereçoCidadeEstadoCEP
    + + {{ costumer.id }} + + {{ costumer.name }}{{ costumer.mail }}{{ costumer.phone }}{{ costumer.document_id }}{{ costumer.address }}{{ costumer.city }}{{ costumer.state }}{{ costumer.zip_code }} + + + + + {% if perms.costumers.change_costumer %} + + + + {% endif %} + + {% if perms.costumers.delete_costumer %} + + + + {% endif %} +
    +
    + +{% include 'components/_pagination.html' %} + +{% endblock %} \ No newline at end of file diff --git a/application/costumers/templates/costumer_update.html b/application/costumers/templates/costumer_update.html new file mode 100644 index 00000000..675d71c3 --- /dev/null +++ b/application/costumers/templates/costumer_update.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} + +{% block content %} +
    +

    Editar Cliente

    + +
    +
    +
    + {% csrf_token %} + {{ form.as_p }} + +
    +
    +
    + + Cancelar e Voltar para a Lista de Clientes +
    +{% endblock %} diff --git a/application/costumers/urls.py b/application/costumers/urls.py new file mode 100644 index 00000000..4a02459a --- /dev/null +++ b/application/costumers/urls.py @@ -0,0 +1,15 @@ +from django.urls import path +from . import views + + +urlpatterns = [ + path('costumers/list/', views.CostumerListView.as_view(), name='costumer_list'), + path('costumers/create/', views.CostumerCreateView.as_view(), name='costumer_create'), + path('costumers//detail/', views.CostumerDetailView.as_view(), name='costumer_detail'), + path('costumers//update/', views.CostumerUpdateView.as_view(), name='costumer_update'), + path('costumers//delete/', views.CostumerDeleteView.as_view(), name='costumer_delete'), + path("costumers/export/", views.costumers_export, name="costumers_export"), + + path('api/v1/costumers/', views.CostumerCreateListAPIView.as_view(), name='costumer-create-list-api-view'), + path('api/v1/costumers//', views.CostumerRetrieveUpdateDestroyAPIView.as_view(), name='costumer-detail-api-view'), +] diff --git a/application/costumers/views.py b/application/costumers/views.py new file mode 100644 index 00000000..ec8c060f --- /dev/null +++ b/application/costumers/views.py @@ -0,0 +1,74 @@ +from rest_framework import generics +from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin +from django.urls import reverse_lazy +from django.views.generic import ListView, CreateView, DetailView, UpdateView, DeleteView +from . import models, forms, serializers +from django.http import HttpResponse +import csv + + +class CostumerListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): + model = models.Costumer + template_name = 'costumer_list.html' + context_object_name = 'costumers' + paginate_by = 10 + permission_required = 'costumers.view_costumer' + + def get_queryset(self): + queryset = super().get_queryset() + name = self.request.GET.get('name') + + if name: + queryset = queryset.filter(name__icontains=name) + + return queryset + + +class CostumerCreateView(LoginRequiredMixin, PermissionRequiredMixin, CreateView): + model = models.Costumer + template_name = 'costumer_create.html' + form_class = forms.CostumerForm + success_url = reverse_lazy('costumer_list') + permission_required = 'costumers.add_costumer' + + +class CostumerDetailView(LoginRequiredMixin, PermissionRequiredMixin, DetailView): + model = models.Costumer + template_name = 'costumer_detail.html' + permission_required = 'costumers.view_costumer' + + +class CostumerUpdateView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView): + model = models.Costumer + template_name = 'costumer_update.html' + form_class = forms.CostumerForm + success_url = reverse_lazy('costumer_list') + permission_required = 'costumers.change_costumer' + + +class CostumerDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteView): + model = models.Costumer + template_name = 'costumer_delete.html' + success_url = reverse_lazy('costumer_list') + permission_required = 'costumers.delete_costumer' + + +class CostumerCreateListAPIView(generics.ListCreateAPIView): + queryset = models.Costumer.objects.all() + serializer_class = serializers.CostumerSerializer + + +class CostumerRetrieveUpdateDestroyAPIView(generics.RetrieveUpdateDestroyAPIView): + queryset = models.Costumer.objects.all() + serializer_class = serializers.CostumerSerializer + +def costumers_export(request): + response = HttpResponse(content_type="text/csv") + response["Content-Disposition"] = 'attachment; filename="clientes.csv"' + writer = csv.writer(response) + writer.writerow(["Nome", "E-mail", "Telefone", "Site/MediaSocial", "CPF/CNPJ", "Endereço", "Cidade", "Estado", "CEP", "Data de Criação"]) + + for c in models.Costumer.objects.all(): + writer.writerow([c.name, c.mail, c.phone, c.document_id, c.social_media, c.address, c.city, c.state, c.zip_code, c.created_at]) + + return response diff --git a/cron b/application/cron similarity index 100% rename from cron rename to application/cron diff --git a/outflows/__init__.py b/application/inflows/__init__.py similarity index 100% rename from outflows/__init__.py rename to application/inflows/__init__.py diff --git a/inflows/admin.py b/application/inflows/admin.py similarity index 100% rename from inflows/admin.py rename to application/inflows/admin.py diff --git a/inflows/apps.py b/application/inflows/apps.py similarity index 100% rename from inflows/apps.py rename to application/inflows/apps.py diff --git a/inflows/forms.py b/application/inflows/forms.py similarity index 100% rename from inflows/forms.py rename to application/inflows/forms.py diff --git a/inflows/migrations/0001_initial.py b/application/inflows/migrations/0001_initial.py similarity index 100% rename from inflows/migrations/0001_initial.py rename to application/inflows/migrations/0001_initial.py diff --git a/outflows/migrations/__init__.py b/application/inflows/migrations/__init__.py similarity index 100% rename from outflows/migrations/__init__.py rename to application/inflows/migrations/__init__.py diff --git a/inflows/models.py b/application/inflows/models.py similarity index 100% rename from inflows/models.py rename to application/inflows/models.py diff --git a/inflows/serializers.py b/application/inflows/serializers.py similarity index 100% rename from inflows/serializers.py rename to application/inflows/serializers.py diff --git a/inflows/signals.py b/application/inflows/signals.py similarity index 100% rename from inflows/signals.py rename to application/inflows/signals.py diff --git a/inflows/templates/inflow_create.html b/application/inflows/templates/inflow_create.html similarity index 100% rename from inflows/templates/inflow_create.html rename to application/inflows/templates/inflow_create.html diff --git a/inflows/templates/inflow_detail.html b/application/inflows/templates/inflow_detail.html similarity index 100% rename from inflows/templates/inflow_detail.html rename to application/inflows/templates/inflow_detail.html diff --git a/inflows/templates/inflow_list.html b/application/inflows/templates/inflow_list.html similarity index 100% rename from inflows/templates/inflow_list.html rename to application/inflows/templates/inflow_list.html diff --git a/inflows/urls.py b/application/inflows/urls.py similarity index 100% rename from inflows/urls.py rename to application/inflows/urls.py diff --git a/inflows/views.py b/application/inflows/views.py similarity index 100% rename from inflows/views.py rename to application/inflows/views.py diff --git a/manage.py b/application/manage.py similarity index 100% rename from manage.py rename to application/manage.py diff --git a/products/__init__.py b/application/outflows/__init__.py similarity index 100% rename from products/__init__.py rename to application/outflows/__init__.py diff --git a/outflows/admin.py b/application/outflows/admin.py similarity index 100% rename from outflows/admin.py rename to application/outflows/admin.py diff --git a/outflows/apps.py b/application/outflows/apps.py similarity index 100% rename from outflows/apps.py rename to application/outflows/apps.py diff --git a/outflows/forms.py b/application/outflows/forms.py similarity index 100% rename from outflows/forms.py rename to application/outflows/forms.py diff --git a/outflows/migrations/0001_initial.py b/application/outflows/migrations/0001_initial.py similarity index 100% rename from outflows/migrations/0001_initial.py rename to application/outflows/migrations/0001_initial.py diff --git a/products/management/__init__.py b/application/outflows/migrations/__init__.py similarity index 100% rename from products/management/__init__.py rename to application/outflows/migrations/__init__.py diff --git a/outflows/models.py b/application/outflows/models.py similarity index 100% rename from outflows/models.py rename to application/outflows/models.py diff --git a/outflows/serializers.py b/application/outflows/serializers.py similarity index 100% rename from outflows/serializers.py rename to application/outflows/serializers.py diff --git a/outflows/signals.py b/application/outflows/signals.py similarity index 100% rename from outflows/signals.py rename to application/outflows/signals.py diff --git a/outflows/templates/outflow_create.html b/application/outflows/templates/outflow_create.html similarity index 100% rename from outflows/templates/outflow_create.html rename to application/outflows/templates/outflow_create.html diff --git a/outflows/templates/outflow_detail.html b/application/outflows/templates/outflow_detail.html similarity index 100% rename from outflows/templates/outflow_detail.html rename to application/outflows/templates/outflow_detail.html diff --git a/outflows/templates/outflow_list.html b/application/outflows/templates/outflow_list.html similarity index 100% rename from outflows/templates/outflow_list.html rename to application/outflows/templates/outflow_list.html diff --git a/outflows/urls.py b/application/outflows/urls.py similarity index 100% rename from outflows/urls.py rename to application/outflows/urls.py diff --git a/outflows/views.py b/application/outflows/views.py similarity index 100% rename from outflows/views.py rename to application/outflows/views.py diff --git a/products/management/commands/__init__.py b/application/products/__init__.py similarity index 100% rename from products/management/commands/__init__.py rename to application/products/__init__.py diff --git a/products/admin.py b/application/products/admin.py similarity index 76% rename from products/admin.py rename to application/products/admin.py index 2d291021..e6e9c0ef 100644 --- a/products/admin.py +++ b/application/products/admin.py @@ -3,7 +3,7 @@ class ProductAdmin(admin.ModelAdmin): - list_display = ('title', 'serie_number',) + list_display = ('title', 'serie_number', 'color') search_fields = ('title',) diff --git a/products/apps.py b/application/products/apps.py similarity index 100% rename from products/apps.py rename to application/products/apps.py diff --git a/products/forms.py b/application/products/forms.py similarity index 76% rename from products/forms.py rename to application/products/forms.py index 87571d98..03d3e93e 100644 --- a/products/forms.py +++ b/application/products/forms.py @@ -10,7 +10,10 @@ class Meta: widgets = { 'title': forms.TextInput(attrs={'class': 'form-control'}), 'category': forms.Select(attrs={'class': 'form-control'}), - 'brand': forms.Select(attrs={'class': 'form-control'}), + 'color': forms.TextInput(attrs={'class': 'form-control'}), + 'size': forms.TextInput(attrs={'class': 'form-control'}), + 'type': forms.TextInput(attrs={'class': 'form-control'}), + 'brand': forms.Select(attrs={'class': 'form-control'}), 'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}), 'serie_number': forms.TextInput(attrs={'class': 'form-control'}), 'cost_price': forms.NumberInput(attrs={'class': 'form-control'}), @@ -19,6 +22,9 @@ class Meta: labels = { 'title': 'Título', 'category': 'Categoria', + 'color': 'Cor', + 'size': 'Tamanho', + 'type': 'Tipo', 'brand': 'Marca', 'description': 'Descrição', 'serie_number': 'Número de Série', diff --git a/products/migrations/__init__.py b/application/products/management/__init__.py similarity index 100% rename from products/migrations/__init__.py rename to application/products/management/__init__.py diff --git a/suppliers/__init__.py b/application/products/management/commands/__init__.py similarity index 100% rename from suppliers/__init__.py rename to application/products/management/commands/__init__.py diff --git a/products/management/commands/fazer_coisas.py b/application/products/management/commands/fazer_coisas.py similarity index 100% rename from products/management/commands/fazer_coisas.py rename to application/products/management/commands/fazer_coisas.py diff --git a/products/migrations/0001_initial.py b/application/products/migrations/0001_initial.py similarity index 100% rename from products/migrations/0001_initial.py rename to application/products/migrations/0001_initial.py diff --git a/application/products/migrations/0002_product_color_product_size_product_type.py b/application/products/migrations/0002_product_color_product_size_product_type.py new file mode 100644 index 00000000..2c64ca24 --- /dev/null +++ b/application/products/migrations/0002_product_color_product_size_product_type.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.1 on 2025-11-09 00:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('products', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='product', + name='color', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='product', + name='size', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='product', + name='type', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/suppliers/migrations/__init__.py b/application/products/migrations/__init__.py similarity index 100% rename from suppliers/migrations/__init__.py rename to application/products/migrations/__init__.py diff --git a/products/models.py b/application/products/models.py similarity index 85% rename from products/models.py rename to application/products/models.py index 98afc49c..10881306 100644 --- a/products/models.py +++ b/application/products/models.py @@ -7,6 +7,9 @@ class Product(models.Model): title = models.CharField(max_length=500) category = models.ForeignKey(Category, on_delete=models.PROTECT, related_name='products') brand = models.ForeignKey(Brand, on_delete=models.PROTECT, related_name='products') + color = models.TextField(null=True, blank=True) + size = models.TextField(null=True, blank=True) + type = models.TextField(null=True, blank=True) description = models.TextField(null=True, blank=True) serie_number = models.CharField(max_length=200, null=True, blank=True) cost_price = models.DecimalField(max_digits=20, decimal_places=2) diff --git a/products/serializers.py b/application/products/serializers.py similarity index 100% rename from products/serializers.py rename to application/products/serializers.py diff --git a/products/templates/product_create.html b/application/products/templates/product_create.html similarity index 100% rename from products/templates/product_create.html rename to application/products/templates/product_create.html diff --git a/products/templates/product_delete.html b/application/products/templates/product_delete.html similarity index 100% rename from products/templates/product_delete.html rename to application/products/templates/product_delete.html diff --git a/products/templates/product_detail.html b/application/products/templates/product_detail.html similarity index 84% rename from products/templates/product_detail.html rename to application/products/templates/product_detail.html index 8a1fb578..87ef8429 100644 --- a/products/templates/product_detail.html +++ b/application/products/templates/product_detail.html @@ -8,6 +8,9 @@

    Detalhes do Produto

    {{ object.title }}

    Categoria: {{ object.category }}

    +

    Cor: {{ object.color }}

    +

    Tamanho: {{ object.size }}

    +

    Tipo: {{ object.type }}

    Marca: {{ object.brand }}

    {{ object.description }}

    Número de Série: {{ object.serie_number }}

    diff --git a/products/templates/product_list.html b/application/products/templates/product_list.html similarity index 92% rename from products/templates/product_list.html rename to application/products/templates/product_list.html index 0d870646..4329d789 100644 --- a/products/templates/product_list.html +++ b/application/products/templates/product_list.html @@ -28,6 +28,7 @@ {% endif %} @@ -64,6 +65,9 @@ ID Título Categoria + Cor + Tamanho + Tipo Marca Preço de Custo Preço de Venda @@ -82,6 +86,9 @@ {{ product.title }} {{ product.category }} + {{ product.color }} + {{ product.size }} + {{ product.type }} {{ product.brand }} R$ {{ product.cost_price }} R$ {{ product.selling_price }} diff --git a/products/templates/product_update.html b/application/products/templates/product_update.html similarity index 100% rename from products/templates/product_update.html rename to application/products/templates/product_update.html diff --git a/products/urls.py b/application/products/urls.py similarity index 90% rename from products/urls.py rename to application/products/urls.py index c51c916c..8a98bc47 100644 --- a/products/urls.py +++ b/application/products/urls.py @@ -8,6 +8,7 @@ path('products//detail/', views.ProductDetailView.as_view(), name='product_detail'), path('products//update/', views.ProductUpdateView.as_view(), name='product_update'), path('products//delete/', views.ProductDeleteView.as_view(), name='product_delete'), + path("products/export/", views.products_export, name="products_export"), path('api/v1/products/', views.ProductCreateListAPIView.as_view(), name='product-create-list-api-view'), path('api/v1/products//', views.ProductRetrieveUpdateDestroyAPIView.as_view(), name='product-detail-api-view'), diff --git a/products/views.py b/application/products/views.py similarity index 83% rename from products/views.py rename to application/products/views.py index 66e0cb73..a64c4c44 100644 --- a/products/views.py +++ b/application/products/views.py @@ -6,6 +6,9 @@ from brands.models import Brand from categories.models import Category from . import models, forms, serializers +from django.http import HttpResponse +import csv + class ProductListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): @@ -79,3 +82,15 @@ class ProductCreateListAPIView(generics.ListCreateAPIView): class ProductRetrieveUpdateDestroyAPIView(generics.RetrieveUpdateDestroyAPIView): queryset = models.Product.objects.all() serializer_class = serializers.ProductSerializer + +def products_export(request): + response = HttpResponse(content_type="text/csv") + response["Content-Disposition"] = 'attachment; filename="produtos.csv"' + writer = csv.writer(response) + writer.writerow(["Título", "Categoria", "Marca", "Descrição", "Número de Série", "Preço de Custo", "Preço de Venda"]) + + for c in models.Product.objects.all(): + writer.writerow([c.title, c.category, c.brand, c.color , c.size, c.type, c.description, c.serie_number, c.cost_price, c.selling_price]) + + return response + diff --git a/requirements.txt b/application/requirements.txt similarity index 100% rename from requirements.txt rename to application/requirements.txt diff --git a/requirements_dev.txt b/application/requirements_dev.txt similarity index 100% rename from requirements_dev.txt rename to application/requirements_dev.txt diff --git a/application/suppliers/__init__.py b/application/suppliers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/suppliers/admin.py b/application/suppliers/admin.py similarity index 53% rename from suppliers/admin.py rename to application/suppliers/admin.py index 617ef587..026be2a3 100644 --- a/suppliers/admin.py +++ b/application/suppliers/admin.py @@ -3,7 +3,7 @@ class SupplierAdmin(admin.ModelAdmin): - list_display = ('name', 'description',) + list_display = ('name', 'mail', 'phone', 'site', 'document_id', 'contact', 'contact_phone', 'address', 'city' , 'state' , 'zip_code', 'description') search_fields = ('name',) diff --git a/suppliers/apps.py b/application/suppliers/apps.py similarity index 100% rename from suppliers/apps.py rename to application/suppliers/apps.py diff --git a/application/suppliers/forms.py b/application/suppliers/forms.py new file mode 100644 index 00000000..d74140d7 --- /dev/null +++ b/application/suppliers/forms.py @@ -0,0 +1,37 @@ +from django import forms +from . import models + + +class SupplierForm(forms.ModelForm): + + class Meta: + model = models.Supplier + fields = ['name', 'mail', 'phone', 'site', 'document_id', 'contact', 'contact_phone', 'address', 'city' , 'state' , 'zip_code', 'description'] + widgets = { + 'name': forms.TextInput(attrs={'class': 'form-control'}), + 'mail': forms.TextInput(attrs={'class': 'form-control'}), + 'phone': forms.TextInput(attrs={'class': 'form-control'}), + 'site': forms.TextInput(attrs={'class': 'form-control'}), + 'document_id': forms.TextInput(attrs={'class': 'form-control','maxlength': '20'}), + 'contact': forms.TextInput(attrs={'class': 'form-control'}), + 'contact_phone': forms.TextInput(attrs={'class': 'form-control'}), + 'address': forms.TextInput(attrs={'class': 'form-control'}), + 'city': forms.TextInput(attrs={'class': 'form-control'}), + 'state': forms.TextInput(attrs={'class': 'form-control', 'maxlength': '2'}), + 'zip_code': forms.TextInput(attrs={'class': 'form-control'}), + 'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}), + } + labels = { + 'name': 'Fornecedor', + 'mail': 'E-mail', + 'phone': 'Telefone', + 'site': 'Site/MediaSocial', + 'document_id': 'CPF/CNPJ', + 'contact': 'Vendedor', + 'contact_phone': 'Contato Vendedor', + 'address': 'Endereço', + 'city': 'Cidade', + 'state': 'Estado', + 'zip_code': 'CEP', + 'description': 'Descrição', + } diff --git a/suppliers/migrations/0001_initial.py b/application/suppliers/migrations/0001_initial.py similarity index 100% rename from suppliers/migrations/0001_initial.py rename to application/suppliers/migrations/0001_initial.py diff --git a/application/suppliers/migrations/0002_supplier_address_supplier_city_supplier_contact_and_more.py b/application/suppliers/migrations/0002_supplier_address_supplier_city_supplier_contact_and_more.py new file mode 100644 index 00000000..665f8f17 --- /dev/null +++ b/application/suppliers/migrations/0002_supplier_address_supplier_city_supplier_contact_and_more.py @@ -0,0 +1,68 @@ +# Generated by Django 5.0.1 on 2025-11-08 15:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('suppliers', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='supplier', + name='address', + field=models.CharField(blank=True, max_length=300), + ), + migrations.AddField( + model_name='supplier', + name='city', + field=models.CharField(blank=True, max_length=30), + ), + migrations.AddField( + model_name='supplier', + name='contact', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AddField( + model_name='supplier', + name='contact_phone', + field=models.CharField(blank=True, max_length=20), + ), + migrations.AddField( + model_name='supplier', + name='document_id', + field=models.CharField(blank=True, max_length=15), + ), + migrations.AddField( + model_name='supplier', + name='mail', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='supplier', + name='phone', + field=models.CharField(blank=True, max_length=15), + ), + migrations.AddField( + model_name='supplier', + name='site', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AddField( + model_name='supplier', + name='state', + field=models.CharField(blank=True, max_length=2), + ), + migrations.AddField( + model_name='supplier', + name='zip_code', + field=models.CharField(blank=True, max_length=10), + ), + migrations.AlterField( + model_name='supplier', + name='name', + field=models.CharField(max_length=50), + ), + ] diff --git a/application/suppliers/migrations/0003_alter_supplier_address_alter_supplier_contact_and_more.py b/application/suppliers/migrations/0003_alter_supplier_address_alter_supplier_contact_and_more.py new file mode 100644 index 00000000..c3bc0279 --- /dev/null +++ b/application/suppliers/migrations/0003_alter_supplier_address_alter_supplier_contact_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.1 on 2025-11-08 15:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('suppliers', '0002_supplier_address_supplier_city_supplier_contact_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='supplier', + name='address', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AlterField( + model_name='supplier', + name='contact', + field=models.CharField(blank=True, max_length=20), + ), + migrations.AlterField( + model_name='supplier', + name='document_id', + field=models.CharField(blank=True, max_length=20), + ), + ] diff --git a/application/suppliers/migrations/0004_alter_supplier_contact_alter_supplier_document_id.py b/application/suppliers/migrations/0004_alter_supplier_contact_alter_supplier_document_id.py new file mode 100644 index 00000000..a5e813c8 --- /dev/null +++ b/application/suppliers/migrations/0004_alter_supplier_contact_alter_supplier_document_id.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.1 on 2025-11-08 15:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('suppliers', '0003_alter_supplier_address_alter_supplier_contact_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='supplier', + name='contact', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AlterField( + model_name='supplier', + name='document_id', + field=models.CharField(blank=True, max_length=15), + ), + ] diff --git a/application/suppliers/migrations/__init__.py b/application/suppliers/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/application/suppliers/models.py b/application/suppliers/models.py new file mode 100644 index 00000000..d3b87bc3 --- /dev/null +++ b/application/suppliers/models.py @@ -0,0 +1,24 @@ +from django.db import models + + +class Supplier(models.Model): + name = models.CharField(max_length=50) + mail = models.TextField(null=True, blank=True) + phone = models.CharField(max_length=15, blank=True) + site = models.CharField(max_length=50, blank=True) + document_id = models.CharField(max_length=15, blank=True) + contact = models.CharField(max_length=50, blank=True) + contact_phone = models.CharField(max_length=20, blank=True) + address = models.CharField(max_length=50, blank=True) + city = models.CharField(max_length=30, blank=True) + state = models.CharField(max_length=2, blank=True) + zip_code = models.CharField(max_length=10, blank=True) + description = models.TextField(null=True, blank=True) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + class Meta: + ordering = ['name'] + + def __str__(self): + return self.name diff --git a/suppliers/serializers.py b/application/suppliers/serializers.py similarity index 100% rename from suppliers/serializers.py rename to application/suppliers/serializers.py diff --git a/suppliers/templates/supplier_create.html b/application/suppliers/templates/supplier_create.html similarity index 100% rename from suppliers/templates/supplier_create.html rename to application/suppliers/templates/supplier_create.html diff --git a/suppliers/templates/supplier_delete.html b/application/suppliers/templates/supplier_delete.html similarity index 100% rename from suppliers/templates/supplier_delete.html rename to application/suppliers/templates/supplier_delete.html diff --git a/application/suppliers/templates/supplier_detail.html b/application/suppliers/templates/supplier_detail.html new file mode 100644 index 00000000..32ce2521 --- /dev/null +++ b/application/suppliers/templates/supplier_detail.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} + +{% block content %} +
    +

    Detalhes do Fornecedor

    + + +
    +
    +

    {{ object.name }}

    +

    {{ object.mail }}

    +

    {{ object.phone }}

    +

    {{ object.document_id }}

    +

    {{ object.address }}

    +

    {{ object.city }}

    +

    {{ object.state }}

    +

    {{ object.zip_code }}

    +

    {{ object.description }}

    +
    +
    + + Voltar para a Lista de Fornecedores +
    +{% endblock %} diff --git a/suppliers/templates/supplier_list.html b/application/suppliers/templates/supplier_list.html similarity index 76% rename from suppliers/templates/supplier_list.html rename to application/suppliers/templates/supplier_list.html index f6c3f1d9..cf8eaeec 100644 --- a/suppliers/templates/supplier_list.html +++ b/application/suppliers/templates/supplier_list.html @@ -21,6 +21,8 @@ {% endif %} @@ -32,8 +34,12 @@ ID Nome - Descrição - Ações + E-mail + Telefone + Site/MediaSocial + CPF/CNPJ + Vendedor + Contato Vendedor @@ -45,7 +51,14 @@ {{ supplier.name }} - {{ supplier.description }} + {{ supplier.mail }} + {{ supplier.phone }} + {{ supplier.site }} + {{ supplier.document_id }} + {{ supplier.contact }} + {{ supplier.contact_phone }} + {{ supplier.contact_city }} + {{ supplier.contact_state }} diff --git a/suppliers/templates/supplier_update.html b/application/suppliers/templates/supplier_update.html similarity index 100% rename from suppliers/templates/supplier_update.html rename to application/suppliers/templates/supplier_update.html diff --git a/suppliers/urls.py b/application/suppliers/urls.py similarity index 90% rename from suppliers/urls.py rename to application/suppliers/urls.py index 652a93ae..350ca652 100644 --- a/suppliers/urls.py +++ b/application/suppliers/urls.py @@ -8,6 +8,7 @@ path('suppliers//detail/', views.SupplierDetailView.as_view(), name='supplier_detail'), path('suppliers//update/', views.SupplierUpdateView.as_view(), name='supplier_update'), path('suppliers//delete/', views.SupplierDeleteView.as_view(), name='supplier_delete'), + path("suppliers/export/", views.suppliers_export, name="suppliers_export"), path('api/v1/suppliers/', views.SupplierCreateListAPIView.as_view(), name='supplier-create-list-api-view'), path('api/v1/suppliers//', views.SupplierRetrieveUpdateDestroyAPIView.as_view(), name='supplier-detail-api-view'), diff --git a/suppliers/views.py b/application/suppliers/views.py similarity index 81% rename from suppliers/views.py rename to application/suppliers/views.py index 48bf7c8d..97a0ca2d 100644 --- a/suppliers/views.py +++ b/application/suppliers/views.py @@ -3,6 +3,8 @@ from django.urls import reverse_lazy from django.views.generic import ListView, CreateView, DetailView, UpdateView, DeleteView from . import models, forms, serializers +from django.http import HttpResponse +import csv class SupplierListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): @@ -59,3 +61,14 @@ class SupplierCreateListAPIView(generics.ListCreateAPIView): class SupplierRetrieveUpdateDestroyAPIView(generics.RetrieveUpdateDestroyAPIView): queryset = models.Supplier.objects.all() serializer_class = serializers.SupplierSerializer + +def suppliers_export(request): + response = HttpResponse(content_type="text/csv") + response["Content-Disposition"] = 'attachment; filename="fornecedores.csv"' + writer = csv.writer(response) + writer.writerow(["Nome", "Descrição"]) + + for c in models.Supplier.objects.all(): + writer.writerow([c.name, c.description, c.phone, c.document_id, c.address, c.city, c.state, c.zip_code, c.created_at]) + + return response diff --git a/docker-compose.yml b/docker-compose.yml index 0fcfd1ad..191603ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,9 @@ services: sge_web: build: . env_file: - - .env + - ./application/.env + volumes: + - ./application:/sge:rw restart: always ports: - 8000:8000 diff --git a/suppliers/forms.py b/suppliers/forms.py deleted file mode 100644 index ddae4828..00000000 --- a/suppliers/forms.py +++ /dev/null @@ -1,17 +0,0 @@ -from django import forms -from . import models - - -class SupplierForm(forms.ModelForm): - - class Meta: - model = models.Supplier - fields = ['name', 'description'] - widgets = { - 'name': forms.TextInput(attrs={'class': 'form-control'}), - 'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}), - } - labels = { - 'name': 'Nome', - 'description': 'Descrição', - } diff --git a/suppliers/models.py b/suppliers/models.py deleted file mode 100644 index 8c13172b..00000000 --- a/suppliers/models.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import models - - -class Supplier(models.Model): - name = models.CharField(max_length=500) - description = models.TextField(null=True, blank=True) - created_at = models.DateTimeField(auto_now_add=True) - updated_at = models.DateTimeField(auto_now=True) - - class Meta: - ordering = ['name'] - - def __str__(self): - return self.name diff --git a/suppliers/templates/supplier_detail.html b/suppliers/templates/supplier_detail.html deleted file mode 100644 index 0d420aee..00000000 --- a/suppliers/templates/supplier_detail.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} - -{% endblock %}