diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ec1143..8b3df0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -* +* Support for automatic fill of Seeplus fulfillment and delivery data ### Changed diff --git a/README.md b/README.md index 28c061e..fdd9979 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,11 @@ Code coverage of at least 75% of the code base should be considered a priority. ### Seeplus -| Name | Type | Description | -| ------------------ | ----- | --------------------------------------------------------------------------------------------- | -| **SEEPLUS_ORIGIN** | `str` | The origin token to be used in Seeplus integration (defaults to: `63971c5c62bd0a62b956b4f3`). | -| **SEEPLUS_KEY** | `str` | If provided offer a way to ensure shared key authentication to Webhooks. | +| Name | Type | Description | +| ------------------------- | ----- | --------------------------------------------------------------------------------------------- | +| **SEEPLUS_ORIGIN** | `str` | The origin token to be used in Seeplus integration (defaults to: `63971c5c62bd0a62b956b4f3`). | +| **SEEPLUS_KEY** | `str` | If provided offers a way to ensure shared key authentication in Seeplus Webhook update calls. | +| **SEEPLUS_FULFILMENT_ID** | `int` | The ID of the Store that will be used for the fulfilment of the orders. | ## License diff --git a/src/budy/models/order.py b/src/budy/models/order.py index 8876759..e27120d 100644 --- a/src/budy/models/order.py +++ b/src/budy/models/order.py @@ -46,6 +46,7 @@ import appier import appier_extras +from . import store from . import bundle from . import product from . import country @@ -1433,8 +1434,8 @@ def merger(first, second, separator = " | "): @appier.operation( name = "Import Seeplus", parameters = ( - ("Fulfilment", "fulfilment", str, "HQ"), - ("Delivery", "delivery", str, "HQ"), + ("Fulfilment", "fulfilment", str), + ("Delivery", "delivery", str), ("Origin", "origin", str), ("Strict", "strict", bool, True) ), @@ -1442,8 +1443,8 @@ def merger(first, second, separator = " | "): ) def import_seeplus_s( self, - fulfilment = "HQ", - delivery = "HQ", + fulfilment = None, + delivery = None, origin = None, strict = True ): @@ -1451,6 +1452,42 @@ def import_seeplus_s( # configuration, expected default behaviour origin = origin or appier.conf("SEEPLUS_ORIGIN", "63971c5c62bd0a62b956b4f3") + # in case there's no fulfilment defined then the default + # store is used to retrieve the fulfilment identifier + if not fulfilment: + fulfilment_id = appier.conf("SEEPLUS_FULFILMENT_ID", None, cast = int) + appier.verify( + not fulfilment_id == None, + message = "No default fulfilment is defined" + ) + fulfilment_store = store.Store.get(id = fulfilment_id) + fulfilment = fulfilment_store.meta.get("seeplus_id", None) + + # if no explicit delivery is defined then the store for the + # delivery is used to obtain the Seeplus identifier + if not delivery: + appier.verify( + self.store, + message = "No store defined for order" + ) + delivery = self.store.meta.get("seeplus_id", None) + + # ensures that the complete set of required parameters for the + # Seeplus import are defined and valid, otherwise an exception + # is raised indicating the problem + appier.verify( + fulfilment, + message = "No fulfilment is set for order" + ) + appier.verify( + delivery, + message = "No delivery is set for order" + ) + appier.verify( + origin, + message = "No origin is set for order" + ) + # obtains the reference to the Seeplus API instance and # validates that the order is ready to be imported api = self.owner.get_seeplus_api()