Открыл админу изделия, доработал списание
All checks were successful
Deploy MES Core / deploy (push) Successful in 10s
All checks were successful
Deploy MES Core / deploy (push) Successful in 10s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
import logging
|
||||
|
||||
from shiftflow.models import (
|
||||
CuttingSession,
|
||||
@@ -9,7 +10,8 @@ from shiftflow.models import (
|
||||
ShiftItem,
|
||||
)
|
||||
from shiftflow.services.sessions import close_cutting_session
|
||||
from warehouse.models import StockItem
|
||||
|
||||
logger = logging.getLogger('mes')
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
@@ -22,12 +24,15 @@ def apply_closing(
|
||||
consumptions: dict[int, float],
|
||||
remnants: list[dict],
|
||||
) -> None:
|
||||
logger.info('apply_closing:start user=%s machine=%s material=%s items=%s consumptions=%s remnants=%s', user_id, machine_id, material_id, list(item_actions.keys()), list(consumptions.keys()), len(remnants))
|
||||
|
||||
items = list(
|
||||
Item.objects.select_for_update(of=('self',))
|
||||
.select_related('task', 'task__deal', 'task__material', 'machine')
|
||||
.filter(id__in=list(item_actions.keys()), machine_id=machine_id, status='work', task__material_id=material_id)
|
||||
)
|
||||
if not items:
|
||||
logger.error('apply_closing:no_items machine=%s material=%s', machine_id, material_id)
|
||||
raise RuntimeError('Не найдено пунктов сменки для закрытия.')
|
||||
|
||||
report = CuttingSession.objects.create(
|
||||
@@ -38,6 +43,8 @@ def apply_closing(
|
||||
is_closed=False,
|
||||
)
|
||||
|
||||
logger.info('apply_closing:report_created id=%s', report.id)
|
||||
logger.info('apply_closing:update_items start items=%s', [it.id for it in items])
|
||||
for it in items:
|
||||
spec = item_actions.get(it.id) or {}
|
||||
action = (spec.get('action') or '').strip()
|
||||
@@ -59,6 +66,7 @@ def apply_closing(
|
||||
|
||||
ShiftItem.objects.create(session=report, task=it.task, quantity_fact=fact)
|
||||
|
||||
logger.info('apply_closing:consumption_count=%s', len(consumptions))
|
||||
for stock_item_id, qty in consumptions.items():
|
||||
if qty <= 0:
|
||||
continue
|
||||
@@ -69,6 +77,7 @@ def apply_closing(
|
||||
quantity=float(qty),
|
||||
)
|
||||
|
||||
logger.info('apply_closing:remnants_count=%s', len(remnants))
|
||||
for r in remnants:
|
||||
qty = float(r.get('quantity') or 0)
|
||||
if qty <= 0:
|
||||
@@ -82,6 +91,7 @@ def apply_closing(
|
||||
unique_id=None,
|
||||
)
|
||||
|
||||
logger.info('apply_closing:close_session id=%s', report.id)
|
||||
close_cutting_session(report.id)
|
||||
|
||||
for it in items:
|
||||
@@ -117,4 +127,6 @@ def apply_closing(
|
||||
quantity_fact=0,
|
||||
status='leftover',
|
||||
is_synced_1c=False,
|
||||
)
|
||||
)
|
||||
|
||||
logger.info('apply_closing:done report=%s', report.id)
|
||||
|
||||
Reference in New Issue
Block a user