def cash_flow(n): """ Get cash flow. """ # Create dict for last 'n' months list = list_monthly(n) # Get min date to query filter date = datetime.datetime.now() - dateutil.relativedelta.relativedelta( months=n) # Get purchases query queryPurchases = purchasesModel.get_query_purchase() # Get purchases by date filter purchases = queryPurchases.filter( purchasesModel.PurchaseModel.purchase_date > date).fetch(projection=[ purchasesModel.PurchaseModel.total_cost, purchasesModel.PurchaseModel.payment_date ]) # Group by period for purchase in purchases: for i in list: if same_period(purchase.payment_date, i['period']): i['purchases'] = round(i['purchases'] + purchase.total_cost, 2) # Get sales query salesQuery = salesModel.get_sales_query() # Get sales by date filter sales = salesQuery.filter(salesModel.SaleModel.sale_date > date).fetch( projection=[ salesModel.SaleModel.amount, salesModel.SaleModel.sale_date ]) # Group by period for sale in sales: for i in list: if same_period(sale.sale_date, i['period']): i['sales'] = round(i['sales'] + sale.amount, 2) # Calculate balance and accumulated balance accumulated_balance = 0.0 for month in list: month['balance'] = round(month['sales'] - month['purchases'], 2) accumulated_balance = accumulated_balance + month['balance'] month['accumulated_balance'] = round(accumulated_balance, 2) # return list return list
def cash_flow(n): """ Get cash flow. """ # Create dict for last 'n' months list = list_monthly(n) # Get min date to query filter date = datetime.datetime.now() - dateutil.relativedelta.relativedelta( months=n) # Get purchases query queryPurchases = purchasesModel.get_query_purchase() # Get purchases by date filter purchases = queryPurchases.filter( purchasesModel.PurchaseModel.purchase_date > date).fetch( projection=[purchasesModel.PurchaseModel.total_cost, purchasesModel.PurchaseModel.payment_date]) # Group by period for purchase in purchases: for i in list: if same_period(purchase.payment_date, i['period']): i['purchases'] = round(i['purchases'] + purchase.total_cost, 2) # Get sales query salesQuery = salesModel.get_sales_query() # Get sales by date filter sales = salesQuery.filter( salesModel.SaleModel.sale_date > date).fetch( projection=[salesModel.SaleModel.amount, salesModel.SaleModel.sale_date]) # Group by period for sale in sales: for i in list: if same_period(sale.sale_date, i['period']): i['sales'] = round(i['sales'] + sale.amount, 2) # Calculate balance and accumulated balance accumulated_balance = 0.0 for month in list: month['balance'] = round(month['sales'] - month['purchases'], 2) accumulated_balance = accumulated_balance + month['balance'] month['accumulated_balance'] = round(accumulated_balance, 2) # return list return list
def has_sales_by_product(productKey): """ Check if there is any sale with product key. """ return get_query_purchase().filter( SaleModel.product == productKey).get() is not None
def has_sales_by_product(productKey): """ Check if there is any sale with product key. """ return get_query_purchase().filter(SaleModel.product == productKey).get() is not None