# -*- 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 SupplierResource(resources.Resource):

    def __init__(self):
        super(SupplierResource, self).__init__()
        self.fields['name'] = Field(attribute='name')
        self.fields['type_text'] = Field(attribute='type_text')
        self.fields['contacts'] = Field(attribute='contacts')
        self.fields['phone_number'] = Field(attribute='phone_number')
        self.fields['address'] = Field(attribute='address')
        self.fields['opening_bank'] = Field(attribute='opening_bank')
        self.fields['account'] = Field(attribute='account')
        self.fields['tax_number'] = Field(attribute='tax_number')
        self.fields['credit_code'] = Field(attribute='credit_code')
        self.fields['enabled_text'] = Field(attribute='enabled_text')
        self.fields['notes'] = Field(attribute='notes')

    def get_export_headers(self):
        return [u'名称', u'类别',  u'联系人', u'电话', u'地址', u'开户行', u'账号', u'税号', u'信用代码', u'可用', u'备注']

    class Meta:
        export_order = ('name', 'type_text', 'contacts', 'phone_number', 'address', 'opening_bank', 'account', 'tax_number', 'credit_code', 'enabled_text', 'notes')



class SupplierImporter(ExcelImporter):
    fields = {
        u'名称': (True, ExcelImporter.formatUnicode),
        u'类别': (True, ExcelImporter.formatUnicode),
        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),
        u'备注': (False, ExcelImporter.formatUnicode),
    }