save

async AsyncJournalModel.save(head_df, line_df, callback=None, relation_field='journal_id', enable_create=True, enable_default_value=True, enable_repeat_check=True, enable_required=True, enable_valid_range=True, enable_all_errors=True, enable_need_one_line=True, sync=True)

凭证模型数据保存

参数
  • head_df (DataFrame) – 凭证头表的数据(字段名与凭证模型上头表的字段名对应)

  • line_df (DataFrame) – 凭证行表的数据(字段名与凭证模型上行表的字段名对应)

  • callback (Union[Dict, JournalModelExecCallbackPythonDTO, None]) – 回调脚本配置信息 若为None,则保存模型数据在结束后不会调用脚本, 如果配置了回调,则不论保存是否保存成功,都将在结束后调用回调该脚本

  • relation_field (str) – 用于指定凭证头、行表的关联字段, 即通过该字段确定凭证头表对应的凭证行表数据,默认为journal_id

  • enable_create (bool) – 是否启用创建人、创建时间自动赋值,默认为True

  • enable_default_value (bool) – 是否启用字段值为空时使用默认值填充,默认为True

  • enable_repeat_check (bool) – 是否启用业务主键重复的校验,默认为True

  • enable_required (bool) – 是否启用必填字段的校验,默认为True

  • enable_valid_range (bool) – 是否启用有效性范围的校验,默认为True

  • enable_all_errors (bool) – 是否启用一次性校验所有规则和数据,默认为True

  • enable_need_one_line (bool) – 是否启用凭证行表至少需要一条数据的校验,默认为True

  • sync (bool) – 调用模型数据保存接口的类型,同步(True)/异步(False),默认为同步 异步保存接口会在收到保存请求时立刻响应,同步保存 接口会等保存数据完成后才响应,并返回保存信息 如果设置为同步,当数据量过大时可能会时间过长时,可能因超出SDK的接口响应超时时间而报错

返回类型

CommonResultDTO

返回

调用同步接口时返回信息(CommonResultDTO的success为true 表示成功,如false 则错误在errors集合里)

示例

1.以自定义数据选取参数执行

# 凭证头表数据(注:_type的值必须对应模型配置的凭证类型代码,
# journal_id的值在下面的行表中必须有对应的数据)
head_df = pd.DataFrame([
    {
      "_type": "type_account_01", "journal_id": "head_main_id_202306080001",
      "is_balance": "true", "scenario": "Actual", "version": "Working",
      "value": "CNY", "entity": "[TotalEntity].[A]", "year": "2023",
      "period": "12", "approve_time": "2023-05-23 15:56:00",
      "convert_date": "2023-05-23"
    },
    {
      "_type": "type_account_01", "journal_id": "head_main_id_202306080002",
      "is_balance": "true", "scenario": "Actual","version": "Working",
      "value": "CNY","entity": "[TotalEntity].[A]", "year": "2023",
      "period": "12", "approve_time": "2023-05-23 15:56:00",
      "convert_date": "2023-05-23"
    }
])

# 凭证行表数据(注:行表中的 journal_id 的值必须在头表数据中存在,line_no 不允许重复)
line_df = pd.DataFrame([
    {
      "journal_id": "head_main_id_202306080001",
      "line_no": "1","account": "100101","movement": "OPN",
      "trx_debit": "130","debit": "130","comment_line": "line1"
    },
    {
      "journal_id": "head_main_id_202306080001",
      "line_no": "2","account": "100101","movement": "OPN",
      "trx_credit": "130","credit": "130","comment_line": "line2"
    },
    {
      "journal_id": "head_main_id_202306080002",
      "line_no": "1","account": "100101","movement": "OPN",
      "trx_debit": "130","debit": "130","comment_line": "line1"
    },
    {
      "journal_id": "head_main_id_202306080002",
      "line_no": "2", "account": "100101","movement": "OPN",
      "trx_credit": "130","credit": "130","comment_line": "line2"
    }
])

# 回调脚本
callback_info = {
    "elementName": "testPy01", "elementType": "PY",
    "path": "/zhy_test",
    "callbackParams": {"year": "2023", "period": "03"}
}
# 创建凭证组件元素对象
journal = JournalModel('ZHY_TEST_0613_02')
# 调用保存
res = journal.save(
    head_df=head_df,
    line_df=line_df,
    callback=callback_info,
    enable_create = True,
    enable_default_value = False,
    enable_repeat_check= True,
    enable_required= False,
    enable_valid_range= True,
    enable_all_errors = True,
    enable_need_one_line = True,
    sync=True
)

注意

以示例的回调参数为例,回调脚本接收到参数为


# 凭证组件V1.0.6.3版本以前

p2 = {

“batch_id”: “b14d943609b”, “success”: True, “year”: “2023”, # 自定义参数 “period”: “03” # 自定义参数

}

# 凭证组件V1.0.6.3版本及以后

p2 = {
“mainKey”: {
“journal_id”: [

“ZDlhYj”, “ZWU00005”, “ZjY4MG”, “NWQ00002”, “ZTl00003”, “NmNiNW”, “YWM5ZG”, “M2E00004”

]

}, “success”: True, “year”: “2023”, # 自定义参数 “period”: “03” # 自定义参数

}