def new_production_order(): form = CreateProductionOrderForm() stage = {'crumbroot': '/production'} if form.validate_on_submit(): try: sno = form.prod_order_sno.sno.data with get_session() as session: title = form.prod_order_title.data.strip() if not sno: sno = get_serialno(series='PROD', efield=title, register=True, session=session) else: # additional sno validation? pass cards = {x['ident']: int(x['qty']) for x in form.modules.data if x['ident']} deltas = [{'orig-cardname': x['orig_cardname'], 'target-cardname': x['target_cardname'], 'sno': x['sno']} for x in form.deltas.data if x['sno']] requested_by = get_username_from_full_name(full_name=form.user.data, session=session) # Construct Production Order prod_order = order.ProductionOrder(sno=sno) prod_order.create( title=form.prod_order_title.data.strip(), desc=form.desc.data.strip(), cards=cards, deltas=deltas, sourcing_order_snos=None, root_order_snos=form.root_order_sno.data, ordered_by=requested_by, ) # Check for Authorization # Nothing right now. # Create Order # TODO detach at this point fe_workspace_path = os.path.join(TEMPDIR, 'frontend') if not os.path.exists(fe_workspace_path): os.makedirs(fe_workspace_path) workspace_path = os.path.join(fe_workspace_path, get_tempname()) os.makedirs(workspace_path) prod_order.process(outfolder=workspace_path, register=True, session=session) shutil.rmtree(workspace_path) # Redirect to Created Order return redirect(url_for('.production_orders', order_sno=str(sno))) except AuthChainNotValidError: stage['auth_not_valid'] = True stage_crumbs = {'breadcrumbs': [Crumb(name="Production", path=""), Crumb(name="Orders", path="order/"), Crumb(name="New", path="order/new")], } stage.update(stage_crumbs) pagetitle = "Create New Production Order" return render_template('production_order_new.html', stage=stage, form=form, pagetitle=pagetitle)
def new_production_order(): form = CreateProductionOrderForm() stage = {'crumbroot': '/production'} if form.validate_on_submit(): try: sno = form.prod_order_sno.sno.data with get_session() as session: title = form.prod_order_title.data.strip() if not sno: sno = get_serialno(series='PROD', efield=title, register=True, session=session) else: # additional sno validation? pass cards = { x['ident']: int(x['qty']) for x in form.modules.data if x['ident'] } deltas = [{ 'orig-cardname': x['orig_cardname'], 'target-cardname': x['target_cardname'], 'sno': x['sno'] } for x in form.deltas.data if x['sno']] requested_by = get_username_from_full_name( full_name=form.user.data, session=session) # Construct Production Order prod_order = order.ProductionOrder(sno=sno) prod_order.create( title=form.prod_order_title.data.strip(), desc=form.desc.data.strip(), cards=cards, deltas=deltas, sourcing_order_snos=None, root_order_snos=form.root_order_sno.data, ordered_by=requested_by, ) # Check for Authorization # Nothing right now. # Create Order # TODO detach at this point fe_workspace_path = os.path.join(TEMPDIR, 'frontend') if not os.path.exists(fe_workspace_path): os.makedirs(fe_workspace_path) workspace_path = os.path.join(fe_workspace_path, get_tempname()) os.makedirs(workspace_path) prod_order.process(outfolder=workspace_path, register=True, session=session) shutil.rmtree(workspace_path) # Redirect to Created Order return redirect(url_for('.production_orders', order_sno=str(sno))) except AuthChainNotValidError: stage['auth_not_valid'] = True stage_crumbs = { 'breadcrumbs': [ Crumb(name="Production", path=""), Crumb(name="Orders", path="order/"), Crumb(name="New", path="order/new") ], } stage.update(stage_crumbs) pagetitle = "Create New Production Order" return render_template('production_order_new.html', stage=stage, form=form, pagetitle=pagetitle)
def new_indent(indent_sno=None): form = CreateIndentForm(parent_indent_sno=indent_sno) stage = {'crumbroot': '/inventory'} if form.validate_on_submit(): try: with get_session() as session: sno = form.indent_sno.sno.data if not sno: if indent_sno is not None: sno = form.get_supplementary_sno_default() register_serialno(sno=sno, efield="WEB FRONTEND INDENT", session=session) else: sno = get_serialno(series='IDT', efield='WEB FRONTEND INDENT', register=True, session=session) else: # additional sno validation? pass nindent = InventoryIndent(sno=sno, session=session) # Construct COBOM obom = create_obom_from_listing(form.components.data, 'MANUAL (WEB)') cobom = CompositeOutputBom([obom], name='MANUAL (WEB) {0}'.format(sno)) requested_by = get_username_from_full_name( full_name=form.user.data, session=session) icparams = { 'cobom': cobom, 'title': form.indent_title.data, 'desc': form.indent_desc.data, 'requested_by': requested_by, 'rdate': form.rdate.data or arrow.utcnow(), 'indent_type': form.indent_type.data, } nindent.create(**icparams) root_order_sno = form.root_order_sno.data prod_order_sno = form.prod_order_sno.data try: nindent.define_auth_chain(prod_order_sno=prod_order_sno, root_order_sno=root_order_sno, session=session) except AuthChainNotValidError: raise nindent.register_auth_chain(session=session) fe_workspace_path = os.path.join(TEMPDIR, 'frontend') if not os.path.exists(fe_workspace_path): os.makedirs(fe_workspace_path) workspace_path = os.path.join(fe_workspace_path, get_tempname()) os.makedirs(workspace_path) nindent.process(outfolder=workspace_path, register=True, session=session) shutil.rmtree(workspace_path) return redirect(url_for('.indent', indent_sno=str(sno))) except AuthChainNotValidError: stage['auth_not_valid'] = True if indent_sno is None: stage_crumbs = { 'breadcrumbs': [ Crumb(name="Inventory", path=""), Crumb(name="Indent", path="indent/"), Crumb(name="New", path="indent/new") ], } pagetitle = "Create New Indent" else: stage_crumbs = { 'breadcrumbs': [ Crumb(name="Inventory", path=""), Crumb(name="Indent", path="indent/"), Crumb(name=indent_sno, path="indent/" + indent_sno), Crumb(name="New", path='/'.join(["indent", indent_sno, "/new"])), ] } pagetitle = "New Supplementary Indent for " + indent_sno stage.update(stage_crumbs) return render_template('indent_new.html', stage=stage, form=form, pagetitle=pagetitle)
def new_indent(indent_sno=None): form = CreateIndentForm(parent_indent_sno=indent_sno) stage = {'crumbroot': '/inventory'} if form.validate_on_submit(): try: with get_session() as session: sno = form.indent_sno.sno.data if not sno: if indent_sno is not None: sno = form.get_supplementary_sno_default() register_serialno(sno=sno, efield="WEB FRONTEND INDENT", session=session) else: sno = get_serialno(series='IDT', efield='WEB FRONTEND INDENT', register=True, session=session) else: # additional sno validation? pass nindent = InventoryIndent(sno=sno, session=session) # Construct COBOM obom = create_obom_from_listing(form.components.data, 'MANUAL (WEB)') cobom = CompositeOutputBom([obom], name='MANUAL (WEB) {0}'.format(sno)) requested_by = get_username_from_full_name(full_name=form.user.data, session=session) icparams = { 'cobom': cobom, 'title': form.indent_title.data, 'desc': form.indent_desc.data, 'requested_by': requested_by, 'rdate': form.rdate.data or arrow.utcnow(), 'indent_type': form.indent_type.data, } nindent.create(**icparams) root_order_sno = form.root_order_sno.data prod_order_sno = form.prod_order_sno.data try: nindent.define_auth_chain(prod_order_sno=prod_order_sno, root_order_sno=root_order_sno, session=session) except AuthChainNotValidError: raise nindent.register_auth_chain(session=session) fe_workspace_path = os.path.join(TEMPDIR, 'frontend') if not os.path.exists(fe_workspace_path): os.makedirs(fe_workspace_path) workspace_path = os.path.join(fe_workspace_path, get_tempname()) os.makedirs(workspace_path) nindent.process(outfolder=workspace_path, register=True, session=session) shutil.rmtree(workspace_path) return redirect(url_for('.indent', indent_sno=str(sno))) except AuthChainNotValidError: stage['auth_not_valid'] = True if indent_sno is None: stage_crumbs = {'breadcrumbs': [Crumb(name="Inventory", path=""), Crumb(name="Indent", path="indent/"), Crumb(name="New", path="indent/new")], } pagetitle = "Create New Indent" else: stage_crumbs = {'breadcrumbs': [Crumb(name="Inventory", path=""), Crumb(name="Indent", path="indent/"), Crumb(name=indent_sno, path="indent/" + indent_sno), Crumb(name="New", path='/'.join(["indent", indent_sno, "/new"])), ] } pagetitle = "New Supplementary Indent for " + indent_sno stage.update(stage_crumbs) return render_template('indent_new.html', stage=stage, form=form, pagetitle=pagetitle)