def _unfinished():
        time_delta = datetime.timedelta(hours=12)
        late_to_finish_jobs = []
        late_to_start_jobs = []

        error_free_start_status, start_status = Status.find_status(Keys.STATUS_START)
        error_free_accepted_status, accepted_status = Status.find_status(Keys.STATUS_ACCEPTED_BY_BUSINESS_OWNER)
        if not error_free_start_status:
            return accepted_status

        list_started_jobs = Job.find(status_id=start_status.id)[1]
        list_accepted_jobs = Job.find(100000, status_id=accepted_status.id)[1]

        if list_started_jobs is not []:

            for unfinished_job in list_started_jobs:
                now_time = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
                                                      "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %H:%M:%S")
                if unfinished_job.start_time is not None:
                    real_start_time = unfinished_job.start_time.strftime("%Y-%m-%d %H:%M:%S")
                    start_time_schedule = unfinished_job.start_schedule.strftime("%Y-%m-%d %H:%M:%S")
                    finish_time_schedule = unfinished_job.finish_schedule.strftime("%Y-%m-%d %H:%M:%S")

                    time_length_to_finish_job = datetime.datetime.strptime(finish_time_schedule,
                                                                           '%Y-%m-%d %H:%M:%S') - datetime.datetime.strptime(
                        start_time_schedule, '%Y-%m-%d %H:%M:%S')

                    expected_time_to_finish = datetime.datetime.strptime(real_start_time,
                                                                         '%Y-%m-%d %H:%M:%S') + time_length_to_finish_job

                    if now_time > expected_time_to_finish.strftime("%Y-%m-%d %H:%M:%S"):
                        late_to_finish_jobs.append(unfinished_job.id)
                else:
                    start_time_schedule = unfinished_job.start_schedule.strftime("%Y-%m-%d %H:%M:%S")
                    if start_time_schedule + str(time_delta) > now_time:
                        late_to_finish_jobs.append(unfinished_job.id)

        if list_accepted_jobs is not []:
            for accepted_job in list_accepted_jobs:

                job_limited_time = datetime.datetime.strptime(str(accepted_job.start_schedule + time_delta),
                                                              "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S")
                now_time = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
                                                      "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %H:%M:%S")

                if now_time > job_limited_time:
                    late_to_start_jobs.append(accepted_job.id)

        wanted_list = late_to_start_jobs + late_to_finish_jobs

        error_free, unfinished_jobs = AutoServiceJob.unfinished(wanted_list)
        if not error_free:
            return unfinished_jobs
        return True, SuccessListOfUnfinishedJob(status=200, message=MessagesKeys.SUCCESS_LIST,
                                                params=unfinished_jobs)
Exemple #2
0
 def _load_jobs_in_queue(self):
     error_free, results = Job.load_jobs_by_statuses_for_business_owner(
         self.business_owner, [Keys.STATUS_ACCEPTED_BY_BUSINESS_OWNER])
     if not error_free:
         return results
     return SuccessInQueueJobs(status=200,
                               message=MessagesKeys.SUCCESS_IN_QUEUE_JOBS,
                               params=results)
Exemple #3
0
 def _is_job_finished(job):
     if Job.is_job_finished() == job.status_id:
         return True, job
     else:
         return False, NotFinishedJob(
             status=404,
             message=MessagesKeys.JOB_IS_NOT_FINISHED,
             params=None)
Exemple #4
0
    def _limit_rating(job, rate):
        list_of_questions_in_a_question_set = Job.count_questions_in_question_set(
            job)

        if len(list_of_questions_in_a_question_set) >= len(rate):
            return True, list_of_questions_in_a_question_set
        else:
            return False, RatedBefore(status=404,
                                      message=MessagesKeys.JOB_RATED_BEFORE,
                                      params=None)
Exemple #5
0
 def _is_job_existence(self):
     error_free, result = Job.find(id=self.job_id)
     if not error_free:
         return False, result
     if len(result) == 0:
         return False, JobNotFound(status=404,
                                   message=MessagesKeys.ID_IS_NOT_IN_DB,
                                   params=None)
     self.job_id = result[0].id
     return True, result[0]
Exemple #6
0
 def deserialize(self):
     if not type(self.json_obj) is dict:
         json_dict = Serializable.convert_input_to_dict(self.json_obj)
     else:
         json_dict = self.json_obj
     result = CancelJobRequest.pre_deserialize(json_dict)
     if not result[0]:
         return result
     self.job = Job(id=json_dict[Keys.JOB_ID])
     result_pattern = self.post_deserialize()
     if not result_pattern[0]:
         return result_pattern
     return True, self
Exemple #7
0
 def deserialize(self):
     if not type(self.json_obj) is dict:
         json_dict = Serializable.convert_input_to_dict(self.json_obj)
     else:
         json_dict = self.json_obj
     result = CancellationByCarOwnerRequest.pre_deserialize(json_dict)
     if result[0]:
         self.job = Job(json_dict[Keys.JOB_ID])
         self.car_owner = CarOwner(
             id=SessionManager.retrieve_session_value_by_key(Keys.USER_ID))
         result_pattern = self.post_deserialize()
         if not result_pattern[0]:
             return result_pattern
         return True, self.job
     return result
Exemple #8
0
    def deserialize(self):
        if not type(self.json_obj) is dict:
            json_dict = Serializable.convert_input_to_dict(self.json_obj)
        else:
            json_dict = self.json_obj
        result = FullRequest.pre_deserialize(json_dict)
        if not result[0]:
            return result

        self.job = Job(id=json_dict[Keys.JOB_ID])
        self.payment = FullPayment(payment_type_id=json_dict[Keys.PAYMENT_TYPE], amount=json_dict[Keys.PAYMENT_AMOUNT],
                               currency='IRR', transaction_number=json_dict[Keys.TRANSACTION_NUMBER])
        result_pattern = self.post_deserialize()
        if not result_pattern[0]:
            return result_pattern
        return True, self
    def execute(self):
        error_free, result = Job.find(car_owner_id=self.car_owner_id)
        if not error_free:
            dct = result.dictionary_creator()
            return self.serialize(dct, self.converter)
        if result:
            error_free, payable_job = self._payable_job()
            if not error_free:
                dct = payable_job.dictionary_creator()
                return self.serialize(dct, converter=self.converter)

            #    if payable_job ro check konam?

            dct = payable_job.dictionary_creator()
            return self.serialize(dct, converter=self.converter)

        else:
            is_busy = JobNotFound(status=404,
                                  message=MessagesKeys.NOT_FOUND_JOB,
                                  params=None)
            dct = is_busy.dictionary_creator()
            return self.serialize(dct, self.converter)
Exemple #10
0
 def _load_job(self):
     return Job.load_job(self.job.id)
Exemple #11
0
 def _add_job(self):
     return Job.register_problem(db, self.job.job, self.car_problems)
Exemple #12
0
 def _update_rate(job, rate):
     data = {Keys.RATE: rate}
     return Job.update_by_id(job.id, db, data)
Exemple #13
0
 def cancel_job(self):
     status = Status.query.filter(Status.name == Keys.STATUS_CANCELLED_BY_BUSINESS_OWNER).first()
     data = {Keys.STATUS_ID: status.id}
     return Job.cancel_job(self.job, data, db)
Exemple #14
0
 def load_jobs(self):
     error_free, results = Job.load_jobs_by_statuses_for_business_owner(business_owner=self.business_owner,
                                                                        statuses=self.status_list)
     if not error_free:
         return results
     return SuccessInQueueJobs(status=200, message=MessagesKeys.SUCCESS_IN_QUEUE_JOBS, params=results)
 def _finished_job(self):
     car_owner_id = SessionManager.retrieve_session_value_by_key(
         Keys.USER_ID)
     return Job.find_all_finished_job(car_owner_id=car_owner_id)
    def insert_some_data(cls):
        data = [
            {
                "service_type": 1,
                "service_grade": 1
            },
            {
                "service_type": 2,
                "service_grade": 1
            },
            {
                "service_type": 4,
                "service_grade": 1
            },
        ]
        car_problems = []
        for car_problem in data:
            c_p = CarProblem(consumable_item_id=1, services_definition_id=1)
            car_problems.append(c_p)
        status = Status.query.filter(Status.name == Keys.STATUS_START).first()
        status1 = Status.query.filter(Status.name == Keys.STATUS_DONE).first()
        status2 = Status.query.filter(
            Status.name == Keys.STATUS_ACCEPTED_BY_BUSINESS_OWNER).first()

        job1 = Job(business_owner_id=1,
                   car_owner_id=2,
                   car_id=1,
                   status_=status1,
                   start_schedule="2018-04-3 07:30:00",
                   finish_schedule="2018-04-3 11:40:00",
                   start_time="2018-04-3 07:33:00")
        job2 = Job(business_owner_id=2,
                   car_owner_id=3,
                   car_id=2,
                   status_=status,
                   start_schedule="2018-04-3 08:00:00",
                   finish_schedule="2018-04-3 08:13:00",
                   start_time="2018-04-3 08:02:00")

        job3 = Job(business_owner_id=6,
                   car_owner_id=5,
                   car_id=5,
                   status_=status1,
                   start_schedule="2018-04-3 08:40:00",
                   finish_schedule="2018-04-3 08:41:00",
                   start_time="2018-04-3 09:02:00")
        job4 = Job(business_owner_id=7,
                   car_owner_id=4,
                   car_id=4,
                   status_=status1,
                   start_schedule="2018-04-3 07:13:00",
                   finish_schedule="2018-04-3 07:15:00",
                   start_time="2018-04-3 07:20:00",
                   finish_time="2018-04-3 08:15:00")
        job5 = Job(business_owner_id=5,
                   car_owner_id=3,
                   car_id=3,
                   status_=status2,
                   start_schedule="2018-04-2 06:00:00",
                   finish_schedule="2018-04-2 11:11:00")

        job1.car_problems.extend(car_problems)
        db.session.add(job1)
        db.session.commit()

        job2.car_problems.extend(car_problems)
        db.session.add(job2)
        db.session.commit()

        job3.car_problems.extend(car_problems)
        db.session.add(job3)
        db.session.commit()

        job4.car_problems.extend(car_problems)
        db.session.add(job4)
        db.session.commit()

        job5.car_problems.extend(car_problems)
        db.session.add(job5)
        db.session.commit()
 def _payable_job(self):
     return Job.find_all_payable_job(car_owner_id=self.car_owner_id)