Brak opisu

models.py 5.3KB

    # -*- coding: utf-8 -*- from django.db import models from django.utils.translation import ugettext_lazy as _ from django_models_ext import BaseModelMixin, upload_path from mch.models import ConsumeImpressionInfo, ModelInfo class SaleclerkIntegralIncomeExpensesInfo(BaseModelMixin): INCOME = 0 EXPENSE = 1 UNFREEZE = 2 TYPE = ( (INCOME, u'收入'), (EXPENSE, u'支出'), (UNFREEZE, u'解冻'), ) clerk_id = models.CharField(_(u'clerk_id'), max_length=32, blank=True, null=True, help_text=u'店员唯一标识', db_index=True) type = models.IntegerField(_(u'type'), choices=TYPE, default=INCOME, help_text=u'收支类别', db_index=True) brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称') model_id = models.CharField(_(u'model_id'), max_length=32, blank=True, null=True, help_text=u'型号唯一标识', db_index=True) model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称') distributor_id = models.CharField(_(u'distributor_id'), max_length=32, blank=True, null=True, help_text=u'经销商唯一标识', db_index=True) distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称') code = models.CharField(_(u'code'), max_length=32, blank=True, null=True, help_text=u'机身码', db_index=True) consumer_name = models.CharField(_(u'consumer_name'), max_length=32, blank=True, null=True, help_text=u'消费者姓名') consumer_phone = models.CharField(_(u'consumer_phone'), max_length=32, blank=True, null=True, help_text=u'消费者手机号') lat = models.FloatField(_(u'lat'), default=1.0, help_text=u'纬度') lon = models.FloatField(_(u'lon'), default=1.0, help_text=u'经度') image = models.FileField(_(u'image'), upload_to=upload_path, blank=True, null=True, help_text=u'图片') integral = models.IntegerField(_(u'integral'), default=0, help_text=u'增减积分') left_integral = models.IntegerField(_(u'left_integral'), default=0, help_text=u'积分增减后数量(分)') remark = models.CharField(_(u'remark'), max_length=255, blank=True, null=True, help_text=u'备注') test_user = models.BooleanField(_(u'test_user'), default=False, help_text=_(u'是否为测试用户'), db_index=True) class Meta: verbose_name = _(u'saleclerkintegralincomeexpensesinfo') verbose_name_plural = _(u'saleclerkintegralincomeexpensesinfo') def __unicode__(self): return unicode(self.pk) @property def model_info(self): try: info = ModelInfo.objects.get(model_id=self.model_id).fulldata except ModelInfo.DoesNotExist: info = {} return info @property def consumer_impression(self): try: impression = ConsumeImpressionInfo.objects.get(clerk_id=self.clerk_id, brand_id=self.brand_id, model_id=self.model_id, serialNo=self.code) except ConsumeImpressionInfo.DoesNotExist: impression = None return impression.data if impression else {} @property def data(self): return { 'type': self.type, 'integral': self.integral, 'model_info': self.model_info, 'modelName': self.model_name, 'consumer_impression': self.consumer_impression, 'serialNo': self.code, 'created_at': self.created_at, } class SaleclerkSubmitLogInfo(BaseModelMixin): clerk_id = models.CharField(_(u'clerk_id'), max_length=32, blank=True, null=True, help_text=u'店员唯一标识', db_index=True) brand_pk = models.IntegerField(_(u'brand_pk'), default=0, help_text=u'品牌PK', db_index=True) model_pk = models.IntegerField(_(u'model_pk'), default=0, help_text=u'型号PK', db_index=True) distributor_pk = models.IntegerField(_(u'distributor_pk'), default=0, help_text=u'经销商PK', db_index=True) code = models.CharField(_(u'code'), max_length=32, blank=True, null=True, help_text=u'机身码', db_index=True) consumer_name = models.CharField(_(u'consumer_name'), max_length=32, blank=True, null=True, help_text=u'消费者姓名') consumer_phone = models.CharField(_(u'consumer_phone'), max_length=32, blank=True, null=True, help_text=u'消费者手机号') lat = models.FloatField(_(u'lat'), default=1.0, help_text=u'纬度') lon = models.FloatField(_(u'lon'), default=1.0, help_text=u'经度') image = models.FileField(_(u'image'), upload_to=upload_path, blank=True, null=True, help_text=u'图片') remark = models.CharField(_(u'remark'), max_length=255, blank=True, null=True, help_text=u'备注') dupload = models.BooleanField(_(u'dupload'), default=False, help_text=_(u'是否为重复提交'), db_index=True) test_user = models.BooleanField(_(u'test_user'), default=False, help_text=_(u'是否为测试用户'), db_index=True) test_sn = models.BooleanField(_(u'test_sn'), default=False, help_text=_(u'是否为测试序列号'), db_index=True) class Meta: verbose_name = _(u'saleclerksubmitloginfo') verbose_name_plural = _(u'saleclerksubmitloginfo') def __unicode__(self): return unicode(self.pk)