resources.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. from import_export import resources
  4. from import_export.fields import Field
  5. from apps.base import ExcelImporter
  6. class SupplierResource(resources.Resource):
  7. def __init__(self):
  8. super(SupplierResource, self).__init__()
  9. self.fields['name'] = Field(attribute='name')
  10. self.fields['type_text'] = Field(attribute='type_text')
  11. self.fields['contacts'] = Field(attribute='contacts')
  12. self.fields['phone_number'] = Field(attribute='phone_number')
  13. self.fields['address'] = Field(attribute='address')
  14. self.fields['opening_bank'] = Field(attribute='opening_bank')
  15. self.fields['account'] = Field(attribute='account')
  16. self.fields['tax_number'] = Field(attribute='tax_number')
  17. self.fields['credit_code'] = Field(attribute='credit_code')
  18. self.fields['enabled_text'] = Field(attribute='enabled_text')
  19. self.fields['notes'] = Field(attribute='notes')
  20. def get_export_headers(self):
  21. return [u'名称', u'类别', u'联系人', u'电话', u'地址', u'开户行', u'账号', u'税号', u'信用代码', u'可用', u'备注']
  22. class Meta:
  23. export_order = ('name', 'type_text', 'contacts', 'phone_number', 'address', 'opening_bank', 'account', 'tax_number', 'credit_code', 'enabled_text', 'notes')
  24. class SupplierImporter(ExcelImporter):
  25. fields = {
  26. u'名称': (True, ExcelImporter.formatUnicode),
  27. u'类别': (True, ExcelImporter.formatUnicode),
  28. u'联系人': (False, ExcelImporter.formatUnicode),
  29. u'电话': (False, ExcelImporter.formatTel),
  30. u'地址': (False, ExcelImporter.formatUnicode),
  31. u'开户行': (False, ExcelImporter.formatUnicode),
  32. u'账号': (False, ExcelImporter.formatUnicode),
  33. u'信用代码': (False, ExcelImporter.formatUnicode),
  34. u'税号': (False, ExcelImporter.formatUnicode),
  35. u'备注': (False, ExcelImporter.formatUnicode),
  36. }