SebRut/pygrocy

Enable "allow_subproduct_substitution" on consume endpoint

kingo55 opened this issue · 0 comments

Expected behaviour: Consumption against parent products will use sub-products' stock when substitution is allowed.

Actual behaviour: Consumption against parent products returns HTTP 400 and we can't set "allow_subproduct_substitution" to use sub-products' stock.

This is causing the following issues downstream in the grocy / Home Assistant custom component: custom-components/grocy#182

Possible solution

Bernd points out that we should allow substitution: grocy/grocy#1767 (comment)

image

So, I think we need to update the POST body with "allow_subproduct_substitution", possibly defaulted to False in the code here:

def consume_product(
self,
product_id: int,
amount: float = 1,
spoiled: bool = False,
transaction_type: TransactionType = TransactionType.CONSUME,
):
data = {
"amount": amount,
"spoiled": spoiled,
"transaction_type": transaction_type.value,
}
self._do_post_request(f"stock/products/{product_id}/consume", data)

What do you think?