1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
| class WorkDayOffAdmin(object): data_charts = OrderedDict(( ( "all", { 'title': u"总览", 'x-field': 'burnish_user__name', 'y-field': ( 'work_day_offs', 'extra_works', 'total_hours', ), 'order': ('hours', ), 'option':{ 'series': { 'bars': { 'show': True, 'barWidth': 0.5, } }, 'xaxis': { 'mode': "categories", 'tickLength': 0, }, } }, ), ( "last", { 'title': u"剩余换休", 'x-field': 'burnish_user__name', 'y-field': ( 'total_hours', ), 'order': ('hours', ), 'option':{ 'series': { 'bars': { 'show': True, 'barWidth': 0.5, } }, 'xaxis': { 'mode': "categories", 'tickLength': 0, }, } }, ), ( "extra_works", { 'title': u"加班", 'x-field': 'burnish_user__name', 'y-field': ( 'extra_works', ), 'order': ('hours', ), 'option':{ 'series': { 'bars': { 'show': True, 'barWidth': 0.5, } }, 'xaxis': { 'mode': "categories", 'tickLength': 0, }, } }, ), ( "work_offs", { 'title': u"已换休", 'x-field': 'burnish_user__name', 'y-field': ( 'work_day_offs', ), 'order': ('hours', ), 'option':{ 'series': { 'bars': { 'show': True, 'barWidth': 0.5, } }, 'xaxis': { 'mode': "categories", 'tickLength': 0, }, }, }, ), )) list_display = ( 'burnish_user', 'from_date', 'end_date', 'hours', 'status', 'reason', ) list_filter = ( 'burnish_user', 'status', ) search_fields = ( 'burnish_user__name', 'reason', ) list_editable = ( 'from_date', 'end_date', 'hours', 'status', ) date_hierarchy = 'from_date' total_hours_dealed = None extra_works_dealed = None work_day_offs_dealed = None def total_hours(self, data): if not self.total_hours_dealed: self.total_hours_dealed = [] user_id = data.burnish_user.id if user_id in self.total_hours_dealed: return None self.total_hours_dealed.append(user_id) return WorkDayOff.objects.filter( burnish_user_id=user_id, status='sure', ).aggregate( total_hours=Sum('hours') )['total_hours'] or 0 total_hours.short_description = '剩余换休' def extra_works(self, data): if not self.extra_works_dealed: self.extra_works_dealed= [] user_id = data.burnish_user.id if user_id in self.extra_works_dealed: return None self.extra_works_dealed.append(user_id) return WorkDayOff.objects.filter( burnish_user_id=user_id, status='sure', hours__gt=0, ).aggregate( total_hours=Sum('hours') )['total_hours'] or 0 extra_works.short_description = '总计加班' def work_day_offs(self, data): if not self.work_day_offs_dealed: self.work_day_offs_dealed= [] user_id = data.burnish_user.id if user_id in self.work_day_offs_dealed: return None self.work_day_offs_dealed.append(user_id) return abs(WorkDayOff.objects.filter( burnish_user_id=user_id, status='sure', hours__lt=0, ).aggregate( total_hours=Sum('hours') )['total_hours'] or 0) work_day_offs.short_description = '总计休假'
|