Skip to content

Commit

Permalink
Merge pull request #213 from marcelvriend/feature/subproduct-substitu…
Browse files Browse the repository at this point in the history
…tion

Add support for subproduct substitution
  • Loading branch information
isabellaalstrom authored May 18, 2022
2 parents a8c730e + 0f778d7 commit 37e647c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion custom_components/grocy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SERVICE_AMOUNT = "amount"
SERVICE_PRICE = "price"
SERVICE_SPOILED = "spoiled"
SERVICE_SUBPRODUCT_SUBSTITUTION = "allow_subproduct_substitution"
SERVICE_TRANSACTION_TYPE = "transaction_type"
SERVICE_CHORE_ID = "chore_id"
SERVICE_DONE_BY = "done_by"
Expand Down Expand Up @@ -47,6 +48,7 @@
vol.Required(SERVICE_PRODUCT_ID): vol.Coerce(int),
vol.Required(SERVICE_AMOUNT): vol.Coerce(float),
vol.Optional(SERVICE_SPOILED): bool,
vol.Optional(SERVICE_SUBPRODUCT_SUBSTITUTION): bool,
vol.Optional(SERVICE_TRANSACTION_TYPE): str,
}
)
Expand Down Expand Up @@ -173,6 +175,7 @@ async def async_consume_product_service(hass, coordinator, data):
product_id = data[SERVICE_PRODUCT_ID]
amount = data[SERVICE_AMOUNT]
spoiled = data.get(SERVICE_SPOILED, False)
allow_subproduct_substitution = data.get(SERVICE_SUBPRODUCT_SUBSTITUTION, False)

transaction_type_raw = data.get(SERVICE_TRANSACTION_TYPE, None)
transaction_type = TransactionType.CONSUME
Expand All @@ -182,7 +185,11 @@ async def async_consume_product_service(hass, coordinator, data):

def wrapper():
coordinator.api.consume_product(
product_id, amount, spoiled=spoiled, transaction_type=transaction_type
product_id,
amount,
spoiled=spoiled,
transaction_type=transaction_type,
allow_subproduct_substitution=allow_subproduct_substitution,
)

await hass.async_add_executor_job(wrapper)
Expand Down
7 changes: 7 additions & 0 deletions custom_components/grocy/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ consume_product_from_stock:
default: false
selector:
boolean:
allow_subproduct_substitution:
name: Subproduct substitution
description: If subproduct substitution is allowed
example: false
default: false
selector:
boolean:
transaction_type:
name: Transaction Type
description: The type of the transaction.
Expand Down

0 comments on commit 37e647c

Please sign in to comment.