Skip to content

Commit

Permalink
calculation of Admission's total price done
Browse files Browse the repository at this point in the history
  • Loading branch information
mirolim-dev committed Feb 13, 2024
1 parent d3e8978 commit 6d6b944
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Binary file modified departments/__pycache__/meals_models.cpython-39.pyc
Binary file not shown.
23 changes: 22 additions & 1 deletion departments/meals_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.db import models
from django.db.models import Sum, F, ExpressionWrapper, DecimalField
from django.utils import timezone
from ckeditor_uploader.fields import RichTextUploadingField

from decimal import Decimal

# from local
from .models import Department, Bed
from hr_management.models import Patient
Expand Down Expand Up @@ -65,5 +68,23 @@ class Meta:
def __str__(self):
return f"{self.patient.__str__()} | {self.bed.__str__()}"


# @property
def calculate_total_price(self):
"""This function calculates the total price of admission by
(bed, diagnoses, meals, curings) fields' price
"""
bed_price = self.bed.price_for_one_day
diagnoz_price = self.diagnoses.aggregate(total_price=ExpressionWrapper(Sum('price'), output_field=DecimalField()))['total_price'] or Decimal('0.00')

# Calculate meal price considering individual prices per MealTime
mealtime_price = self.meals.aggregate(
total_price=ExpressionWrapper(Sum(F('price')), output_field=DecimalField())
)['total_price'] or Decimal('0.00')

curing_price = self.curings.aggregate(
total_price=ExpressionWrapper(Sum(F('price')), output_field=DecimalField())
)['total_price'] or Decimal('0.00')

total_price = diagnoz_price + mealtime_price + curing_price + bed_price
total_price_formatted = total_price.quantize(Decimal('0.00'), rounding='ROUND_HALF_UP')
return total_price_formatted
3 changes: 2 additions & 1 deletion templates/departments/show_admissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<th scope="col">Bed</th>
<th scope="col">Starts at</th>
<th scope="col">Finishes at</th>
<th scope='col'>Total price</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
Expand All @@ -48,8 +49,8 @@ <h5>There are no admissions in this department</h5>
<td>{{ admission.bed.room.name }}</td>
<td>{{ admission.starts_at | date }}</td>
<td>{{ admission.finishes_at | date }}</td>
<td>{{ admission.calculate_total_price }} UZS</td>
<td>{{ admission.status | display_admission_status }}</td>

<td>
<span>

Expand Down

0 comments on commit 6d6b944

Please sign in to comment.