def set_employee_date(self, employee, d):
        self.current_employee = employee
        self.current_date = d

        self.timesheet_info_label.setText(
            _("Time recordings for <b>{}</b> on <b>{}</b>").format(
                employee.fullname, date_to_s(d, True)))

        self.controller.model._buildModelFromObjects(
            dao.task_action_report_dao.get_reports_for_employee_on_date(
                employee, d))

        for i in range(len(self.controller.model.objects)):
            if self.controller.model.objects[i]:
                row = self.controller.model.table[i]
                obj = self.controller.model.objects[i].task

                if isinstance(obj, TaskOnOrder):
                    row[0] = obj.order
                elif isinstance(obj, TaskOnOperation):
                    row[0] = obj.operation.production_file.order_part
                elif isinstance(obj, TaskOnNonBillable):
                    row[0] = ""
                elif obj is None:
                    row[0] = ""
                else:
                    raise Exception("Can't work with type {}".format(
                        type(obj)))

        self.controller.model_data_changed = False  # FIXME dirty (encapsulate in controller plz)
Exemple #2
0
    def _quality_event_title(self, qe):
        if qe.quality_event_id:
            id = qe.human_identifier
            # id = str(qe.quality_event_id)
        else:
            id = "-"

        return _("{} ({})").format(id, date_to_s(qe.when))
Exemple #3
0
 def _fill_order_part_detail(self, supply_order_part):
     if supply_order_part:
         supply_order_part_id = supply_order_part.supply_order_id
         supply_order, parts = supply_order_service.find_by_id(
             supply_order_part.supply_order_id)
         self.detail_description.setText(supply_order.description)
         self.delivery_date_widget.setText(
             date_to_s(supply_order.expected_delivery_date) or "-")
         self.supplier_reference_widget.setText(
             supply_order.supplier_reference or "-")
         self.creation_date_widget.setText(
             date_to_s(supply_order.creation_date) or "-")
     else:
         self.detail_description.setText("-")
         self.delivery_date_widget.setText("-")
         self.supplier_reference_widget.setText("-")
         self.creation_date_widget.setText("-")
Exemple #4
0
    def set_employee_and_date(
        self, employee_id, edit_date
    ):  # FIXME move this into constructore and remove call in using class... Or change the timestamp prototype

        employee = dao.employee_dao.find_by_id_frozen(employee_id)
        timetracks = dao.timetrack_dao.all_work_for_employee_date(
            employee_id, edit_date)
        self.task_cache = PotentialTasksCache(dao.task_dao, edit_date)

        mainlog.debug("set_employee_and_date : timetracks are")
        proxified_timetracks = []
        for timetrack in timetracks:
            mainlog.debug(timetrack)
            proxified_timetracks.append(TimetrackProxy(timetrack))
        mainlog.debug("done")

        self.edit_date = edit_date
        self.task_on_orderpart_prototype.on_date = edit_date
        self.timesheet_info_label.setText(
            _("Timesheet for <b>{}</b> on <b>{}</b>").format(
                employee.fullname, date_to_s(edit_date, True)))

        self.task_on_orderpart_prototype.set_task_cache(self.task_cache)

        self.controller.model._buildModelFromObjects(proxified_timetracks)

        self.controller.model.set_row_protect_func(
            lambda obj, row: obj is not None and obj.managed_by_code,
            prevent_row_delete_message)
        self.controller.model.row_update_protect_func = lambda obj, row: obj and obj.managed_by_code
        self.controller.model.row_update_protect_announce = prevent_row_update_message

        for i in range(len(timetracks)):
            row = self.controller.model.table[i]
            imputable = ImputableProxy(edit_date)
            imputable.set_on_timetrack(timetracks[i])
            row[0] = imputable

        # for row in self.controller.model.table:
        #     if row[1]:
        #         row[0] = row[1].operation.production_file.order_part

        # self.controller.model_data_changed = False # FIXME dirty (encapsulate in controller plz)
        self.current_employee_id_selected = employee_id

        self.controller.view.setFocus(Qt.OtherFocusReason)
        self.controller.view.setCurrentIndex(self.controller.model.index(0, 0))

        # FIXME Better separate presentation and data layer !!!
        session().commit()

        self.data_changed_slot(None)
Exemple #5
0
    def cell_entered(self,ndx):
        chrono = datetime.now()

        employee = self.employees[ndx.row()]

        a = max(1,ndx.column())
        d = date(self.base_date.year,self.base_date.month,min(calendar.monthrange(self.base_date.year,self.base_date.month)[1], max(1,ndx.column())))
        # print employee, d

        # Fill in the timetracks report panel ----------------------------

        # First we read the timetrackss and their associated OrderPart

        t_start = datetime(d.year,d.month,d.day,0,0,0,0)
        t_end = datetime(d.year,d.month,d.day,23,59,59,999999)

        # FIXME not abstract enough
        # FIXME This should be in the DAO

        tt = session().query(TimeTrack,OrderPart).\
            join(TaskOnOperation).join(Operation).join(ProductionFile).join(OrderPart).\
            filter(and_(TimeTrack.employee == employee,
                        TimeTrack.start_time >= t_start,
                        TimeTrack.start_time <= t_end)).order_by(asc(TimeTrack.start_time)).all()

        tt += session().query(TimeTrack,Order).join(TaskOnOrder).join(Order).filter(and_(TimeTrack.employee == employee, TimeTrack.start_time >= t_start, TimeTrack.start_time <= t_end)).order_by(asc(TimeTrack.start_time)).all()

        tt += session().query(TimeTrack,OperationDefinition).join(TaskOnNonBillable).join(OperationDefinition).filter(and_(TimeTrack.employee == employee, TimeTrack.start_time >= t_start, TimeTrack.start_time <= t_end)).order_by(asc(TimeTrack.start_time)).all()


        # Fill in the report panel ---------------------------------------

        self.hours_on_day_subframe.set_title(_("Hours worked on the {} by {}").format(date_to_s(d,True),employee.fullname))
        self.controller.model._buildModelFromObjects(map(lambda o : o[0],tt)) #     dao.timetrack_dao.all_for_employee(employee))

        # self.controller.model.row_protect_func = lambda obj,row: obj is not None and obj.managed_by_code

        ndx = 0
        for row in self.controller.model.table:
            if row[1]:
                row[0] = tt[ndx][1] # First column becomes the order
            ndx += 1

        self.controller.view.resizeColumnsToContents()


        # Fill in the time report panel ---------------------------------

        self.pointage_timestamp_prototype.set_fix_date(d)
        self.controller_actions.model._buildModelFromObjects(
            dao.task_action_report_dao.get_reports_for_employee_on_date(employee,d))