Добавил страницу отгрузки, подправил логику генерации сменных заданий. Организовал редактирование позици сделок
All checks were successful
Deploy MES Core / deploy (push) Successful in 29s

This commit is contained in:
2026-04-14 07:27:54 +03:00
parent 69edd3fa97
commit 49e9080d0e
14 changed files with 2056 additions and 564 deletions

View File

@@ -436,4 +436,78 @@ def explode_roots_additive(
skipped_no_material,
skipped_supply,
)
return ExplosionStats(tasks_created, tasks_updated, 0, 0)
return ExplosionStats(tasks_created, tasks_updated, 0, 0)
@transaction.atomic
def rollback_roots_additive(
deal_id: int,
roots: list[tuple[int, int]],
) -> ExplosionStats:
"""Откат additive BOM Explosion.
Используется для сценария "запустили в производство, но в смену ещё не поставили":
- уменьшает started_qty у строки партии (делается во вьюхе)
- уменьшает quantity_ordered у ProductionTask по всем узлам BOM пропорционально откату
Ограничение: откат должен быть запрещён, если по сущности уже есть план/факт в WorkItem.
"""
deal = Deal.objects.select_for_update().get(pk=deal_id)
roots = [(int(eid), int(q)) for eid, q in (roots or []) if int(q or 0) > 0]
if not roots:
return ExplosionStats(0, 0, 0, 0)
root_ids = {eid for eid, _ in roots}
adjacency = _build_bom_graph(root_ids)
required_nodes: dict[int, int] = {}
for root_entity_id, root_qty in roots:
_accumulate_requirements(int(root_entity_id), int(root_qty), adjacency, set(), required_nodes)
entities = {
e.id: e
for e in ProductEntity.objects.select_related('planned_material', 'planned_material__category')
.filter(id__in=list(required_nodes.keys()))
}
tasks_updated = 0
skipped_supply = 0
missing_tasks = 0
for entity_id, qty in required_nodes.items():
entity = entities.get(int(entity_id))
if not entity:
continue
et = (entity.entity_type or '').strip()
if et in ['purchased', 'casting', 'outsourced']:
skipped_supply += 1
continue
pt = ProductionTask.objects.filter(deal=deal, entity=entity).first()
if not pt:
missing_tasks += 1
continue
old = int(pt.quantity_ordered or 0)
new_qty = old - int(qty)
if new_qty < 0:
new_qty = 0
if new_qty != old:
pt.quantity_ordered = int(new_qty)
pt.save(update_fields=['quantity_ordered'])
tasks_updated += 1
logger.info(
'rollback_roots_additive: deal_id=%s roots=%s nodes=%s tasks_updated=%s skipped_supply=%s missing_tasks=%s',
deal_id,
roots,
len(required_nodes),
tasks_updated,
skipped_supply,
missing_tasks,
)
return ExplosionStats(0, tasks_updated, 0, 0)