def save(self, person=None,cost=None,docs=None,commit=True): # create purchase reques purchase_instance = PurchaseRequest(person=person,quantity=self.cleaned_data['quantity'],cost=cost) purchase_instance.save() # add document if possible if docs != None: purchase_instance.docs.add(docs) # get purchase item item = self.cleaned_data['item'] #ItemTemplate.objects.get(id=self.cleaned_data['item']) # create asset_group asset_g_instance = assetgroup(name='Purchase_'+str(purchase_instance.id)) asset_g_instance.save() # need to save first to add many-to-many # create asets and asset group for i in range(0,self.cleaned_data['quantity']): FSIN = '%s_%s' % (str(purchase_instance.id).zfill(5), str(i).zfill(5)) asset_instance = asset(item=item,FSIN=FSIN) asset_instance.save() asset_g_instance.assets.add(asset_instance) asset_g_instance.save() return asset_g_instance
def Commit_vending_fullfill(purchaserequest): # create group first groupname = purchaserequest.__unicode__() assetgroupinst = assetgroup(name=groupname) assetgroupinst.save() # create asset and add to group for j in range(0,purchaserequest.quantity): FSIN = str(purchaserequest.id).zfill(6)+str(j).zfill(6) assetinst = asset(item=purchaserequest.item,FSIN=FSIN) assetinst.save() # add default storage assetstorageinst = assetstorage(item=assetinst,location=purchaserequest.storage) assetstorageinst.save() # add asset to purchase asset group assetgroupinst.assets.add(assetinst) purchaserequest.assets.add(assetinst) # change fullfill status purchaserequest.fullfilled = True purchaserequest.save()
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")