def filter_production_model(production_id): """ 产品型号 :param production_id: :return: """ production_info = get_production_row_by_id(production_id) return production_info.production_model if production_info else '-'
def filter_production_cost_avg(production_id): """ 平均成本 :param production_id: :return: """ production_info = get_production_row_by_id(production_id) return production_info.cost_avg if production_info else '0.00'
def filter_production_brand(production_id): """ 产品品牌 :param production_id: :return: """ production_info = get_production_row_by_id(production_id) return production_info.production_brand if production_info else '-'
def info(production_id): """ 产品详情 :param production_id: :return: """ # 详情数据 production_info = get_production_row_by_id(production_id) # 检查资源是否存在 if not production_info: abort(404) # 检查资源是否删除 if production_info.status_delete == STATUS_DEL_OK: abort(410) # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('production info') # 渲染模板 return render_template('production/info.html', production_info=production_info, **document_info)
def ajax_info(): """ 获取产品详情 :return: """ ajax_success_msg = AJAX_SUCCESS_MSG.copy() ajax_failure_msg = AJAX_FAILURE_MSG.copy() # 检查请求方法 if not (request.method == 'GET' and request.is_xhr): ext_msg = _('Method Not Allowed') ajax_failure_msg['msg'] = _('Get Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) # 检查请求参数 production_id = request.args.get('production_id', 0, type=int) if not production_id: ext_msg = _('ID does not exist') ajax_failure_msg['msg'] = _('Get Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) production_info = get_production_row_by_id(production_id) # 检查资源是否存在 if not production_info: ext_msg = _('ID does not exist') ajax_failure_msg['msg'] = _('Get Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) # 检查资源是否删除 if production_info.status_delete == STATUS_DEL_OK: ext_msg = _('Already deleted') ajax_failure_msg['msg'] = _('Get Failure, %(ext_msg)s', ext_msg=ext_msg) return jsonify(ajax_failure_msg) ajax_success_msg['msg'] = _('Get Success') ajax_success_msg['data'] = production_info.to_dict() return jsonify(ajax_success_msg)
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)
def ajax_delete(): """ 产品删除 :return: """ ajax_success_msg = AJAX_SUCCESS_MSG.copy() ajax_failure_msg = AJAX_FAILURE_MSG.copy() # 检查删除权限 if not permission_production_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) # 检查请求参数 production_id = request.args.get('production_id', 0, type=int) if not production_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) production_info = get_production_row_by_id(production_id) # 检查资源是否存在 if not production_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 production_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_quotation_items(**{ 'production_id': production_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_production_sensitive(**{ 'production_id': production_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() production_data = { 'status_delete': STATUS_DEL_OK, 'delete_time': current_time, 'update_time': current_time, } result = edit_production(production_id, production_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(production_id): """ 产品编辑 """ production_info = get_production_row_by_id(production_id) # 检查资源是否存在 if not production_info: abort(404) # 检查资源是否删除 if production_info.status_delete == STATUS_DEL_OK: abort(410) template_name = 'production/edit.html' # 加载编辑表单 form = ProductionEditForm(request.form) # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('production edit') # 进入编辑页面 if request.method == 'GET': # 表单赋值 form.id.data = production_info.id form.production_brand.data = production_info.production_brand form.production_model.data = production_info.production_model form.production_sku.data = production_info.production_sku form.ind.data = production_info.ind form.oud.data = production_info.oud form.wid.data = production_info.wid form.cost_ref.data = production_info.cost_ref form.cost_new.data = production_info.cost_new form.cost_avg.data = production_info.cost_avg form.note.data = production_info.note form.create_time.data = production_info.create_time form.update_time.data = production_info.update_time # 渲染页面 return render_template(template_name, production_id=production_id, form=form, **document_info) # 处理编辑请求 if request.method == 'POST': # 表单校验失败 if production_id != form.id.data or not form.validate_on_submit(): flash(_('Edit Failure'), 'danger') return render_template(template_name, production_id=production_id, form=form, **document_info) # 表单校验成功 current_time = datetime.utcnow() production_data = { 'production_brand': form.production_brand.data.upper(), 'production_model': form.production_model.data.upper(), 'production_sku': form.production_sku.data, 'ind': form.ind.data, 'oud': form.oud.data, 'wid': form.wid.data, 'cost_ref': form.cost_ref.data, 'cost_new': form.cost_new.data, 'cost_avg': form.cost_avg.data, 'note': form.note.data, 'update_time': current_time, } result = edit_production(production_id, production_data) # 编辑操作成功 if result: flash(_('Edit Success'), 'success') return redirect( request.args.get('next') or url_for('production.lists')) # 编辑操作失败 else: flash(_('Edit Failure'), 'danger') return render_template(template_name, production_id=production_id, form=form, **document_info)