1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
from ..base import ShopifyResource
import shopify
import json
class InventoryLevel(ShopifyResource):
def __repr__(self):
return "%s(inventory_item_id=%s, location_id=%s)" % (self._singular, self.inventory_item_id, self.location_id)
@classmethod
def _element_path(cls, prefix_options={}, query_options=None):
if query_options is None:
prefix_options, query_options = cls._split_options(prefix_options)
return "%s%s.%s%s" % (
cls._prefix(prefix_options) + "/",
cls.plural,
cls.format.extension,
cls._query_string(query_options),
)
@classmethod
def adjust(cls, location_id, inventory_item_id, available_adjustment):
body = {
"inventory_item_id": inventory_item_id,
"location_id": location_id,
"available_adjustment": available_adjustment,
}
resource = cls.post("adjust", body=json.dumps(body).encode())
return InventoryLevel(InventoryLevel.format.decode(resource.body))
@classmethod
def connect(cls, location_id, inventory_item_id, relocate_if_necessary=False, **kwargs):
body = {
"inventory_item_id": inventory_item_id,
"location_id": location_id,
"relocate_if_necessary": relocate_if_necessary,
}
resource = cls.post("connect", body=json.dumps(body).encode())
return InventoryLevel(InventoryLevel.format.decode(resource.body))
@classmethod
def set(cls, location_id, inventory_item_id, available, disconnect_if_necessary=False, **kwargs):
body = {
"inventory_item_id": inventory_item_id,
"location_id": location_id,
"available": available,
"disconnect_if_necessary": disconnect_if_necessary,
}
resource = cls.post("set", body=json.dumps(body).encode())
return InventoryLevel(InventoryLevel.format.decode(resource.body))
def is_new(self):
return False
def destroy(self):
options = {"inventory_item_id": self.inventory_item_id, "location_id": self.location_id}
return self.__class__.connection.delete(self._element_path(query_options=options), self.__class__.headers)
|