def filter_warehouse_name(warehouse_id): """ 仓库名称 :param warehouse_id: :return: """ warehouse_info = get_warehouse_row_by_id(warehouse_id) return warehouse_info.name if warehouse_info else '-'
def info(warehouse_id): """ 仓库详情 :param warehouse_id: :return: """ # 详情数据 warehouse_info = get_warehouse_row_by_id(warehouse_id) # 检查资源是否存在 if not warehouse_info: abort(404) # 检查资源是否删除 if warehouse_info.status_delete == STATUS_DEL_OK: abort(410) # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('warehouse info') # 渲染模板 return render_template('warehouse/info.html', warehouse_info=warehouse_info, **document_info)
def ajax_delete(): """ 仓库删除 :return: """ ajax_success_msg = AJAX_SUCCESS_MSG.copy() ajax_failure_msg = AJAX_FAILURE_MSG.copy() # 检查删除权限 if not permission_warehouse_section_del.can(): ext_msg = _('Permission Denied') ajax_failure_msg['msg'] = _('Del Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) # 检查请求方法 if not (request.method == 'GET' and request.is_xhr): ext_msg = _('Method Not Allowed') ajax_failure_msg['msg'] = _('Del Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) # 检查请求参数 warehouse_id = request.args.get('warehouse_id', 0, type=int) if not warehouse_id: ext_msg = _('ID does not exist') ajax_failure_msg['msg'] = _('Del Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) warehouse_info = get_warehouse_row_by_id(warehouse_id) # 检查资源是否存在 if not warehouse_info: ext_msg = _('ID does not exist') ajax_failure_msg['msg'] = _('Del Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) # 检查资源是否删除 if warehouse_info.status_delete == STATUS_DEL_OK: ext_msg = _('Already deleted') ajax_failure_msg['msg'] = _('Del Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) # 检查是否正在使用 # 库存、货架 if count_inventory(**{ 'warehouse_id': warehouse_id, 'status_delete': STATUS_DEL_NO }): ext_msg = _('Currently In Use') ajax_failure_msg['msg'] = _('Del Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) if count_rack(**{ 'warehouse_id': warehouse_id, 'status_delete': STATUS_DEL_NO }): ext_msg = _('Currently In Use') ajax_failure_msg['msg'] = _('Del Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) current_time = datetime.utcnow() warehouse_data = { 'status_delete': STATUS_DEL_OK, 'delete_time': current_time, 'update_time': current_time, } result = edit_warehouse(warehouse_id, warehouse_data) if result: ajax_success_msg['msg'] = _('Del Success') return jsonify(ajax_success_msg) else: ajax_failure_msg['msg'] = _('Del Failure') return jsonify(ajax_failure_msg)
def edit(warehouse_id): """ 仓库编辑 """ warehouse_info = get_warehouse_row_by_id(warehouse_id) # 检查资源是否存在 if not warehouse_info: abort(404) # 检查资源是否删除 if warehouse_info.status_delete == STATUS_DEL_OK: abort(410) template_name = 'warehouse/edit.html' # 加载编辑表单 form = WarehouseEditForm(request.form) # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('warehouse edit') # 进入编辑页面 if request.method == 'GET': # 表单赋值 form.name.data = warehouse_info.name form.address.data = warehouse_info.address form.linkman.data = warehouse_info.linkman form.tel.data = warehouse_info.tel form.fax.data = warehouse_info.fax # form.create_time.data = warehouse_info.create_time # form.update_time.data = warehouse_info.update_time # 渲染页面 return render_template(template_name, warehouse_id=warehouse_id, form=form, **document_info) # 处理编辑请求 if request.method == 'POST': # 表单校验失败 if not form.validate_on_submit(): flash(_('Edit Failure'), 'danger') return render_template(template_name, warehouse_id=warehouse_id, form=form, **document_info) # 表单校验成功 current_time = datetime.utcnow() warehouse_data = { 'name': form.name.data, 'address': form.address.data, 'linkman': form.linkman.data, 'tel': form.tel.data, 'fax': form.fax.data, 'update_time': current_time, } result = edit_warehouse(warehouse_id, warehouse_data) # 编辑操作成功 if result: flash(_('Edit Success'), 'success') return redirect( request.args.get('next') or url_for('warehouse.lists')) # 编辑操作失败 else: flash(_('Edit Failure'), 'danger') return render_template(template_name, warehouse_id=warehouse_id, form=form, **document_info)
def edit(inventory_id): """ 库存编辑 """ inventory_info = get_inventory_row_by_id(inventory_id) # type: Inventory # 检查资源是否存在 if not inventory_info: abort(404) # 检查资源是否删除 if inventory_info.status_delete == STATUS_DEL_OK: abort(410) template_name = 'inventory/edit.html' # 加载编辑表单 form = InventoryEditForm(request.form) form.warehouse_id.choices = get_warehouse_choices(option_type='update') form.rack_id.choices = get_rack_choices(form.warehouse_id.data or inventory_info.warehouse_id, option_type='update') # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('inventory edit') # 进入编辑页面 if request.method == 'GET': # 表单赋值 form.production_id.data = inventory_info.production_id form.production_brand.data = inventory_info.production_brand form.production_model.data = inventory_info.production_model form.production_sku.data = inventory_info.production_sku form.warehouse_id.data = inventory_info.warehouse_id form.rack_id.data = inventory_info.rack_id form.stock_qty.data = inventory_info.stock_qty_current form.note.data = inventory_info.note # 渲染页面 return render_template(template_name, inventory_id=inventory_id, form=form, **document_info) # 处理编辑请求 if request.method == 'POST': # 修改仓库 - 不做校验 if form.warehouse_changed.data: form.warehouse_changed.data = '' return render_template(template_name, form=form, **document_info) # 表单校验失败 if not form.validate_on_submit(): flash(_('Edit Failure'), 'danger') return render_template(template_name, inventory_id=inventory_id, form=form, **document_info) # 表单校验成功 current_time = datetime.utcnow() # 获取产品信息 production_info = get_production_row_by_id(form.production_id.data) if not production_info: abort(404, exceptions.NotFound(description='production')) # 获取仓库信息 warehouse_info = get_warehouse_row_by_id(form.warehouse_id.data) if not warehouse_info: abort(404, exceptions.NotFound(description='warehouse')) # 获取货架信息 rack_info = get_rack_row_by_id(form.rack_id.data) if not rack_info: abort(404, exceptions.NotFound(description='rack')) inventory_data = { 'production_id': form.production_id.data, 'production_brand': production_info.production_brand, 'production_model': production_info.production_model, 'production_sku': production_info.production_sku, 'warehouse_id': form.warehouse_id.data, 'warehouse_name': warehouse_info.name, 'rack_id': form.rack_id.data, 'rack_name': rack_info.name, 'stock_qty_current': form.stock_qty.data, 'note': form.note.data, 'create_time': current_time, 'update_time': current_time, } result = edit_inventory(inventory_id, inventory_data) # 编辑操作成功 if result: flash(_('Edit Success'), 'success') return redirect( request.args.get('next') or url_for('inventory.lists')) # 编辑操作失败 else: flash(_('Edit Failure'), 'danger') return render_template(template_name, inventory_id=inventory_id, form=form, **document_info)
def add(): """ 创建库存 :return: """ template_name = 'inventory/add.html' # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('inventory add') # 加载创建表单 form = InventoryAddForm(request.form) form.warehouse_id.choices = get_warehouse_choices(option_type='update') form.rack_id.choices = get_rack_choices(form.warehouse_id.data, option_type='update') # 进入创建页面 if request.method == 'GET': # 渲染页面 return render_template(template_name, form=form, **document_info) # 处理创建请求 if request.method == 'POST': # 修改仓库 - 不做校验 if form.warehouse_changed.data: form.warehouse_changed.data = '' return render_template(template_name, form=form, **document_info) # 表单校验失败 if not form.validate_on_submit(): flash(_('Add Failure'), 'danger') return render_template(template_name, form=form, **document_info) # 表单校验成功 current_time = datetime.utcnow() # 获取产品信息 production_info = get_production_row_by_id(form.production_id.data) if not production_info: abort(404, exceptions.NotFound(description='production')) # 获取仓库信息 warehouse_info = get_warehouse_row_by_id(form.warehouse_id.data) if not warehouse_info: abort(404, exceptions.NotFound(description='warehouse')) # 获取货架信息 rack_info = get_rack_row_by_id(form.rack_id.data) if not rack_info: abort(404, exceptions.NotFound(description='rack')) inventory_data = { 'production_id': form.production_id.data, 'production_brand': production_info.production_brand, 'production_model': production_info.production_model, 'production_sku': production_info.production_sku, 'warehouse_id': form.warehouse_id.data, 'warehouse_name': warehouse_info.name, 'rack_id': form.rack_id.data, 'rack_name': rack_info.name, 'stock_qty_current': form.stock_qty.data, 'note': form.note.data, 'create_time': current_time, 'update_time': current_time, } result = add_inventory(inventory_data) # 创建操作成功 if result: flash(_('Add Success'), 'success') return redirect( request.args.get('next') or url_for('inventory.lists')) # 创建操作失败 else: flash(_('Add Failure'), 'danger') return render_template(template_name, form=form, **document_info)