feat: wpr增加自动编号逻辑
This commit is contained in:
parent
9f3b3a52a7
commit
88a5d55425
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.12 on 2025-05-16 07:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mtm', '0057_process_number_to_batch'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='process',
|
||||||
|
name='wpr_number_rule',
|
||||||
|
field=models.TextField(blank=True, null=True, verbose_name='单个编号规则'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -32,6 +32,7 @@ class Process(CommonBModel):
|
||||||
mstate_json = models.JSONField('中间状态', default=list, blank=True)
|
mstate_json = models.JSONField('中间状态', default=list, blank=True)
|
||||||
parent = models.ForeignKey('self', verbose_name='父工序', on_delete=models.CASCADE, null=True, blank=True)
|
parent = models.ForeignKey('self', verbose_name='父工序', on_delete=models.CASCADE, null=True, blank=True)
|
||||||
number_to_batch = models.BooleanField('个号转批号', default=False)
|
number_to_batch = models.BooleanField('个号转批号', default=False)
|
||||||
|
wpr_number_rule = models.TextField("单个编号规则", null=True, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '工序'
|
verbose_name = '工序'
|
||||||
|
|
|
@ -656,15 +656,24 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
|
||||||
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok}))
|
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok}))
|
||||||
mlogbout.count_json_from = mlogbin.count_json_from
|
mlogbout.count_json_from = mlogbin.count_json_from
|
||||||
mlogbout.save(update_fields=["count_json_from"])
|
mlogbout.save(update_fields=["count_json_from"])
|
||||||
|
wpr_number_rule = process.wpr_number_rule
|
||||||
if material_out.tracking == Material.MA_TRACKING_SINGLE:
|
if material_out.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
number = mlogbin.batch
|
number = mlogbin.batch
|
||||||
if mlogbin.number_from:
|
if mlogbin.number_from:
|
||||||
number = mlogbin.number_from
|
number = mlogbin.number_from
|
||||||
if d_count_real == 1:
|
if d_count_real == 1:
|
||||||
|
if wpr_number_rule:
|
||||||
|
number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out)
|
||||||
Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout)
|
Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout)
|
||||||
else:
|
else:
|
||||||
|
if wpr_number_rule:
|
||||||
|
number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, gen_count=d_count_real)
|
||||||
for i in range(d_count_real):
|
for i in range(d_count_real):
|
||||||
Mlogbw.objects.get_or_create(number=f'{number}-{i+1}', mlogb=mlogbout)
|
if wpr_number_rule:
|
||||||
|
numberx = number_list[i]
|
||||||
|
else:
|
||||||
|
numberx = f'{number}-{i+1}'
|
||||||
|
Mlogbw.objects.get_or_create(number=numberx, mlogb=mlogbout)
|
||||||
elif is_fix:# 支持批到批,个到个
|
elif is_fix:# 支持批到批,个到个
|
||||||
d_count_real = mlogbin.count_use-mlogbin.count_pn_jgqbl
|
d_count_real = mlogbin.count_use-mlogbin.count_pn_jgqbl
|
||||||
d_count_ok = d_count_real
|
d_count_ok = d_count_real
|
||||||
|
@ -676,6 +685,22 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
|
||||||
else:
|
else:
|
||||||
raise ParseError("不支持生成产出物料!")
|
raise ParseError("不支持生成产出物料!")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def gen_number_with_rule(cls, rule, material_out:Material, gen_count=1):
|
||||||
|
from apps.wpmw.models import Wpr
|
||||||
|
now = timezone.now()
|
||||||
|
c_year = now.year
|
||||||
|
c_month = now.month
|
||||||
|
m_model = material_out.model
|
||||||
|
wps_qs = Wpr.objects.filter(material_start=material_out, create_time__year=c_year, create_time__month=c_month).order_by("create_time")
|
||||||
|
n_count = wps_qs.count() + 1
|
||||||
|
try:
|
||||||
|
if gen_count == 1:
|
||||||
|
return rule.format(c_year=c_year, c_month=c_month, m_model=m_model, n_count=n_count)
|
||||||
|
else:
|
||||||
|
return [rule.format(c_year=c_year, c_month=c_month, m_model=m_model, n_count=n_count+i) for i in range(gen_count)]
|
||||||
|
except (KeyError, ValueError) as e:
|
||||||
|
raise ParseError(f"个号生成错误: {e}")
|
||||||
|
|
||||||
class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet):
|
class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet):
|
||||||
perms_map = {"put": "mlog.update"}
|
perms_map = {"put": "mlog.update"}
|
||||||
|
|
Loading…
Reference in New Issue