diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/inventory/models.py b/inventory/models.py index 9bf6b85..b0ad803 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -1,5 +1,7 @@ from django.db import models +from django.contrib.auth.models import AbstractUser +# Справочник товаров class Product(models.Model): name = models.CharField(max_length=255, verbose_name="Наименование товара") manufacturer_name = models.CharField(max_length=255, verbose_name="Производитель") @@ -13,7 +15,28 @@ class Product(models.Model): def __str__(self): return self.name +# Справочник должностей +class Position(models.Model): + name = models.CharField(max_length=255, verbose_name="Наименование должности") + hourly_rate = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Ставка в час") + monthly_hours = models.IntegerField(verbose_name="Часы в месяц") + def __str__(self): + return self.name + + +# Справочник сотрудников +class Employee(AbstractUser): + position = models.ForeignKey(Position, on_delete=models.SET_NULL, null=True, verbose_name="Должность") + department = models.CharField(max_length=255, verbose_name="Подразделение") + work_phone = models.CharField(max_length=20, blank=True, null=True, verbose_name="Рабочий телефон") + personal_phone = models.CharField(max_length=20, blank=True, null=True, verbose_name="Личный телефон") + email = models.EmailField(unique=True, verbose_name="Электронная почта") + + def __str__(self): + return self.get_full_name() + +# Справочник мест хранения class StorageLocation(models.Model): TYPE_CHOICES = [ ('Store', 'Магазин'), @@ -26,6 +49,35 @@ class StorageLocation(models.Model): def __str__(self): return self.name +# Справочник контрагентов и договоров +class Contractor(models.Model): + name = models.CharField(max_length=255, verbose_name="Наименование контрагента") + address = models.TextField(verbose_name="Адрес") + phone = models.CharField(max_length=20, verbose_name="Телефон") + email = models.EmailField(verbose_name="Электронная почта") + + def __str__(self): + return self.name + + +class SupplyContract(models.Model): + contractor = models.ForeignKey(Contractor, on_delete=models.CASCADE, verbose_name="Контрагент") + description = models.TextField(verbose_name="Описание") + start_date = models.DateField(verbose_name="Дата начала") + end_date = models.DateField(verbose_name="Дата окончания", blank=True, null=True) + + def __str__(self): + return f"Договор с {self.contractor.name}" + + +# Справочник грузовиков +class Truck(models.Model): + plate_number = models.CharField(max_length=20, verbose_name="Номерной знак") + model = models.CharField(max_length=50, verbose_name="Модель") + capacity = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Грузоподъемность (тонны)") + + def __str__(self): + return self.plate_number class StockOperation(models.Model): OPERATION_TYPE_CHOICES = [ diff --git a/inventory/serializers.py b/inventory/serializers.py new file mode 100644 index 0000000..d8f7513 --- /dev/null +++ b/inventory/serializers.py @@ -0,0 +1,43 @@ +from rest_framework import serializers +from .models import Product, Employee, Position, StorageLocation, Contractor, SupplyContract, Truck + +class ProductSerializer(serializers.ModelSerializer): + class Meta: + model = Product + fields = '__all__' + + +class PositionSerializer(serializers.ModelSerializer): + class Meta: + model = Position + fields = '__all__' + + +class EmployeeSerializer(serializers.ModelSerializer): + class Meta: + model = Employee + fields = '__all__' + + +class StorageLocationSerializer(serializers.ModelSerializer): + class Meta: + model = StorageLocation + fields = '__all__' + + +class ContractorSerializer(serializers.ModelSerializer): + class Meta: + model = Contractor + fields = '__all__' + + +class SupplyContractSerializer(serializers.ModelSerializer): + class Meta: + model = SupplyContract + fields = '__all__' + + +class TruckSerializer(serializers.ModelSerializer): + class Meta: + model = Truck + fields = '__all__' \ No newline at end of file diff --git a/inventory/urls.py b/inventory/urls.py new file mode 100644 index 0000000..d9c180a --- /dev/null +++ b/inventory/urls.py @@ -0,0 +1,19 @@ +from django.urls import path, include +from rest_framework.routers import DefaultRouter +from .views import ( + ProductViewSet, EmployeeViewSet, PositionViewSet, + StorageLocationViewSet, ContractorViewSet, SupplyContractViewSet, TruckViewSet +) + +router = DefaultRouter() +router.register(r'products', ProductViewSet) +router.register(r'employees', EmployeeViewSet) +router.register(r'positions', PositionViewSet) +router.register(r'storage-locations', StorageLocationViewSet) +router.register(r'contractors', ContractorViewSet) +router.register(r'supply-contracts', SupplyContractViewSet) +router.register(r'trucks', TruckViewSet) + +urlpatterns = [ + path('api/', include(router.urls)), +] \ No newline at end of file diff --git a/inventory/views.py b/inventory/views.py index 91ea44a..fcc9811 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -1,3 +1,40 @@ -from django.shortcuts import render +from rest_framework import viewsets +from .models import Product, Employee, Position, StorageLocation, Contractor, SupplyContract, Truck +from .serializers import ( + ProductSerializer, EmployeeSerializer, PositionSerializer, + StorageLocationSerializer, ContractorSerializer, SupplyContractSerializer, TruckSerializer +) -# Create your views here. +class ProductViewSet(viewsets.ModelViewSet): + queryset = Product.objects.all() + serializer_class = ProductSerializer + + +class EmployeeViewSet(viewsets.ModelViewSet): + queryset = Employee.objects.all() + serializer_class = EmployeeSerializer + + +class PositionViewSet(viewsets.ModelViewSet): + queryset = Position.objects.all() + serializer_class = PositionSerializer + + +class StorageLocationViewSet(viewsets.ModelViewSet): + queryset = StorageLocation.objects.all() + serializer_class = StorageLocationSerializer + + +class ContractorViewSet(viewsets.ModelViewSet): + queryset = Contractor.objects.all() + serializer_class = ContractorSerializer + + +class SupplyContractViewSet(viewsets.ModelViewSet): + queryset = SupplyContract.objects.all() + serializer_class = SupplyContractSerializer + + +class TruckViewSet(viewsets.ModelViewSet): + queryset = Truck.objects.all() + serializer_class = TruckSerializer \ No newline at end of file diff --git a/settings/base.py b/settings/base.py index bf20ec2..d62e02f 100644 --- a/settings/base.py +++ b/settings/base.py @@ -16,5 +16,6 @@ INSTALLED_APPS = [ # 'django.contrib.sessions', # 'django.contrib.messages', # 'django.contrib.staticfiles', + 'rest_framework', 'inventory', ] \ No newline at end of file