"code": "6140" 重复文档编号错误

"code": "6140" Duplicate Document Number Error

我正在使用 QuickBooks。不知何故,我在创建一张发票时遇到了一些奇怪的错误。

{
    "Fault": {
        "Error": [
            {
                "Message": "Duplicate Document Number Error",
                "Detail": "Duplicate Document Number Error : You must specify a different number. This number has already been used. DocNumber=O0010714 is assigned to TxnType=Invoice with TxnId=45823",
                "code": "6140",
                "element": ""
            }
        ],
        "type": "ValidationFault"
    },
    "time": "2020-12-15T04:54:25.476-08:00"
}

为什么会发生这种情况,因为 QuickBooks 中没有说明文档编号是唯一实体的文档。

简短版本: DocNumber 在大多数情况下应该是唯一的。在某些情况下,您可以在 URL 中添加 include=allowduplicatedocnum arg 以允许这样做。请注意,DocNumber 可以自动生成。

长版: 摘自 DocNumber field documentation for Invoice

Reference number for the transaction. If not explicitly provided at create time, this field is populated based on the setting of Preferences:CustomTxnNumber as follows:

  • If Preferences:CustomTxnNumber is true a custom value can be provided.
    If no value is supplied, the resulting DocNumber is null.
  • If Preferences:CustomTxnNumber is false, resulting DocNumber is system generated by incrementing the last number by 1.

If Preferences:CustomTxnNumber is false then do not send a value as it can lead to unwanted duplicates. If a DocNumber value is sent for an Update operation, then it just updates that particular invoice and does not alter the internal system DocNumber.

Note: DocNumber is an optional field for all locales except France. For France locale if Preferences:CustomTxnNumber is enabled it will not be automatically generated and is a required field. If a duplicate DocNumber needs to be supplied, add the query parameter name/value pair, include=allowduplicatedocnum to the URI.

P.S。回复晚了,但可能对以后的人有用。

更新: 看起来来自 npm node quickbooks 的库本身不支持它。因为 method createBill doesn't allow to provide any params to URI. Even method module.create 只是硬编码了 url 变量,无法提供任何额外的东西。

在这种情况下,如果您仍然想使用include=allowduplicatedocnum,您有以下选择:

  • monkey-patch 这个库;
  • 创建分支并进行更新;
  • 请该库的作者代替您实现它;
  • 找到一个支持它的库;
  • 从您的代码向 QBO 发送原始请求。