add some new fields to quota sale transaction model - add rancher information about live stocks & quota aalocations information
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import string
|
||||
import random
|
||||
from apps.product import models as product_models
|
||||
from apps.authentication.models import User
|
||||
from apps.pos_device.models import Device
|
||||
@@ -7,6 +9,7 @@ from django.db import models
|
||||
|
||||
|
||||
class InventoryEntry(BaseModel):
|
||||
entry_identity = models.CharField(max_length=50, null=True)
|
||||
distribution = models.ForeignKey(
|
||||
product_models.QuotaDistribution,
|
||||
on_delete=models.CASCADE,
|
||||
@@ -27,6 +30,15 @@ class InventoryEntry(BaseModel):
|
||||
is_confirmed = models.BooleanField(default=False)
|
||||
notes = models.TextField(blank=True, null=True)
|
||||
|
||||
def generate_entry_identity(self): # noqa
|
||||
""" generate identity for every device """
|
||||
# prefix = "POS"
|
||||
while True:
|
||||
number_part = ''.join(random.choices(string.digits, k=6))
|
||||
code = f"{self.distribution.quota.quota_id}{number_part}"
|
||||
if not InventoryEntry.objects.filter(entry_identity=code).exists():
|
||||
return code
|
||||
|
||||
@property
|
||||
def total_sold(self):
|
||||
return self.inventory_sales.aggregate(total=models.Sum('weight'))['total'] or 0
|
||||
@@ -39,6 +51,8 @@ class InventoryEntry(BaseModel):
|
||||
return f"distribution: {self.distribution.distribution_id}-{self.organization.name}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.entry_identity:
|
||||
self.entry_identity = self.generate_entry_identity()
|
||||
super(InventoryEntry, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -83,6 +97,14 @@ class InventoryQuotaSaleTransaction(BaseModel):
|
||||
null=True
|
||||
)
|
||||
transaction_price = models.PositiveBigIntegerField(default=0)
|
||||
price_paid = models.PositiveBigIntegerField(default=0)
|
||||
type_of_price = (
|
||||
('card', 'CARD'),
|
||||
('cash', 'CASH'),
|
||||
('credit', 'CREDIT'),
|
||||
('check', 'CHECK'),
|
||||
)
|
||||
price_type = models.CharField(choices=type_of_price, max_length=50, null=True)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
herd_owners_number = models.PositiveBigIntegerField(default=0)
|
||||
transactions_number = models.PositiveBigIntegerField(default=0)
|
||||
@@ -92,6 +114,12 @@ class InventoryQuotaSaleTransaction(BaseModel):
|
||||
('failed', 'Failed'),
|
||||
)
|
||||
transaction_status = models.CharField(choices=status_type, max_length=25, null=True)
|
||||
transaction_status_code = models.IntegerField(default=0)
|
||||
result_text = models.TextField(null=True)
|
||||
ref_num = models.CharField(max_length=50, null=True)
|
||||
terminal = models.CharField(max_length=50, null=True)
|
||||
payer_cart = models.CharField(max_length=50, null=True)
|
||||
additional = models.JSONField(default=dict)
|
||||
|
||||
def buyers_count(self):
|
||||
""" number of buyers from specific inventory """
|
||||
|
||||
Reference in New Issue
Block a user