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

Commit

Permalink
init all Product fields with None by default
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Rutofski <sebastian.rutofski@gmail.com>
  • Loading branch information
SebRut committed Aug 18, 2020
1 parent 8f205f0 commit 75c85d6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pygrocy/grocy.py
Expand Up @@ -24,19 +24,30 @@

class Product(DataModel):
def __init__(self, response):
self._init_empty()
if isinstance(response, CurrentStockResponse):
self._init_from_CurrentStockResponse(response)
elif isinstance(response, MissingProductResponse):
self._init_from_MissingProductResponse(response)
elif isinstance(response, ProductDetailsResponse):
self._init_from_ProductDetailsResponse(response)

def _init_empty(self):
self._name = None
self._id = None
self._amount_missing = None
self._is_partly_in_stock = None

self._available_amount = None
self._best_before_date = None

self._barcodes = None
self._product_group_id = None

def _init_from_CurrentStockResponse(self, response: CurrentStockResponse):
self._id = response.product_id
self._available_amount = response.amount
self._best_before_date = response.best_before_date
self._amount_missing = None
self._is_partly_in_stock = None
if response.product:
self._name = response.product.name
self._barcodes = response.product.barcodes
Expand All @@ -45,12 +56,8 @@ def _init_from_CurrentStockResponse(self, response: CurrentStockResponse):
def _init_from_MissingProductResponse(self, response: MissingProductResponse):
self._id = response.product_id
self._name = response.name
self._available_amount = None
self._best_before_date = None
self._amount_missing = response.amount_missing
self._is_partly_in_stock = response.is_partly_in_stock
self._barcodes = None
self._product_group_id = None

def _init_from_ProductDetailsResponse(self, response: ProductDetailsResponse):
self._id = response.product.id
Expand Down

0 comments on commit 75c85d6

Please sign in to comment.