feat: gen_number_with_rule 完善

This commit is contained in:
caoqianming 2025-09-09 11:28:04 +08:00
parent 81a16fd37e
commit d19fee8e6f
1 changed files with 11 additions and 8 deletions

View File

@ -839,13 +839,13 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
number = mlogbin.number_from
if d_count_real == 1:
if wpr_number_rule:
number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out)
number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog)
if number_to_batch:
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": number}))
Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout)
else:
if wpr_number_rule:
number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, gen_count=d_count_real)
number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog, gen_count=d_count_real)
for i in range(d_count_real):
if wpr_number_rule:
numberx = number_list[i]
@ -864,15 +864,18 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
MlogbInViewSet.p_create_after(mlogbin)
@classmethod
def gen_number_with_rule(cls, rule, material_out:Material, gen_count=1):
def gen_number_with_rule(cls, rule, material_out:Material, mlog:Mlog, gen_count=1):
from apps.wpmw.models import Wpr
now = datetime.now() - timedelta(hours=6, minutes=20)
c_year = now.year
handle_date = mlog.handle_date
c_year = handle_date.year
c_year2 = str(c_year)[-2:]
c_month = now.month
c_month = handle_date.month
m_model = material_out.model
# 不按产品走,只按生产日期走
wpr = Wpr.objects.filter(create_time__year=c_year, create_time__month=c_month).order_by("number").last()
# 按生产日志查询
wpr = Wpr.objects.filter(wpr_mlogbw__mlogb__material_out=material_out,
wpr_mlogbw__mlogb__mlog__is_fix=False,
wpr_mlogbw__mlogb__mlog__submit_time__isnull=False,
wpr_mlogbw__mlogb__mlog__handle_date__year=c_year, wpr_mlogbw__mlogb__mlog__handle_date__month=c_month).order_by("number").last()
cq_w = 4
if '02d' in rule:
cq_w = 2