Ejemplo n.º 1
0
class Education(generic.BO):
    """
    教育履历
    """
    edu_type = models.CharField(_("edu type"),
                                max_length=const.DB_CHAR_CODE_2,
                                choices=const.get_value_list('S035'),
                                default='1')
    school = models.CharField(_("school"), max_length=const.DB_CHAR_NAME_120)
    major = models.CharField(_("major"),
                             max_length=const.DB_CHAR_NAME_120,
                             blank=True,
                             null=True)
    degree = models.CharField(_("major degree"),
                              max_length=const.DB_CHAR_CODE_2,
                              blank=True,
                              null=True,
                              choices=const.get_value_list('S037'),
                              default='4')
    employee = models.ForeignKey(Employee,
                                 verbose_name=_("employee"),
                                 on_delete=models.deletion.PROTECT)

    class Meta:
        verbose_name = _("education experience")
        verbose_name_plural = _("education experience")
Ejemplo n.º 2
0
class SalaryItem(models.Model):
    """
    工资项
    """
    formulas = {}

    @classmethod
    def add_formula(cls, code, handler):
        SalaryItem.formulas[code] = handler

    @classmethod
    def get_formula(cls):
        return SalaryItem.formulas.get(cls.code, None)

    code = models.CharField(_("code"),
                            max_length=const.DB_CHAR_CODE_10,
                            null=True)
    name = models.CharField(_("name"), max_length=const.DB_CHAR_NAME_120)
    classification = models.CharField(_("classification"),
                                      max_length=const.DB_CHAR_CODE_2,
                                      choices=const.get_value_list('S048'),
                                      default='10')
    plus_or_minus = models.CharField(_("plus or minus"),
                                     max_length=const.DB_CHAR_CODE_2,
                                     choices=const.get_value_list('S049'),
                                     default='+')
    required = models.BooleanField(_("is required"), default=0)

    def __str__(self):
        return "%s %s" % (self.code, self.name)

    class Meta:
        verbose_name = _('salary item')
        verbose_name_plural = _('salary items')
        ordering = ('code', )
Ejemplo n.º 3
0
class Family(generic.BO):
    """
    家庭成员
    """
    relation = models.CharField(_("family title"),
                                max_length=const.DB_CHAR_CODE_2,
                                blank=True,
                                null=True,
                                choices=const.get_value_list('S025'))
    status = models.CharField(_("social status"),
                              max_length=const.DB_CHAR_CODE_2,
                              blank=True,
                              null=True,
                              choices=const.get_value_list('S029'),
                              default='17')
    name = models.CharField(_("name"), max_length=const.DB_CHAR_NAME_60)
    birthday = models.DateField(_("birthday"), blank=True, null=True)
    organization = models.CharField(_("organization"),
                                    max_length=const.DB_CHAR_NAME_120,
                                    blank=True,
                                    null=True)
    phone = models.CharField(_("phone"),
                             max_length=const.DB_CHAR_NAME_120,
                             blank=True,
                             null=True)
    emergency = models.BooleanField(_("emergency"), default=False)
    employee = models.ForeignKey(Employee,
                                 verbose_name=_("employee"),
                                 on_delete=models.deletion.PROTECT)

    class Meta:
        verbose_name = _("family member")
        verbose_name_plural = _("family member")
Ejemplo n.º 4
0
class SaleItem(models.Model):
    """
    订单明细
    """
    master = models.ForeignKey(SaleOrder)
    material = models.ForeignKey(Material,verbose_name=_("material"),limit_choices_to={"is_virtual":"0",'can_sale':'1'},blank=True,null=True)
    measure = models.ForeignKey(Measure,verbose_name=_("measure"),blank=True,null=True)
    cnt = models.DecimalField(_("count"),max_digits=14,decimal_places=4)
    stock_price = models.DecimalField(_("stock price"),max_digits=14,decimal_places=4,blank=True,null=True)
    sale_price = models.DecimalField(_("sale price"),max_digits=14,decimal_places=4,blank=True,null=True)
    discount_price = models.DecimalField(_("discount price"),max_digits=14,decimal_places=4,blank=True,null=True)
    tax = models.CharField(_("tax rate"),max_length=const.DB_CHAR_CODE_6,choices=const.get_value_list('S052'),default='0.00')
    create_time = models.DateTimeField(_("create time"),auto_now_add=True)
    status = models.BooleanField(_("executed"),default=0)
    event_time = models.DateTimeField(_("event time"),blank=True,null=True)

    def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None):
        if self.material and self.material.measure.count() > 0:
            self.measure = self.material.measure.all()[0]
        if self.material.sale_price or self.material.stock_price:
            self.sale_price = self.material.sale_price or self.material.stock_price*decimal.Decimal(1.17)/decimal.Decimal(0.6)
        super(SaleItem,self).save(force_insert,force_update,using,update_fields)
        sql = 'update sale_saleorder set amount = (select sum(sale_price*cnt) from sale_saleitem where master_id=%s) where id=%s'
        params = [self.master.id,self.master.id]
        # print sql % (self.master.id,self.master.id)
        generic.update(sql,params)

    class Meta:
        verbose_name = _('order detail')
        verbose_name_plural = _('order detail')
Ejemplo n.º 5
0
class Entry(generic.BO):
    """
    人员入职
    """
    code = models.CharField(_("employee number"),max_length=const.DB_CHAR_NAME_20,blank=True,null=True)
    name = models.CharField(_("employee name"),max_length=const.DB_CHAR_NAME_120)
    pinyin = models.CharField(_("pinyin"),max_length=const.DB_CHAR_NAME_120,blank=True,null=True)
    birthday = models.DateField(_("birthday"),blank=True,null=True)
    gender = models.CharField(_("gender"),max_length=const.DB_CHAR_CODE_2,choices=const.get_value_list('gender'),default='1')
    idcard = models.CharField(_("id card"),max_length=const.DB_CHAR_NAME_20)
    address = models.CharField(_("mail address"),max_length=const.DB_CHAR_NAME_120,blank=True,null=True)
    zipcode = models.CharField(_("zipcode"),max_length=const.DB_CHAR_CODE_8)
    phone = models.CharField(_("phone"),max_length=const.DB_CHAR_NAME_20,blank=True,null=True)

    guider = models.ForeignKey(Employee,verbose_name=_("guider"),on_delete=models.CASCADE)
    position = models.ForeignKey(Position,verbose_name = _('designate position'),on_delete=models.CASCADE)
    rank = models.CharField(_("employee rank"),max_length=const.DB_CHAR_CODE_2,default='00',choices=const.get_value_list('S017'))
    ygxs = models.CharField(_("employ ygxs"),max_length=const.DB_CHAR_CODE_2,blank=True,null=True,choices=const.get_value_list('S019'),default='2')
    category = models.CharField(_("employ category"),max_length=const.DB_CHAR_CODE_2,blank=True,null=True,choices=const.get_value_list('S018'),default='21')

    probation_months = models.CharField(_("probation months"),max_length=2,default='3',choices=const.get_value_list('S047'))
    probation_begin = models.DateField(_("probation begin"),default=datetime.date.today)
    probation_end = models.DateField(_("probation end"),blank=True,null=True)

    memo = models.TextField(_("memo"),blank=True,null=True)
    profile = models.FileField(_("profile"),blank=True,null=True,upload_to='hr profile')

    class Meta:
        verbose_name = _("employee entry")
        verbose_name_plural = _("employee entries")
        permissions = (
            ('modify_salary_item',_("modify salary item")),
        )
Ejemplo n.º 6
0
class Document(generic.BO):
    """
    文档管理
    """
    TP = (
        ('00', _('SYSTEM MANUAL')),
        ('10', _('BUSINESS DOC')),
    )
    STATUS = (
        ('0', _('draft')),
        ('1', _('published'))
    )
    index_weight = 8
    code = models.CharField(_('code'), max_length=const.DB_CHAR_NAME_20, blank=True, null=True)
    title = models.CharField(_('title'), max_length=const.DB_CHAR_NAME_120)
    keywords = models.CharField(_('keywords'), max_length=const.DB_CHAR_NAME_120, blank=True, null=True)
    description = models.TextField(_('description'), blank=True, null=True)
    tp = models.CharField(_('type'), max_length=const.DB_CHAR_CODE_2, default='10', choices=TP)
    business_domain = models.CharField(_("business domain"), max_length=const.DB_CHAR_CODE_4,
                                       choices=const.get_value_list('S045'), default='OT')
    user = models.ForeignKey(User, verbose_name=_('user'), blank=True, null=True)
    status = models.CharField(_('status'), max_length=const.DB_CHAR_CODE_2, default='0', choices=STATUS)
    pub_date = models.DateTimeField(_('publish date'), blank=True, null=True)
    size = models.CharField(_('size'), max_length=const.DB_CHAR_NAME_20, blank=True, null=True)
    attach = models.FileField(_('attach'), blank=True, null=True, upload_to='doc')

    class Meta:
        verbose_name = _("document")
        verbose_name_plural = _("documents")
Ejemplo n.º 7
0
def get_value_list(group):
    """

    :param group:
    :return:
    """
    return const.get_value_list(group)
Ejemplo n.º 8
0
class POItem(models.Model):
    """

    """
    index_weight = 2
    po = models.ForeignKey(
        PurchaseOrder, on_delete=models.CASCADE,verbose_name=_("purchase order"))
    material = models.ForeignKey(Material, on_delete=models.CASCADE, verbose_name=_(
        "material"), limit_choices_to={"is_virtual": "0"})
    measure = models.ForeignKey(Measure, on_delete=models.CASCADE, verbose_name=_(
        "measure"), blank=True, null=True)
    price = models.DecimalField(_("price"),max_digits=12,decimal_places=4,blank=True,null=True)
    cnt = models.DecimalField(_("count"),max_digits=12,decimal_places=4,blank=True,null=True)
    discount_price = models.DecimalField(_("discount price"),max_digits=12,decimal_places=4,blank=True,null=True)
    amount = models.DecimalField(_("money of amount"),max_digits=12,decimal_places=2,blank=True,null=True)
    discount_amount = models.DecimalField(_("discount amount"),max_digits=12,decimal_places=2,blank=True,null=True)
    tax = models.CharField(_("tax rate"),max_length=const.DB_CHAR_CODE_6,choices=const.get_value_list('S052'),default='0.00')
    woitem = models.ForeignKey(WOItem, on_delete=models.CASCADE, verbose_name=_(
        "wo item"), blank=True, null=True)
    is_in_stock = models.BooleanField(_("is in stock"),default=0)
    in_stock_time = models.DateTimeField(_("execute time"),blank=True,null=True)
    entry_cnt = models.DecimalField(_("entry count"),max_digits=12,decimal_places=4,blank=True,null=True)
    left_cnt = models.DecimalField(_("left count"),max_digits=12,decimal_places=4,blank=True,null=True)

    def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None):
        if self.price and self.cnt:
            money = self.price * self.cnt
            self.amount = money

        if self.measure is None and self.material and self.material.measure.count() > 0:
            self.measure = self.material.measure.all()[0]

        if self.is_in_stock:
            self.left_cnt -= self.entry_cnt
        else:
            self.left_cnt = self.cnt
        super(POItem,self).save(force_insert,force_update,using,update_fields)
        self.material.purchase_price = self.price
        self.material.save()
        sql = 'UPDATE purchase_purchaseorder SET amount = (SELECT SUM(a.price*a.cnt) AS amount FROM ' \
                  'purchase_poitem a WHERE a.po_id = %s) WHERE id = %s'
        params = [self.po.id,self.po.id]
        generic.update(sql,params)

    def vender(self):
        return '%s' % (self.po.partner)

    vender.short_description = _("partner")

    class Meta:
        verbose_name = _("po item")
        verbose_name_plural = _("po item")
Ejemplo n.º 9
0
class EmployeeSalaryItem(models.Model):
    """

    """
    entry = models.ForeignKey(Entry,
                              verbose_name=_("employee entry"),
                              on_delete=models.deletion.CASCADE)
    employee = models.ForeignKey(Employee,
                                 verbose_name=_("employee"),
                                 blank=True,
                                 null=True,
                                 on_delete=models.deletion.CASCADE)
    salary_item = models.ForeignKey(SalaryItem,
                                    verbose_name=_("salary item"),
                                    on_delete=models.deletion.CASCADE)
    calculate_way = models.CharField(_("calculate way"),
                                     max_length=const.DB_CHAR_CODE_2,
                                     choices=const.get_value_list('S050'),
                                     default='10')
    fixed_value = models.DecimalField(_("fixed value"),
                                      blank=True,
                                      null=True,
                                      max_digits=10,
                                      decimal_places=2)
    base_value = models.DecimalField(_("base value"),
                                     blank=True,
                                     null=True,
                                     max_digits=10,
                                     decimal_places=2)
    org_percent = models.DecimalField(_("org percent"),
                                      blank=True,
                                      null=True,
                                      max_digits=4,
                                      decimal_places=2)
    employee_percent = models.DecimalField(_("employee percent"),
                                           blank=True,
                                           null=True,
                                           max_digits=4,
                                           decimal_places=2)

    class Meta:
        verbose_name = _("salary item")
        verbose_name_plural = _("salary item")
        unique_together = (('entry', 'salary_item'), )
Ejemplo n.º 10
0
class Position(generic.BO):
    """
    岗位
    """
    SERIES = (
        ('A',_("Admin Position")),
        ('S',_("Sale Position")),
        ('T',_("Technology Position")),
        ('P',_("Produce Position")),
    )

    GRADE = (
        ('01', _("BASIC")),
        ('02', _("MEDIUM")),
        ('03', _("SENIOR")),
        ('04', _("PROFESSOR")),
        ('05', _("EXPERT")),
    )
    index_weight = 3
    unit = models.ForeignKey(OrgUnit,verbose_name=_('org unit'))
    organization = models.ForeignKey(Organization,verbose_name=_('organization'),null=True,blank=True)
    parent = models.ForeignKey('self',verbose_name=_("parent"),null=True,blank=True)
    code = models.CharField(_("position code"),max_length=const.DB_CHAR_CODE_8,blank=True,null=True)
    name = models.CharField(_("position name"),max_length=const.DB_CHAR_NAME_120)
    short = models.CharField(_("short name"),max_length=const.DB_CHAR_NAME_20,blank=True,null=True)
    pinyin = models.CharField(_("pinyin"),max_length=const.DB_CHAR_NAME_120,blank=True,null=True)
    series = models.CharField(_("position series"),max_length=1,default='A',choices=const.get_value_list('S014'))
    grade =  models.CharField(_("position grade"),max_length=const.DB_CHAR_CODE_2,default='01',choices=const.get_value_list('S015'))
    virtual = models.BooleanField(_("is virtual"),default=False)
    status = models.BooleanField(_("in use"),default=True)
    description = models.TextField(_("position description"),blank=True,null=True)
    qualification = models.TextField(_("qualification"),blank=True,null=True)
    document = models.FileField(_("reference"),blank=True,null=True)
    weight = models.IntegerField(_("weight"),default=99)

    def __unicode__(self):
        return u'%s %s' % (self.code,self.name)

    class Meta:
        verbose_name = _('position')
        verbose_name_plural = _('position')
Ejemplo n.º 11
0
class Material(generic.BO):
    """
    物料
    """
    index_weight = 4
    code = models.CharField(_("material code"), max_length=const.DB_CHAR_NAME_20, blank=True, null=True)
    barcode = models.CharField(_("bar code"), max_length=const.DB_CHAR_NAME_40, blank=True, null=True)
    name = models.CharField(_("material name"), max_length=const.DB_CHAR_NAME_120)
    spec = models.CharField(_("specifications"), max_length=const.DB_CHAR_NAME_120, blank=True, null=True)
    pinyin = models.CharField(_("pinyin"), max_length=const.DB_CHAR_NAME_120, blank=True, null=True)
    brand = models.ForeignKey(Brand, blank=True, null=True, verbose_name=_("brand"))
    category = models.ForeignKey(Category, blank=True, null=True, verbose_name=_("category"))
    tp = models.CharField(_('mt type'), blank=True, null=True, max_length=const.DB_CHAR_CODE_2,
                          choices=const.get_value_list('S054'), default='10')
    status = models.BooleanField(_("in use"), default=True)
    is_equip = models.BooleanField(_("is equipment"), default=False)
    can_sale = models.BooleanField(_("can sale"), default=True)
    is_virtual = models.BooleanField(_("is virtual"), default=False)

    warehouse = models.ForeignKey(Warehouse, blank=True, null=True, verbose_name=_("warehouse"))
    measure = models.ManyToManyField(Measure, verbose_name=_("measure"))

    params = models.ManyToManyField(TechnicalParameterValue, verbose_name=_("technical parameter"),
                                    through='MaterialParam')

    stock_price = models.DecimalField(_("stock price"), max_digits=14, decimal_places=4, blank=True, null=True)
    purchase_price = models.DecimalField(_("purchase price"), max_digits=14, decimal_places=4, blank=True, null=True)
    sale_price = models.DecimalField(_("sale price"), max_digits=14, decimal_places=4, blank=True, null=True)
    org = models.ForeignKey(Organization, verbose_name=_("organization"), blank=True, null=True)

    def __unicode__(self):
        return "%s %s" % (self.code, self.name)

    class Meta:
        verbose_name = _('material')
        verbose_name_plural = _('material')
        ordering = ['tp', 'code']
Ejemplo n.º 12
0
class SaleOrder(generic.BO):
    """
    销售订单
    """
    STATUS = (
        ('0', _("NEW")),
        ('1', _("IN PROGRESS")),
        ('4', _("DROP")),
        ('9', _("APPROVED")),
        ('99', _("ALREADY STOCK OUT")),
    )
    index_weight = 2
    code = models.CharField(_("code"),
                            max_length=const.DB_CHAR_NAME_20,
                            blank=True,
                            null=True)
    partner = models.ForeignKey(Partner,
                                verbose_name=_("partner"),
                                limit_choices_to={"partner_type": "C"},
                                on_delete=models.deletion.CASCADE)
    order_date = models.DateField(_("order date"))
    deliver_date = models.DateField(_("deliver date"))
    org = models.ForeignKey(Organization,
                            verbose_name=_("organization"),
                            blank=True,
                            null=True,
                            on_delete=models.deletion.CASCADE)
    title = models.CharField(_("title"), max_length=const.DB_CHAR_NAME_40)
    description = models.TextField(_("memo"), blank=True, null=True)
    contact = models.CharField(_("contacts"),
                               max_length=const.DB_CHAR_NAME_20,
                               blank=True,
                               null=True)
    phone = models.CharField(_("phone"),
                             max_length=const.DB_CHAR_NAME_20,
                             blank=True,
                             null=True)
    fax = models.CharField(_("fax"),
                           max_length=const.DB_CHAR_NAME_20,
                           blank=True,
                           null=True)
    deliver_address = models.CharField(_("deliver address"),
                                       max_length=const.DB_CHAR_NAME_120,
                                       blank=True,
                                       null=True)
    invoice_type = models.CharField(_("invoice type"),
                                    max_length=const.DB_CHAR_CODE_6,
                                    choices=const.get_value_list('S053'),
                                    default='10')

    amount = models.DecimalField(_("money amount"),
                                 max_digits=12,
                                 decimal_places=2,
                                 blank=True,
                                 null=True,
                                 default=0.00)
    discount_amount = models.DecimalField(_("discount amount"),
                                          max_digits=12,
                                          decimal_places=2,
                                          blank=True,
                                          null=True,
                                          default=0.00)
    user = models.ForeignKey(User,
                             verbose_name=_("sales man"),
                             blank=True,
                             null=True,
                             on_delete=models.deletion.CASCADE)
    status = models.CharField(_("status"),
                              max_length=const.DB_CHAR_CODE_2,
                              default='0',
                              choices=STATUS)

    def __str__(self):
        return u'%s %s' % (self.code, self.title)

    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        super(SaleOrder, self).save(force_insert, force_update, using,
                                    update_fields)
        if self.discount_amount > 0:
            sql = 'UPDATE sale_saleitem a SET a.discount_price = a.sale_price - ' \
                  '((SELECT discount_amount/amount FROM sale_saleorder WHERE id = %s) * (a.sale_price*a.cnt)/a.cnt) WHERE a.master_id = %s'
            params = [self.id, self.id]
            generic.update(sql, params)

    def collection_amount(self):
        return PaymentCollection.objects.filter(so=self).aggregate(
            Sum('collection_amount')).get('collection_amount__sum') or 0.00

    collection_amount.short_description = _('collection amount')

    class Meta:
        verbose_name = _('sale order')
        verbose_name_plural = _('sale order')
Ejemplo n.º 13
0
class WorkOrder(generic.BO):
    """

    """
    index_weight = 1
    code = models.CharField(_("工单编号"),blank=True,null=True,max_length=const.DB_CHAR_CODE_10)
    refer = models.ForeignKey("self",verbose_name=_("refer wo"),blank=True,null=True)
    title = models.CharField(_("title"),max_length=const.DB_CHAR_NAME_120)
    description = models.TextField(_("description"),blank=True,null=True)
    business_domain = models.CharField(_("business domain"),max_length=const.DB_CHAR_CODE_4,choices=const.get_value_list('S045'),default='OT')
    classification = models.CharField(_("classification"),max_length=const.DB_CHAR_CODE_4,choices=const.get_value_list('S044'),default='D')
    service = models.ForeignKey(Material,verbose_name=_("service name"),null=True,blank=True,limit_choices_to={"is_virtual":"1"})
    project = models.ForeignKey(Project,verbose_name=_("project"),null=True,blank=True)
    status = models.CharField(_("status"),blank=True,null=True,default='NEW',max_length=const.DB_CHAR_CODE_6,choices=const.get_value_list('S046'))
    answer = models.TextField(_("answer"),blank=True,null=True)
    user = models.ForeignKey(User,verbose_name=_("user"),blank=True,null=True)
    attach = models.FileField(_('attach'),blank=True,null=True,help_text=u'工单附件,不导入明细。')
    detail = models.FileField(_('to be imported detail'),blank=True,null=True,help_text=u'您可导入需求明细,模板请参考文档FD0007')

    def __unicode__(self):
        return u"%s-%s" % (self.code,self.title)

    def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None):
        super(WorkOrder,self).save(force_insert,force_update,using,update_fields)
        if self.service:
            material = self.service
            if self.woextravalue_set.count() < 1 and material.extraparam_set and material.extraparam_set.count() > 0:
                for param in material.extraparam_set.all():
                    extra_param = WOExtraValue.objects.create(workorder=self,param_name=param)
                    self.woextravalue_set.add(extra_param)
        item_count = WOItem.objects.filter(workorder=self).count()
        if self.detail and item_count == 0:
            path = os.path.join(settings.MEDIA_ROOT,self.detail.name)
            workbook = xlrd.open_workbook(path)
            sheet = workbook.sheet_by_index(0)
            row_count = sheet.nrows
            with transaction.atomic():
                for row_index in range(row_count):
                    row = sheet.row_values(row_index)
                    if row_index == 0:
                        doc_type = row[1]
                        if doc_type.startswith('0'):
                            break
                        else:
                            continue
                    elif row_index < 3:
                        continue
                    material = None
                    measure = None
                    try:
                        measure = Measure.objects.get(code=row[4])
                    except Exception as e:
                        measure = Measure.objects.create(code=row[4],name=force_text(row[5]))
                    try:
                        material = Material.objects.get(code=row[0])
                    except Exception as e:
                        material = Material(code=row[0],name=force_text(row[1]),spec=force_text(row[2]))
                        material.save()
                    WOItem.objects.create(workorder=self,material=material,measure=measure,amount=row[6])

    class Meta:
        verbose_name = _("工单服务")
        verbose_name_plural = _("工单服务")

    class Media:
        js = ('js/workorder.js',)
Ejemplo n.º 14
0
class Employee(generic.BO):
    """
    职员信息
    """
    index_weight = 2
    code = models.CharField(_("employee number"),
                            max_length=const.DB_CHAR_NAME_20,
                            blank=True,
                            null=True)
    phone = models.CharField(_("phone"),
                             max_length=const.DB_CHAR_NAME_20,
                             blank=True,
                             null=True)
    organization = models.ForeignKey(Organization,
                                     verbose_name=_('organization'),
                                     null=True,
                                     blank=True,
                                     on_delete=models.deletion.PROTECT)
    name = models.CharField(_("employee name"),
                            max_length=const.DB_CHAR_NAME_120)
    pinyin = models.CharField(_("pinyin"),
                              max_length=const.DB_CHAR_NAME_120,
                              blank=True,
                              null=True)
    birthday = models.DateField(_("birthday"), blank=True, null=True)

    gender = models.CharField(_("gender"),
                              max_length=const.DB_CHAR_CODE_2,
                              choices=const.get_value_list('gender'),
                              default='1')
    idcard = models.CharField(_("id card"), max_length=const.DB_CHAR_NAME_20)

    country = models.CharField(_("nationality"),
                               max_length=const.DB_CHAR_CODE_2,
                               blank=True,
                               null=True,
                               default='CN',
                               choices=const.get_value_list('S022'))
    hometown = models.CharField(_("hometown"),
                                max_length=const.DB_CHAR_NAME_40,
                                blank=True,
                                null=True)
    address = models.CharField(_("home address"),
                               max_length=const.DB_CHAR_NAME_120,
                               blank=True,
                               null=True)
    banknum = models.CharField(_("bank account"),
                               max_length=const.DB_CHAR_NAME_40,
                               blank=True,
                               null=True)
    bankname = models.CharField(_("bank name"),
                                max_length=const.DB_CHAR_NAME_80,
                                blank=True,
                                null=True)
    emergency = models.CharField(_("emergency contacts"),
                                 max_length=const.DB_CHAR_NAME_40,
                                 blank=True,
                                 null=True)
    email = models.CharField(_("email"),
                             max_length=const.DB_CHAR_NAME_20,
                             blank=True,
                             null=True)
    office = models.CharField(_("office phone"),
                              max_length=const.DB_CHAR_NAME_20,
                              blank=True,
                              null=True)

    position = models.ForeignKey(Position,
                                 verbose_name=_('position'),
                                 on_delete=models.deletion.PROTECT)
    rank = models.CharField(_("employee rank"),
                            max_length=const.DB_CHAR_CODE_2,
                            default='00',
                            choices=const.get_value_list('S017'))

    workday = models.DateField(_("workday"), blank=True, null=True)
    startday = models.DateField(_("start date"), blank=True, null=True)

    religion = models.CharField(
        _("religion"),
        max_length=const.DB_CHAR_CODE_2,
        default='00',
        choices=const.get_value_list('S020'),
        blank=True,
        null=True,
    )
    marital = models.CharField(_("marital status"),
                               max_length=const.DB_CHAR_CODE_2,
                               blank=True,
                               null=True,
                               choices=const.get_value_list('S023'),
                               default='10')

    party = models.CharField(_("political party"),
                             max_length=const.DB_CHAR_CODE_2,
                             blank=True,
                             null=True,
                             choices=const.get_value_list('S026'),
                             default='13')
    nation = models.CharField(_("nation"),
                              max_length=const.DB_CHAR_CODE_2,
                              blank=True,
                              null=True,
                              choices=const.get_value_list('S021'),
                              default='01')

    ygxs = models.CharField(_("employ ygxs"),
                            max_length=const.DB_CHAR_CODE_2,
                            blank=True,
                            null=True,
                            choices=const.get_value_list('S019'),
                            default='2')
    status = models.CharField(_("employ status"),
                              max_length=const.DB_CHAR_CODE_2,
                              blank=True,
                              null=True,
                              choices=const.get_value_list('S016'),
                              default='10')
    category = models.CharField(_("employ category"),
                                max_length=const.DB_CHAR_CODE_2,
                                blank=True,
                                null=True,
                                choices=const.get_value_list('S018'),
                                default='21')

    literacy = models.CharField(_("literacy"),
                                max_length=const.DB_CHAR_CODE_2,
                                default='10',
                                choices=const.get_value_list('S024'),
                                blank=True,
                                null=True)
    major = models.CharField(_("major type"),
                             max_length=const.DB_CHAR_CODE_2,
                             blank=True,
                             null=True,
                             choices=const.get_value_list('S038'),
                             default='99')
    degree = models.CharField(_("major degree"),
                              max_length=const.DB_CHAR_CODE_2,
                              blank=True,
                              null=True,
                              choices=const.get_value_list('S037'),
                              default='4')

    spjob = models.CharField(_("special job"),
                             max_length=const.DB_CHAR_CODE_2,
                             blank=True,
                             null=True,
                             choices=const.get_value_list('S042'),
                             default='00')
    health = models.CharField(_("health"),
                              max_length=const.DB_CHAR_CODE_2,
                              blank=True,
                              null=True,
                              choices=const.get_value_list('S043'),
                              default='1')

    tag1 = models.CharField(_("tag1 fzjr"),
                            max_length=const.DB_CHAR_CODE_2,
                            blank=True,
                            null=True,
                            choices=const.get_value_list('S039'),
                            default='99')
    tag2 = models.CharField(_("tag2 dwld"),
                            max_length=const.DB_CHAR_CODE_2,
                            blank=True,
                            null=True,
                            choices=const.get_value_list('S040'),
                            default='9')
    tag3 = models.CharField(_("tag3 dsjs"),
                            max_length=const.DB_CHAR_CODE_2,
                            blank=True,
                            null=True,
                            choices=const.get_value_list('S041'),
                            default='00')
    tag4 = models.CharField(_("tag4 byzk"),
                            max_length=const.DB_CHAR_CODE_2,
                            blank=True,
                            null=True,
                            choices=const.get_value_list('S027'),
                            default='0')

    user = models.ForeignKey(User,
                             verbose_name=_("user"),
                             blank=True,
                             null=True,
                             on_delete=models.deletion.PROTECT)

    def age(self):
        import datetime
        if self.birthday:
            cnt = datetime.date.today().year - self.birthday.year
            return cnt

    def work_age(self):
        import datetime
        if self.birthday and self.workday:
            cnt = datetime.date.today().year - self.workday.year
            return cnt

    def __str__(self):
        return u'%s %s' % (self.code, self.name)

    age.short_description = u'年龄'
    work_age.short_description = u'工龄'

    class Meta:
        verbose_name = _("employee")
        verbose_name_plural = _("employee")
        # 权限
        permissions = (('view_all_employee', _("view all employee")), )