transaction system deploying
This commit is contained in:
@@ -88,14 +88,8 @@ class InventoryQuotaSaleTransaction(BaseModel):
|
||||
related_name='inventory_sales',
|
||||
null=True
|
||||
)
|
||||
weight = models.DecimalField(max_digits=12, decimal_places=2, null=True)
|
||||
weight = models.PositiveBigIntegerField(default=0)
|
||||
delivery_address = models.TextField(blank=True, null=True)
|
||||
product = models.ForeignKey(
|
||||
product_models.Product,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='sale_transactions',
|
||||
null=True
|
||||
)
|
||||
transaction_price = models.PositiveBigIntegerField(default=0)
|
||||
price_paid = models.PositiveBigIntegerField(default=0)
|
||||
type_of_price = (
|
||||
@@ -121,17 +115,43 @@ class InventoryQuotaSaleTransaction(BaseModel):
|
||||
payer_cart = models.CharField(max_length=50, null=True)
|
||||
additional = models.JSONField(default=dict)
|
||||
|
||||
def buyers_count(self):
|
||||
""" number of buyers from specific inventory """
|
||||
|
||||
unique_buyers_count = self.objects.filter(
|
||||
inventory_entry=self.inventory_entry
|
||||
).values('buyer_user').distinct().count()
|
||||
|
||||
return unique_buyers_count
|
||||
@property
|
||||
def total_weight(self):
|
||||
""" summation of total sold product weight """
|
||||
return sum(item.weight for item in self.items.all)
|
||||
|
||||
def __str__(self):
|
||||
return f"Inventory Sale: {self.transaction_id}-{self.quota_distribution.distribution_id}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(InventoryQuotaSaleTransaction, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class InventoryQuotaSaleItem(BaseModel):
|
||||
transaction = models.ForeignKey(
|
||||
InventoryQuotaSaleTransaction,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='items',
|
||||
null=True
|
||||
)
|
||||
quota_distribution = models.ForeignKey(
|
||||
product_models.QuotaDistribution,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='sale_items',
|
||||
null=True
|
||||
)
|
||||
product = models.ForeignKey(
|
||||
product_models.Product,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='sale_items',
|
||||
null=True
|
||||
)
|
||||
weight = models.PositiveBigIntegerField(default=0)
|
||||
unit_price = models.PositiveBigIntegerField(default=0)
|
||||
total_price = models.PositiveBigIntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f'Item {self.product} - {self.weight} Kg - {self.total_price}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
return super(InventoryQuotaSaleItem, self).save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user