Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading