# -*- coding: utf-8 -*-
from __future__ import absolute_import

from import_export import resources
from import_export.fields import Field
from apps.base import ExcelImporter


class CustomerResource(resources.Resource):

    def __init__(self):
        super(CustomerResource, self).__init__()
        self.fields['name'] = Field(attribute='name')
        self.fields['mobile'] = Field(attribute='mobile')
        self.fields['company_name'] = Field(attribute='company_name')
        self.fields['company_tel'] = Field(attribute='company_tel')
        self.fields['opening_bank'] = Field(attribute='opening_bank')
        self.fields['account'] = Field(attribute='account')
        self.fields['credit_code'] = Field(attribute='credit_code')
        self.fields['address'] = Field(attribute='address')
        self.fields['notes'] = Field(attribute='notes')
        self.fields['create_time'] = Field(attribute='create_time')
        self.fields['create_user_text'] = Field(attribute='create_user_text')


    def get_export_headers(self):
        return [u'姓名', u'手机', u'公司名称', u'公司电话', u'开户行', u'账号', u'信用代码', u'地址', u'备注', u'创建时间', u'创建人']

    class Meta:
        export_order = ('name', 'mobile', 'company_name', 'company_tel', 'opening_bank', 'account', 'credit_code', 'address', 'notes', 'create_time', 'create_user_text')


class CustomerImporter(ExcelImporter):
    fields = {
        u'姓名': (True, ExcelImporter.formatUnicode),
        u'手机号': (True, ExcelImporter.formatTel),
        u'公司名称': (False, ExcelImporter.formatUnicode),
        u'公司电话': (False, ExcelImporter.formatTel),
        u'开户行': (False, ExcelImporter.formatUnicode),
        u'账号': (False, ExcelImporter.formatUnicode),
        u'信用代码': (False, ExcelImporter.formatUnicode),
        u'地址': (False, ExcelImporter.formatUnicode),
        u'备注': (False, ExcelImporter.formatUnicode),
    }