def get_check_user_position(self): if self.check_user.is_boss(): return '老板' else: employee = get_object(Employee, user=self.check_user, shop=self.shop, status=Employee.STATUS_VALID) if employee: return employee.get_position_display() return ''
def get_plan_money(self): plan = get_object(PlanInfo, employee=self.report.employee, shop=self.report.shop, plan_type=self.report.report_type, target_date=self.report.target_date, status=PlanInfo.STATUS_VALID) if plan: five_list = plan.get_five_list() if five_list.exists(): return five_list[0].sale_cash_money return 0
def last_month_money(self): lask_week = self.report.target_count - 1 report = get_object(ReportInfo, employee=self.report.employee, shop=self.report.shop, report_type=self.report.report_type, target_count=lask_week, status=ReportInfo.STATUS_VALID) if report: five_list = report.get_five_list() if five_list.exists(): return five_list[0].sale_cash_money return 0
def get_yesterday_money(self): yesterday = self.report.target_date - datetime.timedelta(days=1) report = get_object(ReportInfo, employee=self.report.employee, shop=self.report.shop, report_type=self.report.report_type, target_date=yesterday, status=ReportInfo.STATUS_VALID) if report: five_list = report.get_five_list() if five_list.exists(): return five_list[0].sale_cash_money return 0
def content(self): from report.serializers import ReportMapSerializer # 判断返回哪些模型字段 model_list = ReportMapSerializer().model_map serializer_list = ReportMapSerializer().serializer_map data = {} report_config = get_object(ReportConfig, user=self.shop.user, report_type=self.report_type, position=self.employee.position, status=ReportConfig.STATUS_VALID) if not report_config: return {} choice_list = report_config.get_model_choice() for index, key in enumerate(choice_list): if key in model_list and choice_list[key]: data[key] = serializer_list[key](model_list[key].objects.filter(report=self, status=model_list[key].STATUS_VALID), many=True).data return data
def get_model_choice(self): report_config = get_object(ReportConfig, user=self.shop.user, report_type=self.report_type, position=self.employee.position, status=ReportConfig.STATUS_VALID) if report_config: return report_config.get_model_choice() return {}