Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

feat: add new fields to inventory model #112

Merged
Merged
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
48 changes: 36 additions & 12 deletions commercelayer/resource_inventory_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func resourceInventoryModel() *schema.Resource {
Optional: true,
Default: 2,
},
"stock_reservation_cutoff": {
Description: "The duration in seconds of the generated stock reservations.",
Type: schema.TypeInt,
Optional: true,
Default: 3600,
},
"reference": {
Description: "A string that you can use to add any external identifier to the resource. This " +
"can be useful for integrating the resource to an external system, like an ERP, a " +
Expand All @@ -68,6 +74,18 @@ func resourceInventoryModel() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"manual_stock_decrement": {
Description: "Indicates if the the stock will be decremented manually after the order approval",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"put_stock_transfers_on_hold": {
Description: "Indicates if the the stock transfers must be put on hold automatically with the associated shipment.",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"metadata": {
Description: "Set of key-value pairs that you can attach to the resource. This can be useful " +
"for storing additional information about the resource in a structured format",
Expand Down Expand Up @@ -112,12 +130,15 @@ func resourceInventoryModelCreateFunc(ctx context.Context, d *schema.ResourceDat
Data: commercelayer.InventoryModelCreateData{
Type: inventoryModelType,
Attributes: commercelayer.POSTInventoryModels201ResponseDataAttributes{
Name: attributes["name"].(string),
Strategy: stringRef(attributes["strategy"]),
StockLocationsCutoff: intToInt32Ref(attributes["stock_locations_cutoff"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
Name: attributes["name"].(string),
Strategy: stringRef(attributes["strategy"]),
StockLocationsCutoff: intToInt32Ref(attributes["stock_locations_cutoff"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
ManualStockDecrement: boolRef(attributes["manual_stock_decrement"]),
StockReservationCutoff: intToInt32Ref(attributes["stock_reservation_cutoff"]),
PutStockTransfersOnHold: boolRef(attributes["put_stock_transfers_on_hold"]),
Metadata: keyValueRef(attributes["metadata"]),
},
},
}
Expand Down Expand Up @@ -153,12 +174,15 @@ func resourceInventoryModelUpdateFunc(ctx context.Context, d *schema.ResourceDat
Type: inventoryModelType,
Id: d.Id(),
Attributes: commercelayer.PATCHInventoryModelsInventoryModelId200ResponseDataAttributes{
Name: stringRef(attributes["name"]),
Strategy: stringRef(attributes["strategy"]),
StockLocationsCutoff: intToInt32Ref(attributes["stock_locations_cutoff"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
Name: stringRef(attributes["name"]),
Strategy: stringRef(attributes["strategy"]),
StockLocationsCutoff: intToInt32Ref(attributes["stock_locations_cutoff"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
ManualStockDecrement: boolRef(attributes["manual_stock_decrement"]),
StockReservationCutoff: intToInt32Ref(attributes["stock_reservation_cutoff"]),
PutStockTransfersOnHold: boolRef(attributes["put_stock_transfers_on_hold"]),
Metadata: keyValueRef(attributes["metadata"]),
},
},
}
Expand Down
12 changes: 12 additions & 0 deletions commercelayer/resource_inventory_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (s *AcceptanceSuite) TestAccInventoryModel_basic() {
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Inventory Model"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.stock_locations_cutoff", "1"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.strategy", "no_split"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.manual_stock_decrement", "true"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.stock_reservation_cutoff", "4000"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.put_stock_transfers_on_hold", "true"),
),
},
{
Expand All @@ -52,6 +55,9 @@ func (s *AcceptanceSuite) TestAccInventoryModel_basic() {
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Inventory Model Changed"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.stock_locations_cutoff", "2"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.strategy", "split_shipments"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.manual_stock_decrement", "false"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.stock_reservation_cutoff", "3600"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.put_stock_transfers_on_hold", "false"),
),
},
},
Expand All @@ -65,6 +71,9 @@ func testAccInventoryModelCreate(testName string) string {
name = "Incentro Inventory Model"
stock_locations_cutoff = 1
strategy = "no_split"
manual_stock_decrement = true
stock_reservation_cutoff = 4000
put_stock_transfers_on_hold = true
metadata = {
testName: "{{.testName}}"
}
Expand All @@ -80,6 +89,9 @@ func testAccInventoryModelUpdate(testName string) string {
name = "Incentro Inventory Model Changed"
stock_locations_cutoff = 2
strategy = "split_shipments"
manual_stock_decrement = false
stock_reservation_cutoff = 3600
put_stock_transfers_on_hold = false
metadata = {
testName: "{{.testName}}"
}
Expand Down
9 changes: 6 additions & 3 deletions examples/resources/commercelayer_inventory_model/resource.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
resource "commercelayer_inventory_model" "incentro_inventory_model" {
attributes {
name = "Incentro Inventory Model"
stock_locations_cutoff = 2
strategy = "split_shipments"
name = "Incentro Inventory Model"
stock_locations_cutoff = 2
strategy = "split_shipments"
manual_stock_decrement = true
stock_reservation_cutoff = 4000
put_stock_transfers_on_hold = true
}
}
Loading