Exemple #1
0
    def add_booking_code(self, user, business_id, start, end, user_with):
        if user_with:
            # Make sure they are allowed to propose to this user
            if not business.user_owns_business(user.user_id(), business_id):
                return {"error": "not your business bro"}
            user_with = CoUser.get(user_with)
            if not user_with:
                return {"error":"that guy does not exist"}

            interaction = InteractionRecord.gql("WHERE business_id = :1 AND user = :2", business_id, user_with).get()

            if not interaction:
                return {"error":"You have no reason to talk to that user"}
            user = user_with
            contractor = True
            client = False
        else:
            contractor = False
            client = True
            need_to_create_this = InteractionRecord.guaranteed_get(business_id, user)

        new_booking = Booking(
            user = user,
            business_id = business_id,
            start_time = start,
            end_time = end,
            approved_by_customer = client,
            approved_by_contractor = contractor
        )
        new_booking.put()

        send_emails.booking_created(user, business_id, start, end, user_with)

        return new_booking