我正在使用 Zoho Books API 创建采购订单
(https://www.zoho.com/books/api/v3/#Purchase-Order_Create_a_purchase_order)- _
唯一需要的项目似乎是vendor_id
和line_items
。但是,在创建工作后,我收到以下消息:
ZohoBooks::BadRequestError: Purchase order cannot be created for a non-purchase item.
这是代码:
```
class CreatePurchaseOrderJob < ApplicationJob
queue_as :default
def perform(order_id)
@order = SupplierOrder.find(order_id)
create_purchase_order
end
private
attr_reader :order
def vendor
name = order.supplier.name
books.get_contact_with_options(contact_type: :vendor, contact_name: name)
end
def create_purchase_order
payload = {
vendor_id: vendor['contact_id'],
purchaseorder_number: order.reference,
reference_number: order.reference,
line_items: line_items
}
books.create_purchase_order(payload)
end
def line_items
order.rfq_line_item_prices.order(:id).map do |price|
line_item(price)
end
end
def line_item(price)
{
name: price.current_line_item.shape,
description: price.current_line_item&.name,
bcy_rate: price.unit_price.to_f,
rate: price.unit_price.to_f,
quantity: price.current_line_item.quantity,
tax_id: Registry.zoho_vat_tax_id,
item_custom_fields: [
{ label: 'Grade', value: price.current_line_item&.grade },
{ label: 'Finish', value: price.current_line_item&.finish },
{ label: 'Dimensions', value: price.current_line_item&.dimensions }
]
}
end
def books
@books ||= Registry.books
end
end
这是我们用来制作发票的相同代码并且有效,所以我错过了一些神奇的东西,让 Zoho 知道这是一个购买项目,没有任何迹象表明它可能是什么。我通过聊天询问并得到以下信息: The reason why you're getting this error message is because, You can create a purchase order only when you add the purchase info for an item.