Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Shopify] Connector - Export Posted Sales Invoices to Shopify as Orde…
…rs (#26748) This pull request does not have a related issue as it's part of the delivery for development agreed directly with [@AndreiPanko](https://github.com/AndreiPanko) Here's a quick summary: ### Created a report to export Posted Sales Invoices to Shopify as Orders. Shopify Shop has a **new action "Payment Terms Mapping"** that takes the user to the **new page "Shopify Payment Terms Mapping"**. Shopify Payment Terms cannot be manually inserted or deleted, they can only be refreshed with an action that pulls them from Shopify. By default **FIXED** Payment Term is selected as primary during the synchronization of the Payment Terms. Before Posted Sales Invoices can be synced, a payment term code from Shopify needs to be mapped to the Business Central one or a primary Shopify Payment Term needs to be selected with a Boolean "Is Primary" - this payment term will be used if the Posted Sales Invoice payment terms code doesn't have a mapping to Shopify. This payment term code will also be filled during the sync of Shopify orders. A new Scope is required. To update payment terms on a draft order – write_payment_terms (read_payment_terms scope was removed because it causes strange behavior - every time a Shopify shop card is opened it states that the scope has changed and requires authorization. write_payment_terms overwrites read_payment_terms). To create a draft order - write_draft_orders. ### To export Posted Sales Invoices, here are some conditions that they need to meet: - The **new Boolean field "Posted Invoice Sync"** needs to be enabled. - The "Shopify Order Id" field on the Posted Sales Invoice needs to be 0. - Posted Sales Invoice "Bill-To Customer" has been mapped to the Shopify Customer or Shopify Companies table. - Posted Sales Invoice "Bill-To Customer" is not a customer used as a Default Customer in the Shopify Shop Card or Shopify Customer Template. - There are no lines of type non-comment (or type is populated but No. is empty). - There are no fraction quantities. - There must be a mapped Payment Terms Code or a selected Primary Payment Terms Code on the new "Shopify Payment Terms Mapping" page. - If there is at least one line of type "Item" where the selected item/variant doesn’t have a link to Shopify Product/Shopify variant and the **new Boolean field "Items must be mapped to Products"** on the Shopify Shop card is selected - the Posted Sales Invoice will not be exported. - Posted Sales Invoice currency code matches Shopify shop currency code (explanation at the bottom). If one of the previous conditions is not met, the Posted Sales Invoice "Shopify Order Id" field will be marked with -2. If the GraphQL request fails, then the field will be marked with -1. If everything goes correctly, the field will be filled with the created Shopify Order ID. Users can modify the "Shopify Order Id" field in the posted document (allowed changes from -1 or -2 to 0. The functionality works the same as in the Update Posted Shipment document.) This export can be executed with a new action that is added to Shopify Shop - "Sync Posted Sales Invoices" or just by running the report "Sync Invoices to Shopify". The draft order in Shopify is created with the values from the Posted Sales Invoice order and lines. If the Remaining Amount of the Posted Sales Invoice is 0, then the order is marked as paid, otherwise, the status will be "Payment pending" and a mapped Payment Terms code will be sent out. After that, the created draft order will be completed and the Shopify order created. All orders are automatically fulfilled. To achieve “paid” status on the Shopify order – use the Manual payment function in the Shopify Order card. Once the report is executed, the Inventory will be synced. Order sync will import created orders, then check if the order is present in the **new Shopify Invoice Header table** (this table is filled with the Shopify order ID of the exported Posted Sales Invoice) and if so: - Shopify Order is marked as processed. - A link is added to the Posted Sales Invoice (related documents). ### A few details about the mapping of the values and some additional functionality: - All non-comment type lines are exported as custom products (including Items if the new Boolean field "Items must be mapped to Products"** on the Shopify Shop card is not selected). - Taxes from the lines are sent out as a custom product with the title consisting of "VAT Calculation Type" + VAT %. - Invoice discounts from the lines and the header are added up and sent out as a discount to the whole order with the title "Invoice Discount Amount" - Posted Sales Invoice comments are exported as notes. - Once the draft order is completed, an order confirmation email will be sent out to the customer. This functionality is from Shopify itself. - If the product/variant exists in Shopify, the price, title and other information will be taken from Shopify and not the one in the Posted Sales Invoice line. This is how the draftOrderCreate mutation works. ### Out of scope functionalities: - Open orders and open invoices. - Fulfillment/Tracking Details. - Refund / partial refund status. - Weight export. **Known issues with different currencies (that's why Posted Sales Invoices with different currencies than Shopify Shop cannot be exported at the moment):** - Currently sending out different currencies than the Shopify Shop currency cannot be done because if the currency of the custom product differs from the Shopify shop's currency, the amount sent will still be accepted in the local Shopify shop's currency before being converted to the order's currency and the amount will be incorrect. For example, if the VAT amount is 100 GBP, but the Shopify shop's currency is EUR, the custom product will be exported with an amount of 100 GBP. However, this amount will be treated as 100 EUR and then converted to GBP according to the currency exchange rate in Shopify. Fixes #26819 Fixes [AB#446399](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/446399) --------- Co-authored-by: Jesper Schulz-Wedde <[email protected]> Co-authored-by: Tine Staric <[email protected]>
- Loading branch information