def test_routing_slip_find_search(session): """Assert a routing slip is stored. Start with a blank database. """ payment_account = factory_payment_account() payment_account.save() rs = factory_routing_slip(number=fake.name(), payment_account_id=payment_account.id) rs.save() for i in range(20): factory_routing_slip(number=fake.name(), payment_account_id=payment_account.id).save() routing_slip = RoutingSlip() search_dict = {'routingSlipNumber': rs.number} res, count = routing_slip.search(search_dict, page=1, limit=1, return_all=True) assert count == 1 assert len(res) == 1, 'searched with routing slip.so only one record' res, count = routing_slip.search({}, page=1, limit=1, return_all=True) assert count == 21 assert len(res) == 21, 'retun all true ;so shud return all records' res, count = routing_slip.search({}, page=1, limit=1, return_all=False) assert count == 1 assert len(res) == 1, 'return all false'
def search(cls, search_filter: Dict, page: int, limit: int, return_all: bool = False): """Search for routing slip.""" routing_slips, total = RoutingSlipModel.search(search_filter, page, limit, return_all) data = { 'total': total, 'page': page, 'limit': limit, # We need these fields, to populate the UI. 'items': RoutingSlipSchema(only=('number', 'payments.receipt_number', 'payment_account.name', 'created_name', 'routing_slip_date', 'status', 'invoices.business_identifier', 'payments.cheque_receipt_number', 'remaining_amount', 'total', 'invoices.corp_type_code', 'payments.payment_method_code', 'payments.payment_status_code', 'payment_account.payment_method' ) ).dump(routing_slips, many=True) } return data
def create_daily_reports(cls, date: str, **kwargs): """Create and return daily report for the day provided.""" routing_slips: List[RoutingSlipModel] = RoutingSlipModel.search( dict( dateFilter=dict( endDate=date, startDate=date, target='created_on' ) ), page=1, limit=0, return_all=True )[0] total: float = 0 no_of_cash: int = 0 no_of_cheque: int = 0 total_cash_usd: float = 0 total_cheque_usd: float = 0 total_cash_cad: float = 0 total_cheque_cad: float = 0 # TODO Only CAD supported now, so just add up the total. for routing_slip in routing_slips: total += float(routing_slip.total) if routing_slip.payment_account.payment_method == PaymentMethod.CASH.value: no_of_cash += 1 # TODO check if the payment is CAD or USD. total_cash_cad += float(routing_slip.total) if routing_slip.total_usd is not None: total_cash_usd += float(routing_slip.total_usd) else: no_of_cheque += 1 total_cheque_cad += float(routing_slip.total) if routing_slip.total_usd is not None: total_cheque_usd += float(routing_slip.total_usd) report_dict = dict( templateName='routing_slip_report', reportName=f'Routing-Slip-Daily-Report-{date}', templateVars=dict( day=date, reportDay=str(get_local_time(datetime.now())), total=total, numberOfCashReceipts=no_of_cash, numberOfChequeReceipts=no_of_cheque, totalCashInUsd=total_cash_usd, totalChequeInUsd=total_cheque_usd, totalCashInCad=total_cash_cad, totalChequeInCad=total_cheque_cad ) ) pdf_response = OAuthService.post(current_app.config.get('REPORT_API_BASE_URL'), kwargs['user'].bearer_token, AuthHeaderType.BEARER, ContentType.JSON, report_dict) return pdf_response, report_dict.get('reportName')