def assets_asset_save(request): _id = request.POST.get('id') assets_type = request.POST.get('assets_type') comment = request.POST.get('comment') assets_code = request.POST.get('assets_code') name = request.POST.get('name') if _id =='': orm = asset(name=name,assets_type=assets_type,assets_code=assets_code,comment=comment) comment_info = u'%s %s %s 入库' % (name,assets_type,assets_code) orm_log = log(comment=comment_info) else: orm = asset.objects.get(id=int(_id)) orm.name = name orm.assets_type = assets_type orm.assets_code = assets_code orm.comment = comment comment_info = u'%s %s %s 编辑' % (name,assets_type,assets_code) orm_log = log(comment=comment_info) try: orm_log.save() orm.save() return HttpResponse(json.dumps({'code':0,'msg':u'保存成功'}),content_type="application/json") except Exception,e: logger.error(e,comment) return HttpResponse(json.dumps({'code':1,'msg':str(e)}),content_type="application/json")
def assets_user_save(request): _id = request.POST.get('id') department = request.POST.get('department') comment = request.POST.get('comment') assets = request.POST.get('asset') name = request.POST.get('name') assets_data = '' try: if _id =='': for i in assets.split(','): orm_assets = asset.objects.get(id=i) orm_assets.status = '已发放' orm_assets.save() comment_info = u'%s %s %s 出库,发放给<%s>' % (orm_assets.name,orm_assets.assets_type,orm_assets.assets_code,name) orm_log = log(comment=comment_info) orm_log.save() if assets_data == '': assets_data = '< %s %s %s >' % (orm_assets.name,orm_assets.assets_type,orm_assets.assets_code) else: assets_data = '%s< %s %s %s >' % (assets_data,orm_assets.name,orm_assets.assets_type,orm_assets.assets_code) orm_user = user(name=name,department=department,assets=assets_data,comment=comment,assets_id=assets) orm_user.save() else: orm = user.objects.get(id=_id) for i in orm.assets_id.split(','): if not i in assets.split(','): orm_assets = asset.objects.get(id=i) orm_assets.status = '未发放' orm_assets.save() comment_info = u'%s %s %s 入库库,从<%s>处收回' % (orm_assets.name,orm_assets.assets_type,orm_assets.assets_code,name) orm_log = log(comment=comment_info) orm_log.save() for i in assets.split(','): if not i in orm.assets_id.split(','): orm_assets = asset.objects.get(id=i) orm_assets.status = '已发放' orm_assets.save() comment_info = u'%s %s %s 出库,发放给<%s>' % (orm_assets.name,orm_assets.assets_type,orm_assets.assets_code,name) orm_log = log(comment=comment_info) orm_log.save() if assets_data == '': assets_data = '< %s %s %s >' % (orm_assets.name,orm_assets.assets_type,orm_assets.assets_code) else: assets_data = '%s< %s %s %s >' % (assets_data,orm_assets.name,orm_assets.assets_type,orm_assets.assets_code) orm.name = name orm.department = department orm.assets = assets_data orm.comment = comment orm.assets_id = assets orm.save() return HttpResponse(json.dumps({'code':0,'msg':u'保存成功'}),content_type="application/json") except Exception,e: logger.error(e,comment) return HttpResponse(json.dumps({'code':1,'msg':str(e)}),content_type="application/json")
def assets_asset_del(request): _id = request.POST.get('id') orm = asset.objects.get(id=_id) if orm.status == u'已发放': return HttpResponse(json.dumps({'code':2,'msg':u'该物品已被发放,请收回后再删除'}),content_type="application/json") else: comment_info = u'%s %s %s 出库' % (orm.name,orm.assets_type,orm.assets_code) orm_log = log(comment=comment_info) try: orm_log.save() orm.delete() return HttpResponse(json.dumps({'code':0,'msg':u'删除成功'}),content_type="application/json") except Exception,e: return HttpResponse(json.dumps({'code':1,'msg':str(e)}),content_type="application/json")
def assets_user_del(request): _id = request.POST.get('id') try: orm = user.objects.get(id=_id) for i in orm.assets_id.split(','): orm_assets = asset.objects.get(id=i) orm_assets.status = "未发放" orm_assets.save() comment_info = u'%s %s %s 入库,从<%s>处收回' % (orm_assets.name,orm_assets.assets_type,orm_assets.assets_code,orm.name) orm_log = log(comment=comment_info) orm_log.save() orm.delete() return HttpResponse(json.dumps({'code':0,'msg':u'删除成功'}),content_type="application/json") except Exception,e: return HttpResponse(json.dumps({'code':0,'msg':e}),content_type="application/json")
def assets_table_save(request): # FANO = request.POST.get('FANO') _description = request.POST.get('description') _model = request.POST.get('model') _category = request.POST.get('category') _department = request.POST.get('department') employee = request.POST.get('employee') purchase_date = request.POST.get('purchase_date') payment = request.POST.get('payment') cost = request.POST.get('cost') comment = request.POST.get('comment') count = request.POST.get('count') _id = request.POST.get('id') try: if not count: count = 1 for c in range(int(count)): if not _id: residual_value = round(float(cost) * 0.05, 2) depreciation = round((float(cost) - residual_value) / category[str(_category)][0], 2) fetch_end_num = table.objects.filter(FANO__contains=category[str(_category)][1]) if fetch_end_num: num_list = [] for i in fetch_end_num: num_re = re.search(r'\d+',i.FANO) num_list.append(int(num_re.group())) num = max(num_list) + 1 num = (3 - len(str(num))) * '0' + str(num) FANO = category[str(_category)][1] + num else: FANO = category[str(_category)][1] + "001" if not _department: _department = '' if not employee: employee = '' orm = table(FANO=FANO,description=_description,model=_model,category=_category,department=_department, employee=employee,purchase_date=purchase_date,payment=payment,cost=cost,residual_life=category[str(_category)][0], residual_value=residual_value,depreciation=depreciation,total_depreciation=0, netbook_value=float(cost),comment=comment) orm.save() if employee: comment_info = '<b>%s</b> | %s | %s    分配给了 <b>%s</b>' % (FANO,_description,_model,employee) log_orm = log(comment=comment_info) log_orm.save() else: if employee == None: employee = '' if _department == None: _department = '' orm = table.objects.get(id=_id) if employee != orm.employee: if employee: comment_info = '<b>%s</b> | %s | %s    分配给了 <b>%s</b>' % (orm.FANO,_description,_model,employee) log_orm = log(comment=comment_info) else: comment_info = '<b>%s</b> | %s | %s    从 <b>%s</b> 被回收了 ' % (orm.FANO,_description,_model,orm.employee) log_orm = log(comment=comment_info) log_orm.save() orm.department = _department orm.employee = employee orm.comment = comment orm.save() return HttpResponse(simplejson.dumps({'code':0,'msg':u'保存成功'}),content_type="application/json") except Exception,e: print e return HttpResponse(simplejson.dumps({'code':1,'msg':str(e)}),content_type="application/json")