1
0
forked from erp-dev/erp

feat: added migrate for set id init value into 8000 of plate_order

This commit is contained in:
2025-11-20 13:01:44 +08:00
parent ad0b6a84d2
commit 6091280fdc
12 changed files with 931 additions and 606 deletions

View File

@@ -22,11 +22,35 @@ class StockChangeSourceEnum(models.IntegerChoices):
SALES_RETURN = 2, '销退'
TRANSPORT_IN = 3, '调入'
RECHECK_ADD = 4, '盘盈'
COMBINE = 5, '合并'
SALES = 5, '销售'
PURCHASE_RETURN = 6, '采购退货'
TRANSPORT_OUT = 7, '调出'
RECHECK_REMOVE = 8, '盘亏'
SALES = 6, '销售'
PURCHASE_RETURN = 7, '采购退货'
TRANSPORT_OUT = 8, '调出'
RECHECK_REMOVE = 9, '盘亏'
EXPLODE = 10, '拆卷'
@classmethod
def incoming_values(cls) -> set[int]:
"""返回被视为入库的来源类型"""
return {
cls.PURCHASE,
cls.SALES_RETURN,
cls.TRANSPORT_IN,
cls.RECHECK_ADD,
cls.COMBINE,
}
@classmethod
def outgoing_values(cls) -> set[int]:
"""返回被视为出库的来源类型"""
return {
cls.SALES,
cls.PURCHASE_RETURN,
cls.TRANSPORT_OUT,
cls.RECHECK_REMOVE,
cls.EXPLODE,
}
class StockChangeTypeEnum(models.IntegerChoices):
@@ -103,10 +127,10 @@ class StockChangeRecord(ModelBase):
def clean(self):
if self.type == StockChangeTypeEnum.ADD:
if self.source_type > 4:
if self.source_type not in StockChangeSourceEnum.incoming_values():
raise ValidationError('入库记录的来源类型无效')
elif self.type == StockChangeTypeEnum.REMOVE:
if self.source_type < 5:
if self.source_type not in StockChangeSourceEnum.outgoing_values():
raise ValidationError('出库记录的来源类型无效')
def save(self, *args, **kwargs):

View File

@@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.utils import timezone
from decimal import Decimal
@@ -128,6 +129,54 @@ class StockServicesTestCase(TestCase):
)
class StockChangeRecordValidationTestCase(StockServicesTestCase):
"""验证 StockChangeRecord.clean 的来源类型校验"""
def test_add_record_accepts_combine_source(self):
record = models.StockChangeRecord(
merchant=self.merchant,
warehouse=self.warehouse_main,
type=models.StockChangeTypeEnum.ADD,
source_type=models.StockChangeSourceEnum.COMBINE,
)
try:
record.full_clean()
except ValidationError as exc:
self.fail(f'合并应视为入库来源,但触发校验错误: {exc}')
def test_remove_record_accepts_explode_source(self):
record = models.StockChangeRecord(
merchant=self.merchant,
warehouse=self.warehouse_main,
type=models.StockChangeTypeEnum.REMOVE,
source_type=models.StockChangeSourceEnum.EXPLODE,
)
try:
record.full_clean()
except ValidationError as exc:
self.fail(f'拆卷应视为出库来源,但触发校验错误: {exc}')
def test_add_record_rejects_outgoing_source(self):
record = models.StockChangeRecord(
merchant=self.merchant,
warehouse=self.warehouse_main,
type=models.StockChangeTypeEnum.ADD,
source_type=models.StockChangeSourceEnum.SALES,
)
with self.assertRaises(ValidationError):
record.full_clean()
def test_remove_record_rejects_incoming_source(self):
record = models.StockChangeRecord(
merchant=self.merchant,
warehouse=self.warehouse_main,
type=models.StockChangeTypeEnum.REMOVE,
source_type=models.StockChangeSourceEnum.PURCHASE,
)
with self.assertRaises(ValidationError):
record.full_clean()
class FindInventoryTestCase(StockServicesTestCase):
"""测试 find_inventory 函数"""