This commit is contained in:
29
shiftflow/management/commands/shiftflow_explode_deal.py
Normal file
29
shiftflow/management/commands/shiftflow_explode_deal.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from shiftflow.models import DealItem
|
||||
from shiftflow.services.bom_explosion import explode_deal
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "BOM Explosion для сделки: генерирует ProductionTask и MaterialRequirement."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("deal_id", type=int)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
deal_id = int(options["deal_id"])
|
||||
stats = explode_deal(deal_id)
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"OK deal={deal_id} tasks_created={stats.tasks_created} tasks_updated={stats.tasks_updated} "
|
||||
f"req_created={stats.req_created} req_updated={stats.req_updated}"
|
||||
)
|
||||
)
|
||||
|
||||
if stats.tasks_created == 0 and stats.tasks_updated == 0 and stats.req_created == 0 and stats.req_updated == 0:
|
||||
di_count = DealItem.objects.filter(deal_id=deal_id).count()
|
||||
if di_count == 0:
|
||||
self.stdout.write('Подсказка: в сделке нет позиций (DealItem). Добавь DealItem и повтори команду.')
|
||||
else:
|
||||
self.stdout.write('Подсказка: проверь заполнение BOM и норм расхода (blank_area_m2/blank_length_mm) на leaf-деталях.')
|
||||
Reference in New Issue
Block a user