class TreatmentBills(TimeStampedModel, models.Model):
"""
Description : this table create for treatment_bills
"""
id = models.AutoField(primary_key=True)
treatment_name = models.CharField(_('Treatment Name'), max_length=255, blank=True)
code = models.CharField(_('Treatment Code'), max_length=50, blank=True)
treatment_bill_receiver = models.ForeignKey(
User, on_delete=models.CASCADE, related_name="treatment_bill_receiver",
help_text=_("Patient or Employee received bills")
)
treatment_bill_creator = models.ForeignKey(
User, on_delete=models.CASCADE, related_name="treatment_bill_creator",
help_text=_("Provider doctor or Hospital generate bills")
)
price = models.DecimalField(
_('Bill price amount'), blank=True, null=True,
default=0, max_digits=11,
decimal_places=2
)
class Meta:
"""
Meta class
"""
db_table = "treatment_bills"
class TreatmentBillGenerate(TimeStampedModel, models.Model):
"""
To generate bills
"""
treatment_bill = models.ManyToManyField(TreatmentBills, blank=True, related_name='treatment_bill')
reject_reason = models.TextField(_('Reject reason'), default='')
reject_date = models.DateTimeField(null=True)
is_share = models.BooleanField(default=False, help_text=_("Provider share bill to patient"))
is_accept_reject = models.BooleanField(
default=False, help_text=_(
"Employee can accept/reject bill: if is share True then - accept:True, Reject:False "
)
)
objects = TreatmentBillGenerateManager()
class Meta:
"""
Meta class
"""
db_table = "treatment_bill_generates"
Это мои модели, у которых есть счета, и создание счетов выполняется поставщиком ролей
class ProviderUserSerializer(serializers.ModelSerializer):
"""
Provider List view get
"""
user_profile = UserProfileSerializer()
provider_detail = ProviderDetailSerializer()
specialty = serializers.SerializerMethodField()
bills_accepted = serializers.SerializerMethodField()
bill_generated_price = serializers.SerializerMethodField()
bill_accepted_price = serializers.SerializerMethodField()
@staticmethod
def get_specialty(obj):
return obj.get_user_specialities()
@staticmethod
def get_bills_accepted(self):
bills_accepted = TreatmentBillGenerate.objects.filter(treatment_bill__treatment_bill_creator_id=
self, is_accept_reject=True).count()
return bills_accepted
@staticmethod
def get_bill_generated_price(self):
bill_generated_price = TreatmentBillGenerate.objects.filter(treatment_bill__price=
self).aggregate(Sum('price'))
return bill_generated_price
@staticmethod
def get_bill_accepted_price(self):
bill_accepted_price = TreatmentBillGenerate.objects.filter(treatment_bill__price=
self, is_accept_reject=True).aggregate(Sum('price'))
return bill_accepted_price
class Meta(object):
"""
User meta class.
"""
model = User
fields = (
'id', 'first_name', 'last_name', 'full_name', 'email', 'user_profile', 'provider_detail',
'specialty', 'bill_generated', 'bills_accepted', 'bill_generated_price', 'bill_accepted_price'
)
Это мой сериализатор, в котором есть список, и я хочу получить цены на различные счета созданы и приняты
Я пытаюсь получить цену сформированного счета и счета приняты. Роль пользователя - поставщик, и администратор проходит проверку подлинности, чтобы увидеть список поставщиков с ценой, отличной от стоимости счета, сгенерированного и принятого