Skip to content

DepositLine Object needs to be more specific when a LinkedTxn vs DepositLineDetail #329

@craftypenguins-chris

Description

@craftypenguins-chris

When updating (and also during creation), the QBO API will fail with an obscure error if you are using linked transactions in a deposit.

QB Validation Exception 2020: Required param missing, need to supply the required value for the API
Required parameter Line.DepositLineDetail.AccountRef is missing in the request

This occurs because the DepositLine Object includes the self.DetailType = "DepositLineDetail" attribute regardless if the line being a LinkedTxn or not.

I haven't dug in far enough to know if this can be a conditional inclusion at object creation or not. I ended up using a delattrib on the object method in my operational codebase:

def remove_unwanted_details(obj):
    if isinstance(obj, list):
        return [remove_unwanted_details(item) for item in obj]
    elif isinstance(obj, dict):
        # Remove 'DetailType' if 'LinkedTxn' key is present in the dict
        if "LinkedTxn" in obj and obj["LinkedTxn"]:
            obj.pop("DetailType", None)
        for key, value in list(obj.items()):
            obj[key] = remove_unwanted_details(value)
    elif hasattr(obj, '__dict__'):
        if isinstance(obj, DepositLine) and getattr(obj, 'LinkedTxn', None):
            # Use delattr to remove the 'DetailType' attribute from Line instances with LinkedTxn
            if hasattr(obj, 'DetailType'):
                delattr(obj, 'DetailType')
        # Recurse into attributes of custom objects
        for attr_name in list(obj.__dict__.keys()):
            attr_value = getattr(obj, attr_name)
            setattr(obj, attr_name, remove_unwanted_details(attr_value))
    return obj

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions