microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
773 stars 610 forks source link

[Shopify] Connector - Export Posted Sales Invoices to Shopify as Orders #26748

Closed GediminasGaubys closed 1 month ago

GediminasGaubys commented 3 months ago

This pull request does not have a related issue as it's part of the delivery for development agreed directly with @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:

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:

A few details about the mapping of the values and some additional functionality:

Out of scope functionalities:

Known issues with different currencies (that's why Posted Sales Invoices with different currencies than Shopify Shop cannot be exported at the moment):

Fixes #26819 Fixes AB#446399

JesperSchulz commented 2 months ago

@GediminasGaubys, could you agree to the CLA? @tinestaric for info.

GediminasGaubys commented 2 months ago

@microsoft-github-policy-service agree company="Companial"

JesperSchulz commented 1 month ago

@GediminasGaubys / @tinestaric, I've pushed all latest changes to ALAppExtensions. As we had quite a few open Shopify PRs in parallel, there were some merge conflicts. Most seem to be resolved, except for ID clashes. The ones added in this PR all seem to have been taken now. Could you re-ID with free IDs? Feel free to extend the range, if no IDs in the existing range are available.

tinestaric commented 1 month ago

@JesperSchulz I assigned the same IDs you specified and resolved the remaining ID conflicts (Table Shpfy Payment Terms and report Shpfy Sync Invoices to Shpfy were still conflicting). The new ID Range is now 30100..30370