feat addded fully task 3

main
Далер 1 day ago
parent f529b056b0
commit cd5e1cd648

1
.gitignore vendored

@ -1,3 +1,4 @@
*.pyc
__pycache__/*
inventory/migrations/__pycache__/0001_initial.cpython-310.pyc
*.log

@ -0,0 +1,33 @@
# Generated by Django 5.1.4 on 2025-01-08 16:17
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('inventory', '0002_contractor_position_truck_employee_supplycontract'),
('product_directory', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='stockoperation',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='product_directory.product', verbose_name='Товар'),
),
migrations.AlterField(
model_name='inventory',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='product_directory.product', verbose_name='Товар'),
),
migrations.AlterField(
model_name='pricelist',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='product_directory.product', verbose_name='Товар'),
),
migrations.DeleteModel(
name='Product',
),
]

@ -133,3 +133,28 @@ Watching for file changes with StatReloader
"GET /admin/jsi18n/ HTTP/1.1" 200 3342
"GET /admin/warehouse/stockoperation/statistics/ HTTP/1.1" 200 28103
"GET /admin/warehouse/stockoperation/ HTTP/1.1" 200 15416
Watching for file changes with StatReloader
Not Found: /
"GET / HTTP/1.1" 404 2782
"GET /api/pricing/ HTTP/1.1" 200 11324
"GET /static/rest_framework/css/bootstrap.min.css HTTP/1.1" 304 0
"GET /static/rest_framework/css/prettify.css HTTP/1.1" 304 0
"GET /static/rest_framework/css/bootstrap-tweaks.css HTTP/1.1" 304 0
"GET /static/rest_framework/js/csrf.js HTTP/1.1" 304 0
"GET /static/rest_framework/js/jquery-3.7.1.min.js HTTP/1.1" 304 0
"GET /static/rest_framework/css/default.css HTTP/1.1" 304 0
"GET /static/rest_framework/js/bootstrap.min.js HTTP/1.1" 304 0
"GET /static/rest_framework/js/ajax-form.js HTTP/1.1" 304 0
"GET /static/rest_framework/js/prettify-min.js HTTP/1.1" 304 0
"GET /static/rest_framework/js/default.js HTTP/1.1" 304 0
"GET /static/rest_framework/js/load-ajax-form.js HTTP/1.1" 304 0
"GET /static/rest_framework/img/grid.png HTTP/1.1" 304 0
"GET /api/pricing/swagger/ HTTP/1.1" 200 2245
"GET /static/drf-yasg/style.css HTTP/1.1" 304 0
"GET /static/drf-yasg/swagger-ui-dist/swagger-ui.css HTTP/1.1" 304 0
"GET /static/drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js HTTP/1.1" 304 0
"GET /static/drf-yasg/immutable.min.js HTTP/1.1" 304 0
"GET /static/drf-yasg/swagger-ui-dist/swagger-ui-bundle.js HTTP/1.1" 304 0
"GET /static/drf-yasg/insQ.min.js HTTP/1.1" 304 0
"GET /static/drf-yasg/swagger-ui-init.js HTTP/1.1" 304 0
"GET /api/pricing/swagger/?format=openapi HTTP/1.1" 200 44272

@ -1,4 +1,7 @@
from django.db import models
from io import BytesIO
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
# Справочник товаров
class Product(models.Model):
@ -38,7 +41,6 @@ class PriceList(models.Model):
constraint_price_change = models.DecimalField(max_digits=5, decimal_places=2, default=90, verbose_name="Лимит на изменение цены (%)")
def save(self, *args, **kwargs):
# Логика проверки на изменение цены
if self.pk:
old_price = PriceList.objects.get(pk=self.pk).final_price
price_change_percent = abs((self.final_price - old_price) / old_price) * 100
@ -81,6 +83,19 @@ class PriceTag(models.Model):
price_list = models.ForeignKey(PriceList, on_delete=models.CASCADE, verbose_name="Прайс-лист")
tag_image = models.ImageField(upload_to='price_tags/', verbose_name="Изображение ценника", blank=True, null=True)
price_effective_date = models.DateField(verbose_name="Дата вступления в силу ценника")
def generate_pdf(self):
"""Генерация ценника в формате PDF."""
buffer = BytesIO()
c = canvas.Canvas(buffer, pagesize=letter)
c.drawString(100, 750, f"Продукт: {self.product.name}")
c.drawString(100, 730, f"Тип цены: {self.price_list.price_type.name}")
c.drawString(100, 710, f"Входная цена: {self.price_list.entry_price} руб.")
c.drawString(100, 690, f"Итоговая цена: {self.price_list.final_price} руб.")
c.showPage()
c.save()
buffer.seek(0)
return buffer
def __str__(self):
return f"Ценник для {self.product.name} - {self.price_effective_date}"
@ -104,5 +119,10 @@ class PriceListWithDiscount(models.Model):
discount = models.ForeignKey(Discount, on_delete=models.CASCADE, verbose_name="Скидка")
final_price_after_discount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Итоговая цена после скидки")
def save(self, *args, **kwargs):
# Расчёт итоговой цены с учётом скидки
self.final_price_after_discount = self.price_list.final_price - (self.price_list.final_price * self.discount.discount_percentage / 100)
super().save(*args, **kwargs)
def __str__(self):
return f"{self.price_list.product.name} - {self.final_price_after_discount} руб. (с учетом скидки)"

Loading…
Cancel
Save