Commit 178a7866 by liyijie

import do not assign headers in initialize

parent db15a199
......@@ -6,14 +6,14 @@ module TalltyImportExport
end
module ClassMethods
def model_headers
def model_headers **args
columns.map do |column|
{
key: column.name,
name: column.comment || column.name,
attr_type: column.type,
format: column.type == :string ? :string : nil,
primary_key: column.name == 'id' ? true : false
primary_key: column.name == 'id' ? true : false
}
end
end
......
......@@ -26,6 +26,7 @@ module TalltyImportExport
# chain: 导出时对象属性通过链式调用
# index: 数组方式,需要嵌套拿到里面的
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
# json: model_payload,代表存储在某一个列中
def export_xlsx records, **options
records = with_scope records
......
module TalltyImportExport
class Import
require 'roo'
attr_reader :klass, :context, :headers, :primary_keys, :associations
attr_reader :klass, :context, :primary_keys, :associations
def initialize klass
@klass = klass
@headers = import_headers_result.map { |header| header.with_indifferent_access }
@context = Context.new({})
end
......@@ -15,6 +14,7 @@ module TalltyImportExport
# format: excel是否需要特定的格式,目前主要是类似于身份证号,可以用string
# convert: 导入时候,把excel的内容转换成导入时候代码逻辑需要的内容
# primary_key: 是否是主键
# json: model_payload,代表存储在某一个列中
# xlsx_file 为 file path or file object or TalltyImportExport::Excel.new
def import_xlsx xlsx_file, associations, **options
......@@ -101,7 +101,7 @@ module TalltyImportExport
end
def import_headers **args
@headers || klass.try(:import_headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers'))
@headers || klass.try(:headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers'))
end
# 只保留 key, name, json, 合并到 import_header
......
module TalltyImportExport
VERSION = "1.0.4"
VERSION = "1.0.5"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment