Create invoice from 2 salesorders with custom function
Hello,
We want to make a custom function that, when a customer has 2 or more sales orders, create only one invoice instead of 2 (we have a workflow to create invoices automatically from sales orders that have been sent).
I have been investigating the API documentation and I am not sure how to approach this. The main problem is that I dont see how to link more than one sales order to a invoice when I am creating it.
When I retrieve an invoice created from 2 sales orders the JSON has only two fields: salesorder_id and salesorder_number, but they are from only one invoice despite it was created in Books from 2 sales orders. After those fields there is a Map called salesorders with the info of the 2 that belong to that invoice. What are the rules about this structure? Which fields are mandatory and which not? Can I create a JSON with this structure and create an invoice with it?
- "salesorder_id": "81921000005055258",
- "salesorder_number": "SO-04871",
- "salesorders": [
- {
- "salesorder_id": "81921000005055258",
- "salesorder_number": "SO-04871",
- "reference_number": "",
- "salesorder_order_status": "open",
- "order_sub_status": "",
- "order_sub_status_id": "",
- "total": 561.68,
- "sub_total": 578,
- "date": "2021-03-02",
- "shipment_date": "2021-03-12"
- },
- {
- "salesorder_id": "81921000005055280",
- "salesorder_number": "SO-04872",
- "reference_number": "",
- "salesorder_order_status": "closed",
- "order_sub_status": "",
- "order_sub_status_id": "",
- "total": 82.21,
- "sub_total": 578,
- "date": "2021-03-10",
- "shipment_date": ""
- }