""" Order model """ from django.db import models, transaction from django.db.models import F from core.apps.eggs.models import Location, courier, location, market from core.http.models import base class Order(base.AbstractBaseModel): STATUS_CHOICES = ( ("pending", "Pending"), ("delivery", "Delivery"), ("success", "Success"), ("done", "Done"), ("cancel", "Cancel"), ) courier_id = models.ForeignKey( to=courier.Courier, on_delete=models.CASCADE, related_name="orders", null=True, blank=True, ) market_id = models.ForeignKey( to=market.Market, on_delete=models.CASCADE, related_name="orders", null=True, blank=True, ) data = models.DateTimeField(auto_now_add=True) status = models.CharField( max_length=255, choices=STATUS_CHOICES, default="pending" ) comment = models.TextField(blank=True, null=True) price = models.DecimalField(max_digits=30, decimal_places=2, default=0) price_paid = models.DecimalField( max_digits=30, decimal_places=2, default=0 ) debt = models.DecimalField(max_digits=30, decimal_places=2, default=0) location_id = models.ForeignKey( Location, on_delete=models.CASCADE, null=True ) count = models.IntegerField(null=True, blank=True, default=0) def __str__(self): return f"Order - {self.id}, status - {self.status}" class Meta: verbose_name = "Order" verbose_name_plural = "Orders" db_table = "order"