1
0
forked from erp-dev/erp

feat: added n-to-1 relation between sales_order_item and printing_job model

This commit is contained in:
2025-12-11 18:09:10 +08:00
parent 633031d7cb
commit 1a8c446365
30 changed files with 41736 additions and 40 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.8 on 2025-12-11 04:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('printing', '0021_plateorder_print_count_printingorder_print_count'),
]
operations = [
migrations.AddField(
model_name='printingjob',
name='work_state',
field=models.IntegerField(default=0, verbose_name='业务进展'),
),
]

View File

@@ -0,0 +1,21 @@
from django.db import migrations, models
import printing.models
class Migration(migrations.Migration):
dependencies = [
('printing', '0022_printingjob_work_state'),
]
operations = [
migrations.AlterField(
model_name='printingjob',
name='work_state',
field=models.IntegerField(
choices=printing.models.PrintingJobWorkStateEnum.choices,
default=printing.models.PrintingJobWorkStateEnum.PRODUCING,
verbose_name='业务进展',
),
),
]

View File

@@ -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:
"""