Пример #1
0
    def _recordTaskOnNonBillable(self, operation_definition_id):
        mainlog.debug(
            "_recordTaskOnNonBillable {}".format(operation_definition_id))

        q = self.dao.session.query(
            OperationDefinition.operation_definition_id,
            OperationDefinition.description,
            OperationDefinition.imputable == True, TaskOnNonBillable.active,
            TaskOnNonBillable.task_id).outerjoin(TaskOnNonBillable).filter(
                OperationDefinition.operation_definition_id ==
                operation_definition_id).options(lazyload('*'))

        row = q.first()

        if row is None:
            raise ServerException(1001, operation_definition_id)

        h = dict()
        h['task_type'] = 'TaskOnNonBillable'
        h['operation_definition_id'], h[
            'description'], imputable, task_active, task_id = row

        if not imputable:
            raise ServerException(1002, operation_definition_id)

        if task_id is None:
            t = self.dao.task_dao.create_non_billable_task(
                operation_definition_id)
            task_id = t.task_id
        elif not task_active:
            raise ServerException(1003, task_id, operation_definition_id)

        return task_id, h
Пример #2
0
    def _recordTaskOnOperation(self, operation_id):
        mainlog.debug(
            "_recordTaskOnOperation operation_id={}".format(operation_id))

        q = self.dao.session.query(Operation.operation_id,
                                   Order.accounting_label,
                                   OrderPart.label,
                                   OrderPart.description,
                                   Customer.fullname,
                                   OperationDefinition.short_id,
                                   TaskOnOperation.task_id,
                                   and_(OperationDefinition.imputable == True,
                                        OperationDefinition.on_operation == True,
                                        Order.state == OrderStatusType.order_ready_for_production),
                                   TaskOnOperation.active,
                                   Operation.description,
                                   Operation.position)\
                             .join(ProductionFile).join(OrderPart).join(Order).outerjoin(TaskOnOperation,TaskOnOperation.operation_id == Operation.operation_id).join(OperationDefinition, OperationDefinition.operation_definition_id == Operation.operation_definition_id).join(Customer,Order.customer_id == Customer.customer_id).options(lazyload('*')).filter(Operation.operation_id == operation_id)

        row = q.first()

        if row is None:
            raise ServerException(1004, operation_id)

        mainlog.debug("_recordTaskOnOperation: query results {}".format(row))
        h = dict()
        h['task_type'] = 'TaskOnOperation'
        h['order_part_label'] = str(row[1]) + (row[2] or "-")
        h['order_part_description'] = row[3]
        h['customer_name'] = row[4]
        h['operation_definition'] = row[5]
        task_id = row[6]
        imputable = row[7]
        task_active = row[8]
        h['operation_description'] = row[9]
        h['operation_position'] = row[10]

        if imputable:
            if task_id is None:
                task_id = self.dao.task_dao.create_task_on_operation(
                    operation_id).task_id

            elif not task_active:
                raise ServerException(1000, task_id)

            return task_id, h
        else:
            raise ServerException(
                1005, u"'{} {}'".format((h['operation_definition'] or ""),
                                        (h['operation_description'] or "")),
                h['order_part_label'])
Пример #3
0
    def getMoreTaskInformation(self, task_id):
        try:
            mainlog.debug(
                "getMoreTaskInformation, task id = {}".format(task_id))
            t = self.dao.task_dao.find_by_id(task_id)

            if isinstance(t, TaskOnOperation):
                operation = t.operation

                employees_on_task = self.dao.task_dao.employees_on_task(t)

                h = {
                    'task_type':
                    'TaskOnOperation',
                    'description':
                    operation.description,
                    'operation_definition':
                    operation.operation_model.description,
                    'operation_definition_short':
                    operation.operation_model.short_id,
                    'order_part_description':
                    operation.production_file.order_part.description,
                    'order_description':
                    operation.production_file.order_part.order.description,
                    'order_part_id':
                    operation.production_file.order_part.label,
                    'order_id':
                    operation.production_file.order_part.order.label,
                    'customer_name':
                    operation.production_file.order_part.order.customer.
                    fullname,
                    'employees_on_task':
                    map(lambda emp: emp.employee_id, employees_on_task)
                }
                mainlog.debug("getMoreTaskInformation, returning {}".format(h))
                self.dao.session.commit()
                return h
            elif isinstance(t, TaskOnNonBillable):
                h = {
                    'task_type': 'TaskOnNonBillable',
                    'description': t.operation_definition.description
                }
                self.dao.session.commit()
                return h
            else:
                raise Exception("Unsupported task type")

        except Exception, e:
            mainlog.exception(e)
            return None
Пример #4
0
    def getLastActionReport(self, task_id, employee_id):
        mainlog.info("getLastActionReport task:{} employee:{}".format(
            task_id, employee_id))
        try:
            reports = self.dao.task_action_report_dao.get_reports_for_task_employee(
                task_id, employee_id)
            if reports:
                return rpctools.sqla_to_hash(reports[-1])
            else:
                mainlog.debug("getLastActionReport : return None")
                return None

        except Exception, e:
            mainlog.exception(e)
            return None
Пример #5
0
    def _recordActionOnWorkTask(self, task_id, employee, action_time,
                                location):
        # We're going to use the last action report on the same task we're
        # working now to determine if the pointage is a task start or task stop

        # BUG For some reason if I only ask the action kind
        # the query returns no row at all...

        q = self.dao.session.query(TaskActionReport.task_action_report_id, TaskActionReport.kind).\
            filter(and_(TaskActionReport.task_id == task_id,
                        TaskActionReport.reporter == employee)).order_by(desc(TaskActionReport.time),desc(TaskActionReport.task_action_report_id))

        last_action_report = q.first()
        last_action_report_kind = None
        if last_action_report:
            # There is a last action report
            last_action_report_kind = last_action_report[1]

        # Who else works on the task ?
        # q = self.dao.session.query(TaskActionReport.task_action_report_id, TaskActionReport.reporter_id).filter(and_(TaskActionReport.task_id == task_id,TaskActionReport.reporter_id != employee_id)).order_by(desc(TaskActionReport.time),desc(TaskActionReport.task_action_report_id))

        # When pointage is on started task, then we *guess*
        # the intention of the user is to stop the task.
        # and vice versa...

        action_kind = TaskActionReportType.start_task

        if last_action_report_kind == TaskActionReportType.start_task:
            action_kind = TaskActionReportType.stop_task
        elif last_action_report_kind == TaskActionReportType.stop_task:
            action_kind = TaskActionReportType.start_task

        mainlog.debug(
            "Constructing task action report on task {}".format(task_id))

        self.dao.task_action_report_dao.fast_create(task_id, employee,
                                                    action_time, action_kind,
                                                    location)  # No commit

        self.dao.commit()

        task_action_reports = self.dao.task_action_report_dao.get_reports_for_employee_on_date(
            employee, action_time.date())

        # if len(task_action_reports) > 0:
        #     mainlog.debug(u"_recordActionOnWorkTask : {}".format(task_action_reports[-1]))

        return action_kind
Пример #6
0
    def getOngoingTasksInformation(self, employee_id):
        try:
            mainlog.debug(
                "getOngoingTasksInformation, employee id = {}".format(
                    employee_id))

            employee = self.dao.employee_dao.find_by_id(employee_id)
            task_list = self.dao.task_dao.ongoing_tasks_for_employee(employee)
            r = rpctools.sqla_to_hash(task_list)
            mainlog.debug(
                "getOngoingTasksInformation, about to return with : {}".format(
                    r))
            self.dao.session.commit()

            return r
        except Exception, e:
            mainlog.exception(e)
            return None
Пример #7
0
    def recordPointage(self, barcode, employee_id, action_time, location):
        mainlog.debug("Record pointage")

        try:
            action_time = datetime.strptime(str(action_time),
                                            "%Y%m%dT%H:%M:%S")

            # chrono_start()

            # Figure out the task information
            # Attention ! This will create a new tak if necessary

            task_id, h = self._barcodeToTask(barcode)

            mainlog.debug("Task id is {}".format(task_id))

            # chrono_click("_barcodeToTask")

            if not task_id:
                return None

            # FIXME That's sub optimal, we could use only the employee_id
            # however, this would change the dao layer in a way that we'd
            # use the id instead of the entity, which is less nice.

            employee = self.dao.employee_dao.find_by_id(employee_id)
            self.dao.session.commit()

            if h['task_type'] == 'TaskForPresence':
                if h['action_kind'] == TaskActionReportType.day_in:
                    self._recordDayInAction(employee, action_time, location)
                elif h['action_kind'] == TaskActionReportType.day_out:
                    self._recordDayOutAction(employee, action_time, location)
            else:
                h['action_kind'] = self._recordActionOnWorkTask(
                    task_id, employee, action_time, location)

            return h

        except ServerException, e:
            self.dao.session.rollback()
            mainlog.trace()
            raise xmlrpclib.Fault(e.code, e.msg)
Пример #8
0
    def getTaskInformation(self, task_id):
        try:
            mainlog.debug("getTaskInformation, task id = {}".format(task_id))

            data = BarCodeIdentifier.barcode_to_id(task_id)

            if data[0] == Operation:
                operation_id = data[1]
                t = self.dao.task_dao.task_for_operation(operation_id)
            else:
                e = "Can't get that object, I don't recognize it"
                raise xmlrpclib.Fault(1000, e)

            return rpctools.sqla_to_hash(t)

        except Exception, e:
            mainlog.exception(e)
            e = "Task {} not found".format(task_id)
            mainlog.error(e)
            raise xmlrpclib.Fault(1000, e)
Пример #9
0
    def _recordTaskOnOrder(self, order_id, opdef_id):
        mainlog.debug("_recordTaskOnOrder {}".format(order_id))

        # Pay attention, this code is a double if you compare it
        # with the one from the DAO. I had to duplicate for
        # perforamnce reasons (SQLA loads too many things
        # when I sometimes just need an id)

        q = self.dao.session.query(
            OperationDefinition.description,
            and_(OperationDefinition.imputable == True,
                 OperationDefinition.on_order == True,
                 Order.state == OrderStatusType.order_ready_for_production),
            TaskOnOrder.active, TaskOnOrder.task_id).outerjoin(
                TaskOnOrder,
                and_(TaskOnOrder.order_id == order_id,
                     TaskOnOrder.operation_definition_id == opdef_id)).filter(
                         and_(
                             OperationDefinition.operation_definition_id ==
                             opdef_id, Order.order_id == order_id))

        row = q.first()
        mainlog.debug("query results {}".format(row))

        mainlog.debug("_recordTaskOnOrder")

        for o in self.dao.session.query(OperationDefinition).all():
            mainlog.debug(o.operation_definition_id)
            mainlog.debug(o)

        for o in self.dao.session.query(Order).all():
            mainlog.debug(o)

        if row is None:
            raise ServerException(1006, opdef_id, order_id)

        h = dict()
        h['order_id'] = order_id  # FIXME Should be account/preorder rather than that
        h['description'], imputable, task_active, task_id = row
        h['task_type'] = 'TaskOnOrder'

        if not imputable:
            raise ServerException(1007, opdef_id, order_id)

        if task_id is None:
            t = self.dao.task_dao.create_task_on_order(order_id, opdef_id)
            task_id = t.task_id
        elif not task_active:
            raise ServerException(1008, opdef_id, order_id)

        return task_id, h