diff --git a/.gitignore b/.gitignore index ebd7ddf..bb04232 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc __pycache__/* inventory/migrations/__pycache__/0001_initial.cpython-310.pyc +*.log \ No newline at end of file diff --git a/inventory/__pycache__/models.cpython-310.pyc b/inventory/__pycache__/models.cpython-310.pyc index a87835c..b9b8b02 100644 Binary files a/inventory/__pycache__/models.cpython-310.pyc and b/inventory/__pycache__/models.cpython-310.pyc differ diff --git a/inventory/migrations/0003_alter_stockoperation_product_alter_inventory_product_and_more.py b/inventory/migrations/0003_alter_stockoperation_product_alter_inventory_product_and_more.py new file mode 100644 index 0000000..a8ce40c --- /dev/null +++ b/inventory/migrations/0003_alter_stockoperation_product_alter_inventory_product_and_more.py @@ -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', + ), + ] diff --git a/logs.log b/logs.log index 92ab0b8..1fcc9e7 100644 --- a/logs.log +++ b/logs.log @@ -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 diff --git a/pricing/models.py b/pricing/models.py index bca45d2..246d9ae 100644 --- a/pricing/models.py +++ b/pricing/models.py @@ -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} руб. (с учетом скидки)" diff --git a/settings/__pycache__/base.cpython-310.pyc b/settings/__pycache__/base.cpython-310.pyc index db58c1b..041679a 100644 Binary files a/settings/__pycache__/base.cpython-310.pyc and b/settings/__pycache__/base.cpython-310.pyc differ