diff --git a/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfyInventoryAPI.Codeunit.al b/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfyInventoryAPI.Codeunit.al index 233034fe0c..099e78848d 100644 --- a/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfyInventoryAPI.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfyInventoryAPI.Codeunit.al @@ -121,7 +121,7 @@ codeunit 30195 "Shpfy Inventory API" ShopInventory.Delete(); end; - internal procedure ExportStock(var ShopInventory: Record "Shpfy Shop Inventory") + internal procedure ExportStock(var ShopInventory: Record "Shpfy Shop Inventory"; ForceExport: Boolean) var IGraphQL: Interface "Shpfy IGraphQL"; JGraphQL: JsonObject; @@ -135,7 +135,7 @@ codeunit 30195 "Shpfy Inventory API" JQuantities := JsonHelper.GetJsonArray(JGraphQL, 'variables.input.quantities'); repeat - JQuantity := CalcStock(ShopInventory); + JQuantity := CalcStock(ShopInventory, ForceExport); if JQuantity.Keys.Count = 4 then begin JQuantities.Add(JQuantity); InputSize += 1; @@ -204,7 +204,7 @@ codeunit 30195 "Shpfy Inventory API" SkippedRecord.LogSkippedRecord(EmptyRecordId, CopyStr(StrSubstNo(SkippedMsg, ErrorCode), 1, 250), ShopifyShop); end; - local procedure CalcStock(var ShopInventory: Record "Shpfy Shop Inventory") JQuantity: JsonObject + local procedure CalcStock(var ShopInventory: Record "Shpfy Shop Inventory"; ForceExport: Boolean) JQuantity: JsonObject var Item: Record Item; DelShopInventory: Record "Shpfy Shop Inventory"; @@ -227,7 +227,7 @@ codeunit 30195 "Shpfy Inventory API" if not (Item.Type in [Item.Type::"Non-Inventory", Item.Type::Service]) then begin ShopInventory.Validate(Stock, Round(GetStock(ShopInventory), 1, '<')); ShopInventory.Modify(); - if ShopInventory.Stock <> ShopInventory."Shopify Stock" then + if (ShopInventory.Stock <> ShopInventory."Shopify Stock") or ForceExport then if ShopLocation.Get(ShopInventory."Shop Code", ShopInventory."Location Id") then begin IStockAvailable := ShopLocation."Stock Calculation"; if IStockAvailable.CanHaveStock() then begin diff --git a/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfySyncInventory.Codeunit.al b/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfySyncInventory.Codeunit.al index 3eeac26b83..ef5dccbfd2 100644 --- a/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfySyncInventory.Codeunit.al +++ b/src/Apps/W1/Shopify/App/src/Inventory/Codeunits/ShpfySyncInventory.Codeunit.al @@ -15,28 +15,39 @@ codeunit 30197 "Shpfy Sync Inventory" var InventoryApi: Codeunit "Shpfy Inventory API"; + SkipImport: Boolean; trigger OnRun() var ShopInventory: Record "Shpfy Shop Inventory"; ShopLocation: Record "Shpfy Shop Location"; + ShpfyInventoryEvents: Codeunit "Shpfy Inventory Events"; ShopFilter: Text; + VariantIdFilter: Text; begin ShopFilter := Rec.GetFilter("Shop Code"); - if ShopFilter <> '' then begin + if ShopFilter <> '' then ShopLocation.SetRange("Shop Code", ShopFilter); - ShopInventory.SetRange("Shop Code", ShopFilter); - end; - ShopLocation.SetFilter("Stock Calculation", '<>%1', ShopLocation."Stock Calculation"::Disabled); - if ShopLocation.FindSet(false) then begin - InventoryApi.SetShop(ShopLocation."Shop Code"); - InventoryApi.SetInventoryIds(); - repeat - InventoryApi.ImportStock(ShopLocation); - until ShopLocation.Next() = 0; + + ShopInventory.CopyFilters(Rec); + + if not SkipImport then begin + ShopLocation.SetFilter("Stock Calculation", '<>%1', ShopLocation."Stock Calculation"::Disabled); + if ShopLocation.FindSet(false) then begin + InventoryApi.SetShop(ShopLocation."Shop Code"); + InventoryApi.SetInventoryIds(); + repeat + InventoryApi.ImportStock(ShopLocation); + until ShopLocation.Next() = 0; + end; + InventoryApi.RemoveUnusedInventoryIds(); end; - InventoryApi.RemoveUnusedInventoryIds(); - InventoryApi.ExportStock(ShopInventory); + InventoryApi.ExportStock(ShopInventory, SkipImport); + end; + + internal procedure SetSkipImport(ImportSkip: Boolean) + begin + SkipImport := ImportSkip; end; } \ No newline at end of file diff --git a/src/Apps/W1/Shopify/App/src/Inventory/Reports/ShpfySyncStockToShopify.Report.al b/src/Apps/W1/Shopify/App/src/Inventory/Reports/ShpfySyncStockToShopify.Report.al index 4ece7ef5ae..b7e1dd9a8c 100644 --- a/src/Apps/W1/Shopify/App/src/Inventory/Reports/ShpfySyncStockToShopify.Report.al +++ b/src/Apps/W1/Shopify/App/src/Inventory/Reports/ShpfySyncStockToShopify.Report.al @@ -24,12 +24,45 @@ report 30102 "Shpfy Sync Stock to Shopify" trigger OnAfterGetRecord() var ShopifyShopInventory: Record "Shpfy Shop Inventory"; + ShpfySyncInventory: Codeunit "Shpfy Sync Inventory"; begin ShopifyShopInventory.Reset(); ShopifyShopInventory.SetRange("Shop Code", Shop.Code); - CodeUnit.Run(Codeunit::"Shpfy Sync Inventory", ShopifyShopInventory); + + if VariantIdFilter <> '' then + ShopifyShopInventory.SetFilter("Variant ID", VariantIdFilter); + + ShpfySyncInventory.SetSkipImport(SkipImport); + ShpfySyncInventory.Run(ShopifyShopInventory); end; } } + requestpage + { + layout + { + area(content) + { + group(Group) + { + Caption = 'Options'; + field(SkipImport; SkipImport) + { + Caption = 'Skip Import Stock'; + ToolTip = 'Specifies whether to skip importing stock from Shopify before exporting stock to Shopify.'; + } + field(VariantIdFilter; VariantIdFilter) + { + Caption = 'Variant ID Filter'; + ToolTip = 'Specifies a filter for the Variant ID to limit which inventory items are synchronized.'; + } + } + } + } + } + + protected var + VariantIdFilter: Text; + SkipImport: Boolean; } \ No newline at end of file