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 @@ -123,6 +123,8 @@ codeunit 30174 "Shpfy Create Product"
TempShopifyVariant.SKU := GetVariantSKU(TempShopifyVariant.Barcode, Item."No.", ItemVariant.Code, Item."Vendor Item No.");
TempShopifyVariant.Taxable := true;
TempShopifyVariant.Weight := ItemUnitofMeasure."Qty. per Unit of Measure" > 0 ? Item."Gross Weight" * ItemUnitofMeasure."Qty. per Unit of Measure" : Item."Gross Weight";
TempShopifyVariant."Tariff No." := Item."Tariff No.";
TempShopifyVariant."Country/Region of Origin Code" := ProductExport.GetCountryISOCode(Item."Country/Region of Origin Code");
TempShopifyVariant."Option 1 Name" := 'Variant';
TempShopifyVariant."Option 1 Value" := ItemVariant.Code;
TempShopifyVariant."Option 2 Name" := Shop."Option Name for UoM";
Expand All @@ -145,6 +147,8 @@ codeunit 30174 "Shpfy Create Product"
TempShopifyVariant.SKU := GetVariantSKU(TempShopifyVariant.Barcode, Item."No.", ItemVariant.Code, GetVendorItemNo(Item."No.", ItemVariant.Code, Item."Sales Unit of Measure"));
TempShopifyVariant.Taxable := true;
TempShopifyVariant.Weight := Item."Gross Weight";
TempShopifyVariant."Tariff No." := Item."Tariff No.";
TempShopifyVariant."Country/Region of Origin Code" := ProductExport.GetCountryISOCode(Item."Country/Region of Origin Code");
TempShopifyVariant."Option 1 Name" := 'Variant';
TempShopifyVariant."Option 1 Value" := ItemVariant.Code;
TempShopifyVariant."Shop Code" := Shop.Code;
Expand All @@ -171,6 +175,8 @@ codeunit 30174 "Shpfy Create Product"
TempShopifyVariant.SKU := GetVariantSKU(TempShopifyVariant.Barcode, Item."No.", '', Item."Vendor Item No.");
TempShopifyVariant.Taxable := true;
TempShopifyVariant.Weight := ItemUnitofMeasure."Qty. per Unit of Measure" > 0 ? Item."Gross Weight" * ItemUnitofMeasure."Qty. per Unit of Measure" : Item."Gross Weight";
TempShopifyVariant."Tariff No." := Item."Tariff No.";
TempShopifyVariant."Country/Region of Origin Code" := ProductExport.GetCountryISOCode(Item."Country/Region of Origin Code");
TempShopifyVariant."Option 1 Name" := Shop."Option Name for UoM";
TempShopifyVariant."Option 1 Value" := ItemUnitofMeasure.Code;
TempShopifyVariant."Shop Code" := Shop.Code;
Expand Down Expand Up @@ -257,6 +263,8 @@ codeunit 30174 "Shpfy Create Product"
TempShopifyVariant.SKU := GetVariantSKU(TempShopifyVariant.Barcode, Item."No.", '', Item."Vendor Item No.");
TempShopifyVariant.Taxable := true;
TempShopifyVariant.Weight := Item."Gross Weight";
TempShopifyVariant."Tariff No." := Item."Tariff No.";
TempShopifyVariant."Country/Region of Origin Code" := ProductExport.GetCountryISOCode(Item."Country/Region of Origin Code");
TempShopifyVariant."Shop Code" := Shop.Code;
TempShopifyVariant."Item SystemId" := Item.SystemId;
TempShopifyVariant.Insert(false);
Expand Down Expand Up @@ -303,4 +311,5 @@ codeunit 30174 "Shpfy Create Product"
Page.Run(Page::"Shpfy Shop Locations Mapping", ShopLocation);
end;
end;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Microsoft.Integration.Shopify;

using Microsoft.Foundation.Address;
using Microsoft.Foundation.ExtendedText;
using Microsoft.Inventory.Item;
using Microsoft.Inventory.Item.Attribute;
Expand Down Expand Up @@ -368,6 +369,8 @@ codeunit 30178 "Shpfy Product Export"
end;
ShopifyVariant.Taxable := true;
ShopifyVariant.Weight := ItemUnitofMeasure."Qty. per Unit of Measure" > 0 ? Item."Gross Weight" * ItemUnitofMeasure."Qty. per Unit of Measure" : Item."Gross Weight";
ShopifyVariant."Tariff No." := Item."Tariff No.";
ShopifyVariant."Country/Region of Origin Code" := GetCountryISOCode(Item."Country/Region of Origin Code");
ShopifyVariant."Option 1 Name" := Shop."Option Name for UoM";
ShopifyVariant."Option 1 Value" := ItemUnitofMeasure.Code;
ShopifyVariant."Shop Code" := Shop.Code;
Expand Down Expand Up @@ -424,6 +427,8 @@ codeunit 30178 "Shpfy Product Export"
end;
ShopifyVariant.Taxable := true;
ShopifyVariant.Weight := Item."Gross Weight";
ShopifyVariant."Tariff No." := Item."Tariff No.";
ShopifyVariant."Country/Region of Origin Code" := GetCountryISOCode(Item."Country/Region of Origin Code");
if ShopifyVariant."Option 1 Name" = '' then
ShopifyVariant."Option 1 Name" := 'Variant';
if ShopifyVariant."Option 1 Name" = 'Variant' then
Expand Down Expand Up @@ -479,6 +484,8 @@ codeunit 30178 "Shpfy Product Export"
end;
ShopifyVariant.Taxable := true;
ShopifyVariant.Weight := ItemUnitofMeasure."Qty. per Unit of Measure" > 0 ? Item."Gross Weight" * ItemUnitofMeasure."Qty. per Unit of Measure" : Item."Gross Weight";
ShopifyVariant."Tariff No." := Item."Tariff No.";
ShopifyVariant."Country/Region of Origin Code" := GetCountryISOCode(Item."Country/Region of Origin Code");
ShopifyVariant."Option 1 Name" := 'Variant';
ShopifyVariant."Option 1 Value" := ItemVariant.Code;
ShopifyVariant."Option 2 Name" := Shop."Option Name for UoM";
Expand Down Expand Up @@ -1306,4 +1313,15 @@ codeunit 30178 "Shpfy Product Export"
exit(true);
end;
#endregion

internal procedure GetCountryISOCode(CountryRegionCode: Code[10]): Code[10]
var
CountryRegion: Record "Country/Region";
begin
if CountryRegionCode = '' then
exit('');
if CountryRegion.Get(CountryRegionCode) then
exit(CountryRegion."ISO Code");
exit(CountryRegionCode);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ codeunit 30189 "Shpfy Variant API"
GraphQuery.Append(ShopifyVariant.SKU);
GraphQuery.Append('\"');
end;
if ShopifyVariant."Tariff No." <> xShopifyVariant."Tariff No." then begin
HasChange := true;
GraphQuery.Append(', harmonizedSystemCode: \"');
GraphQuery.Append(CommunicationMgt.EscapeGraphQLData(ShopifyVariant."Tariff No."));
GraphQuery.Append('\"');
end;
if ShopifyVariant."Country/Region of Origin Code" <> xShopifyVariant."Country/Region of Origin Code" then begin
HasChange := true;
GraphQuery.Append(', countryCodeOfOrigin: ');
GraphQuery.Append(ShopifyVariant."Country/Region of Origin Code");
end;
if ShopifyVariant.Weight <> xShopifyVariant.Weight then begin
GraphQuery.Append(', measurement: {weight: {value:');
GraphQuery.Append(Format(ShopifyVariant.Weight, 0, 9));
Expand Down Expand Up @@ -283,6 +294,15 @@ codeunit 30189 "Shpfy Variant API"
GraphQuery.Append(CommunicationMgt.EscapeGraphQLData(ShopifyVariant.SKU));
GraphQuery.Append('\"');
end;
if ShopifyVariant."Tariff No." <> '' then begin
GraphQuery.Append(', harmonizedSystemCode: \"');
GraphQuery.Append(CommunicationMgt.EscapeGraphQLData(ShopifyVariant."Tariff No."));
GraphQuery.Append('\"');
end;
if ShopifyVariant."Country/Region of Origin Code" <> '' then begin
GraphQuery.Append(', countryCodeOfOrigin: ');
GraphQuery.Append(ShopifyVariant."Country/Region of Origin Code");
end;
if ShopifyVariant.Weight > 0 then begin
GraphQuery.Append(', measurement: {weight: {value:');
GraphQuery.Append(Format(ShopifyVariant.Weight, 0, 9));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ table 30129 "Shpfy Variant"
{
DataClassification = SystemMetadata;
}
field(109; "Tariff No."; Code[20])
{
Caption = 'Tariff No.';
DataClassification = SystemMetadata;
}
field(110; "Country/Region of Origin Code"; Code[10])
{
Caption = 'Country/Region of Origin Code';
DataClassification = SystemMetadata;
}
}
keys
{
Expand Down
113 changes: 113 additions & 0 deletions src/Apps/W1/Shopify/Test/Products/ShpfyCreateProductTest.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -2958,4 +2958,117 @@ codeunit 139601 "Shpfy Create Product Test"

until TempShopifyVariant.Next() = 0;
end;

[Test]
procedure UnitTestCreateTempProductSetsHSCodeAndCountryOfOrigin()
var
Item: Record Item;
TempShopifyProduct: Record "Shpfy Product" temporary;
Shop: Record "Shpfy Shop";
TempShopifyVariant: Record "Shpfy Variant" temporary;
TempTag: Record "Shpfy Tag" temporary;
CreateProduct: Codeunit "Shpfy Create Product";
InitializeTest: Codeunit "Shpfy Initialize Test";
ProductInitTest: Codeunit "Shpfy Product Init Test";
begin
// [SCENARIO] Creating a temp product from an Item with Tariff No. and Country/Region of Origin Code
// should populate those fields on the Shopify variant.

// [GIVEN] A shop
Shop := InitializeTest.CreateShop();
Shop."SKU Mapping" := "Shpfy SKU Mapping"::" ";
Shop.Modify();
CreateProduct.SetShop(Shop);

// [GIVEN] An item with Tariff No. and Country/Region of Origin Code
Item := ProductInitTest.CreateItem(Shop."Item Templ. Code", Any.DecimalInRange(10, 100, 2), Any.DecimalInRange(100, 1000, 2));
Item."Tariff No." := '6402.99.0000';
Item."Country/Region of Origin Code" := 'US';
Item.Modify();
Item.SetRecFilter();

// [WHEN] CreateTempProduct is called
CreateProduct.CreateTempProduct(Item, TempShopifyProduct, TempShopifyVariant, TempTag);

// [THEN] The variant has Tariff No. populated
LibraryAssert.AreEqual('6402.99.0000', TempShopifyVariant."Tariff No.", 'TempShopifyVariant."Tariff No." should match Item."Tariff No."');

// [THEN] The variant has Country/Region of Origin Code populated
LibraryAssert.AreEqual('US', TempShopifyVariant."Country/Region of Origin Code", 'TempShopifyVariant."Country/Region of Origin Code" should match Item."Country/Region of Origin Code"');
end;

[Test]
procedure UnitTestCreateTempProductEmptyHSCodeAndCountryOfOrigin()
var
Item: Record Item;
TempShopifyProduct: Record "Shpfy Product" temporary;
Shop: Record "Shpfy Shop";
TempShopifyVariant: Record "Shpfy Variant" temporary;
TempTag: Record "Shpfy Tag" temporary;
CreateProduct: Codeunit "Shpfy Create Product";
InitializeTest: Codeunit "Shpfy Initialize Test";
ProductInitTest: Codeunit "Shpfy Product Init Test";
begin
// [SCENARIO] Creating a temp product from an Item without Tariff No. and Country/Region of Origin Code
// should leave those fields empty on the Shopify variant.

// [GIVEN] A shop
Shop := InitializeTest.CreateShop();
Shop."SKU Mapping" := "Shpfy SKU Mapping"::" ";
Shop.Modify();
CreateProduct.SetShop(Shop);

// [GIVEN] An item without Tariff No. and Country/Region of Origin Code
Item := ProductInitTest.CreateItem(Shop."Item Templ. Code", Any.DecimalInRange(10, 100, 2), Any.DecimalInRange(100, 1000, 2));
Item.SetRecFilter();

// [WHEN] CreateTempProduct is called
CreateProduct.CreateTempProduct(Item, TempShopifyProduct, TempShopifyVariant, TempTag);

// [THEN] The variant has empty Tariff No.
LibraryAssert.AreEqual('', TempShopifyVariant."Tariff No.", 'TempShopifyVariant."Tariff No." should be empty');

// [THEN] The variant has empty Country/Region of Origin Code
LibraryAssert.AreEqual('', TempShopifyVariant."Country/Region of Origin Code", 'TempShopifyVariant."Country/Region of Origin Code" should be empty');
end;

[Test]
procedure UnitTestCreateTempProductWithVariantsSetsHSCode()
var
Item: Record Item;
TempShopifyProduct: Record "Shpfy Product" temporary;
Shop: Record "Shpfy Shop";
TempShopifyVariant: Record "Shpfy Variant" temporary;
TempTag: Record "Shpfy Tag" temporary;
CreateProduct: Codeunit "Shpfy Create Product";
InitializeTest: Codeunit "Shpfy Initialize Test";
ProductInitTest: Codeunit "Shpfy Product Init Test";
begin
// [SCENARIO] Creating a temp product with variants from an Item with Tariff No.
// should populate Tariff No. on all variant records.

// [GIVEN] A shop
Shop := InitializeTest.CreateShop();
Shop."SKU Mapping" := "Shpfy SKU Mapping"::" ";
Shop.Modify();
CreateProduct.SetShop(Shop);

// [GIVEN] An item with variants and Tariff No.
Item := ProductInitTest.CreateItem(Shop."Item Templ. Code", Any.DecimalInRange(10, 100, 2), Any.DecimalInRange(100, 1000, 2), true);
Item."Tariff No." := '8471.30.0100';
Item."Country/Region of Origin Code" := 'DE';
Item.Modify();
Item.SetRecFilter();

// [WHEN] CreateTempProduct is called
CreateProduct.CreateTempProduct(Item, TempShopifyProduct, TempShopifyVariant, TempTag);

// [THEN] All variants have Tariff No. and Country of Origin populated
TempShopifyVariant.Reset();
if TempShopifyVariant.FindSet() then
repeat
LibraryAssert.AreEqual('8471.30.0100', TempShopifyVariant."Tariff No.", 'Each variant should have Tariff No.');
LibraryAssert.AreEqual('DE', TempShopifyVariant."Country/Region of Origin Code", 'Each variant should have Country/Region of Origin Code');
until TempShopifyVariant.Next() = 0;
end;
}
Loading