forked from erp-dev/erp
feat: added n-to-1 relation between sales_order_item and printing_job model
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from flower.common import ModelBase
|
||||
@@ -289,6 +291,13 @@ class PrintingOrder(ModelBase):
|
||||
return int((completed_count / jobs.count()) * 100)
|
||||
|
||||
|
||||
class PrintingJobWorkStateEnum(models.IntegerChoices):
|
||||
PRODUCING = 0, '生产中'
|
||||
WAITING_FOR_DELIVERY = 1, '待送货'
|
||||
WAITING_FOR_INVOICE = 2, '待开单'
|
||||
FINISHED = 3, '已完结'
|
||||
|
||||
|
||||
class PrintingJob(ModelBase):
|
||||
"""PrintingJob model representing a printing job associated with an order."""
|
||||
printing_order = models.ForeignKey(
|
||||
@@ -303,6 +312,11 @@ class PrintingJob(ModelBase):
|
||||
related_name='printing_jobs',
|
||||
verbose_name='产品',
|
||||
)
|
||||
work_state = models.IntegerField(
|
||||
choices=PrintingJobWorkStateEnum.choices,
|
||||
default=PrintingJobWorkStateEnum.PRODUCING,
|
||||
verbose_name='业务进展',
|
||||
)
|
||||
quantity = models.PositiveIntegerField(verbose_name='数量')
|
||||
unit = models.CharField(max_length=50, verbose_name='单位')
|
||||
size = models.CharField(max_length=100, null=True, blank=True, verbose_name='一段尺寸')
|
||||
@@ -320,6 +334,16 @@ class PrintingJob(ModelBase):
|
||||
def __str__(self):
|
||||
return self.printing_order.human_id
|
||||
|
||||
@property
|
||||
def billed_quantity(self) -> Decimal:
|
||||
"""
|
||||
开单数量:所有关联销售明细的数量之和
|
||||
"""
|
||||
from business.models import SalesOrderItem
|
||||
|
||||
total = self.sales_order_items.aggregate(total=models.Sum('quantity')).get('total')
|
||||
return total or Decimal('0')
|
||||
|
||||
@property
|
||||
def status(self) -> str:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user