def save_call(self, destination, customer, route, status, price_customer): end = datetime.datetime.fromtimestamp(int( status['end'])).strftime('%Y-%m-%d %H:%M:%S') cost = 0 price = 0 if status['answeredtime'] > 0: cost = status['answeredtime'] * route.Rate.price / 60 price = status['answeredtime'] * price_customer / 60 self.update_provider_balance(route.Provider, cost) self.update_customer_credit(customer, price) call = model.Call(destination=destination, admin_id=customer.admin_id, at=end, duration=status['answeredtime'], dialstatus=status['dialstatus'], price_customer_id=customer.price_customer_id, provider_id=route.Provider.id, route_id=route.Route.id, customer_id=customer.id, ip=status['ip'], hangupcause=status['hangupcause'], price_for_customer=price, cost=cost) session.add(call) session.commit()
def build(): call_model = model.Call() call_model.call_id = 555 call_model.start_timestamp = datetime.datetime( 1984, 2, 18, 20, 5, 44) call_model.origin_phone = '9990909090' call_model.destination_phone = '99900900909' call_model.end_timestamp = datetime.datetime(1984, 2, 18, 20, 8, 2) return call_model
def register_call(self, call_record): """ Register call from record. Search for existing call_id and update if found. Add the current fare for new calls :param call_record: :return: Call """ call_model = self.db.query( model.Call).filter_by(call_id=call_record['call_id']).first() if not call_model: call_model = model.Call() call_model.fare = self.load_current_fare() call_model.load_from_record(call_record) self.db.add(call_model) return call_model
def test_should_load_start_timestamp_when_type_is_start(start_call): call_model = model.Call() call_model.load_from_record(start_call) assert call_model.start_timestamp == start_call['timestamp']
def test_should_load_end_timestamp_when_type_is_end(end_call): call_model = model.Call() call_model.load_from_record(end_call) assert call_model.end_timestamp == end_call['timestamp']