From 4c3610ac253185d6d6c65976640f34ba2697ce34 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 6 Mar 2024 17:07:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=B7=E6=96=99=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=BD=A6=E9=97=B4=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0041_wmaterial_count_eweight.py | 18 ++++++++++++++++++ apps/wpm/models.py | 1 + apps/wpm/services.py | 19 +++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 apps/wpm/migrations/0041_wmaterial_count_eweight.py diff --git a/apps/wpm/migrations/0041_wmaterial_count_eweight.py b/apps/wpm/migrations/0041_wmaterial_count_eweight.py new file mode 100644 index 00000000..de495869 --- /dev/null +++ b/apps/wpm/migrations/0041_wmaterial_count_eweight.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2024-03-06 08:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wpm', '0040_mlog_count_n_xzp'), + ] + + operations = [ + migrations.AddField( + model_name='wmaterial', + name='count_eweight', + field=models.FloatField(default=0, verbose_name='单数重量'), + ), + ] diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 2f8d279c..accf5d0a 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -83,6 +83,7 @@ class WMaterial(CommonBDModel): Material, verbose_name='物料', on_delete=models.CASCADE) batch = models.CharField('批次号', max_length=50) count = models.PositiveIntegerField('当前数量', default=0) + count_eweight = models.FloatField('单数重量', default=0) class Meta: unique_together = ('material', 'batch', 'belong_dept') diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 022a1a9e..fcbc45a5 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -191,12 +191,15 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): 'batch': mlog.batch, 'material': item.material_out, 'belong_dept': belong_dept }) wmaterial.count = wmaterial.count + item.count_ok + if hasattr(item, 'count_real_eweight'): + wmaterial.count_eweight = item.count_real_eweight wmaterial.save() else: wmaterial, _ = WMaterial.objects.get_or_create(batch=mlog.batch, material=material_out, belong_dept=belong_dept, defaults={ 'batch': mlog.batch, 'material': material_out, 'belong_dept': belong_dept }) wmaterial.count = wmaterial.count + mlog.count_ok + wmaterial.count_eweight = mlog.count_real_eweight wmaterial.save() mlog.submit_time = now mlog.submit_user = user @@ -279,7 +282,10 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime return now = timezone.now() if handover.wm: - wm = handover.wm + wm: WMaterial = handover.wm + need_add = True + if '混料' in wm.material.name: + need_add = False count_x = wm.count - handover.count if count_x < 0: raise ParseError('车间库存不足!') @@ -288,11 +294,12 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime else: wm.count = count_x wm.save() - wm_to, _ = WMaterial.objects.get_or_create(batch=handover.batch, material=handover.material, belong_dept=handover.send_dept, defaults={ - 'batch': handover.batch, 'material': handover.material, 'belong_dept': handover.send_dept - }) - wm_to.count = wm_to.count + handover.count - wm_to.save() + if need_add: + wm_to, _ = WMaterial.objects.get_or_create(batch=handover.batch, material=handover.material, belong_dept=handover.send_dept, defaults={ + 'batch': handover.batch, 'material': handover.material, 'belong_dept': handover.send_dept + }) + wm_to.count = wm_to.count + handover.count + wm_to.save() handover.submit_user = user handover.submit_time = now handover.save()