def add(cls, salesList): if not isinstance(salesList, SalesList): raise TypeError( 'The parameter salesList is not instance of the SalesList instance' ) session = DBSession() session.add(salesList) session.flush() new_item_id = salesList.id # 销售单入库时,更新最新余额 if salesList.isStoraged == SalesListDBUtils.IS_STORAGED_YES: latestCustomPaymentInfo = session.query( CustomPaymentInfo).order_by(desc(CustomPaymentInfo.payTime), desc(CustomPaymentInfo.id)).filter( CustomPaymentInfo.customName == salesList.customName).first() if latestCustomPaymentInfo: latestCustomPaymentInfo.balance = DataUtils.strNumToDeciaml( latestCustomPaymentInfo. balance) - DataUtils.countSaleListPrice( salesList.count, salesList.unitPrice) session.commit() session.close() return new_item_id
def getTotalOfWastage(cls, queryAll): allWastage = [] for item in queryAll: wastagee_json = json.dumps(object2dict(item), cls=DateEncoder) wastage = json.loads(wastagee_json) total = DataUtils.strNumToDeciaml(wastage.get("wastageCount")) allWastage.append(total) return sum(allWastage)
def getTotalOfPurchase(cls, queryAll): allPurchase = [] for item in queryAll: materialPurchase_json = json.dumps(object2dict(item), cls=DateEncoder) materialPurchase = json.loads(materialPurchase_json) total = DataUtils.strNumToDeciaml(materialPurchase.get("count")) allPurchase.append(total) return sum(allPurchase)
def getTotalOfAllSalelist(cls, queryAll): allSaleListTotal = [] for item in queryAll: salesList_json = json.dumps(object2dict(item), cls=DateEncoder) salesList = json.loads(salesList_json) total = DataUtils.countSaleListPrice(salesList.get("count"), salesList.get("unitPrice")) allSaleListTotal.append(total) return sum(allSaleListTotal)
def getTotalOfPayAmount(cls, queryAll): allCustomPaymentInfo = [] for item in queryAll: customPaymentInfo_json = json.dumps(object2dict(item), cls=DateEncoder) customPaymentInfo = json.loads(customPaymentInfo_json) total = DataUtils.strNumToDeciaml( customPaymentInfo.get("payAmount")) allCustomPaymentInfo.append(total) return sum(allCustomPaymentInfo)
def update(cls, updateId, salesList): if not isinstance(salesList, SalesList): raise TypeError( 'The parameter salesList is not instance of the CustomerManage instance' ) session = DBSession() item_to_update = session.query(SalesList).filter_by( id=updateId).first() item_to_update.salesListID = salesList.salesListID item_to_update.customName = salesList.customName item_to_update.customID = salesList.customID item_to_update.purchaseID = salesList.purchaseID item_to_update.category = salesList.category item_to_update.tractorID = salesList.tractorID item_to_update.trailerID = salesList.trailerID item_to_update.driverName = salesList.driverName item_to_update.supercargo = salesList.supercargo item_to_update.count = salesList.count item_to_update.unitPrice = salesList.unitPrice item_to_update.mileage = salesList.mileage item_to_update.orderDate = salesList.orderDate item_to_update.storageDate = salesList.storageDate item_to_update.comment = salesList.comment item_to_update.isInvoiced = salesList.isInvoiced item_to_update.isStoraged = salesList.isStoraged # 销售单入库时,更新最新余额 if salesList.isStoraged == SalesListDBUtils.IS_STORAGED_YES: latestCustomPaymentInfo = session.query( CustomPaymentInfo).order_by(desc(CustomPaymentInfo.payTime), desc(CustomPaymentInfo.id)).filter( CustomPaymentInfo.customName == salesList.customName).first() if latestCustomPaymentInfo: latestCustomPaymentInfo.balance = DataUtils.strNumToDeciaml( latestCustomPaymentInfo. balance) - DataUtils.countSaleListPrice( salesList.count, salesList.unitPrice) session.commit() session.close()
def computeWastageRatio(cls, allWastage, allPurchase): wastageTotal = DataUtils.strNumToDeciaml(allWastage) purchaseTotal = DataUtils.strNumToDeciaml(allPurchase) ratio = wastageTotal / purchaseTotal return format(DataUtils.switchToPercent(ratio), '.2%')