Skip to content

Commit

Permalink
CTD-71: fixed comments from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaroslav committed Aug 11, 2021
1 parent 4d00502 commit a7b20d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
24 changes: 6 additions & 18 deletions livestyled/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,12 @@ def create_new(

def diff(self, other):
differences = {}
fields = ('external_id', 'price', 'translations', 'tax', 'tax_rate', 'tax_band')
fields = (
'external_id', 'price', 'translations', 'product', 'tax', 'tax_rate', 'tax_band'
)
for field in fields:
if getattr(self, field) != getattr(other, field):
differences[field] = getattr(self, field)

related_resource_fields = ['product']
for field in related_resource_fields:
self_id = getattr(self, field).id
other_id = getattr(other, field).id
if self_id != other_id:
differences[field] = getattr(self, field)

return differences


Expand Down Expand Up @@ -150,18 +144,12 @@ def create_new(

def diff(self, other):
differences = {}
fields = ('initial', 'on_hand')
fields = (
'initial', 'on_hand', 'fulfilment_point', 'product_variant'
)
for field in fields:
if getattr(self, field) != getattr(other, field):
differences[field] = getattr(self, field)

related_resource_fields = ('fulfilment_point', 'product_variant')
for field in related_resource_fields:
self_id = getattr(self, field).id
other_id = getattr(other, field).id
if self_id != other_id:
differences[field] = getattr(self, field)

return differences


Expand Down
13 changes: 6 additions & 7 deletions livestyled/resource_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ def _get_resource_by_id(
):
return schema.Meta.model(**self._get_resource(id, schema))

def _get_resource_by_composite_id(self, schema: Type[Schema], composite_id: str):
return schema.Meta.model(**self._get_resource(composite_id, schema))

def _create_resource(
self,
schema: Type[Schema],
Expand Down Expand Up @@ -982,17 +979,19 @@ def create_product_variant_stock(

def get_product_variant_stocks(
self,
composite_id: str
fulfilment_point: int,
product_variant_id: int
) -> ProductVariantStock:
return self._get_resource_by_composite_id(ProductVariantStockSchema, composite_id)
compose_id = f"fulfilmentPoint={fulfilment_point};productVariant={product_variant_id}"
return ProductVariantStockSchema.Meta.model(**self._get_resource(compose_id, ProductVariantStockSchema))

def update_product_variant_stock(
self,
product_variant_stock: ProductVariantStock,
attributes: Dict
) -> ProductVariantStock:
composite_id = 'fulfilmentPoint=' + str(product_variant_stock.fulfilment_point.id) + ';productVariant=' + str(product_variant_stock.product_variant.id)
return self._update_resource_by_composite_id(ProductVariantStockSchema, composite_id, attributes)
compose_id = f"fulfilmentPoint={product_variant_stock.fulfilment_point.id};productVariant={product_variant_stock.product_variant.id}"
return self._update_resource_by_composite_id(ProductVariantStockSchema, compose_id, attributes)

# ---- TICKET INTEGRATIONS

Expand Down
2 changes: 1 addition & 1 deletion livestyled/schemas/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Meta:
additional_price = fields.Integer(data_key='additionalPrice')
translations = fields.Nested(ProductModifierItemTranslationsSchema, many=True, missing=[])
modifier_list = RelatedResourceLinkField('livestyled.schemas.product.ProductModifierListSchema', data_key='modifierList', microservice_aware=True)
status = fields.String(missing=None, data_key='status')
status = fields.String(missing=None)


class ProductModifierListTranslationsSchema(Schema):
Expand Down

0 comments on commit a7b20d0

Please sign in to comment.