Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #11

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added full_scheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
os.environ["PATH"] += os.pathsep + 'C:/Program Files/Graphviz/bin'
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
Binary file added my_project_subsystem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 31 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions products/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth import get_user_model
from django.db import models
from decimal import Decimal


class Product(models.Model):
Expand All @@ -23,6 +24,20 @@ class Product(models.Model):
def shop_name(self):
return self.seller.shop_name

def calculate_final_price(self):
"""
Расчет финальной стоимости товара
"""

base_price = self.price
tax = base_price * Decimal('0.06') #: Налог
bank_fee = base_price * Decimal('0.02') #: Комиссия банку
author_commission = base_price * Decimal('0.02') #: Комиссия за транзакцию продавца
marketplace_fee = base_price * Decimal('0.20') #: Выручка маркетплейса

final_price = base_price + tax + bank_fee + author_commission + marketplace_fee
return final_price

def __str__(self):
return f'{self.product_title} {self.shop_name} {self.seller}'

Expand Down
3 changes: 3 additions & 0 deletions products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def perform_create(self, serializer):

new_product = serializer.save(seller=self.request.user)
new_product.seller = self.request.user

total_price = new_product.calculate_final_price()
new_product.price = total_price
new_product.save()


Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ django-extensions = "^3.2.3"
ipython = "^8.15.0"
django-filter = "^23.3"
pillow = "^10.0.1"
pyparsing = "^3.1.1"
pydot = "^1.4.2"


[build-system]
Expand Down