Skip to content

Commit 3047e05

Browse files
committed
Fix webhook for assets
1 parent 7b21c85 commit 3047e05

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

landolfio/inventory_frontend/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ def get_queryset(self):
378378

379379
for asset in linked_assets:
380380
# Check if sources is missing, null, or empty array
381-
sources = asset.moneybird_data.get('sources') if asset.moneybird_data else None
381+
sources = (
382+
asset.moneybird_data.get("sources")
383+
if asset.moneybird_data
384+
else None
385+
)
382386
if not sources or len(sources) == 0:
383387
asset_ids_with_missing_sources.append(asset.id)
384388

landolfio/moneybird/webhooks/processing.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,20 @@ def process_webhook_payload(payload: MoneybirdResource) -> None:
3434
entity_type = payload["entity_type"]
3535
entity_id = payload["entity_id"]
3636
entity_data = payload["entity"]
37+
38+
# Try to get exact entity type match first
3739
resource_type = get_moneybird_resource_type_for_entity(entity_type)
3840

41+
# If not found and entity_type starts with company_assets_, route to asset resource type
42+
if resource_type is None and entity_type.startswith("company_assets_"):
43+
resource_type = get_moneybird_resource_type_for_entity("company_assets_asset")
44+
if resource_type:
45+
logging.info(f"Routing {entity_type} webhook to AssetResourceType")
46+
3947
if resource_type is None:
40-
logging.warning("Received webhook with unregistered entity type")
48+
logging.warning(
49+
f"Received webhook with unregistered entity type: {entity_type} (event: {event.value})"
50+
)
4151
return
4252

4353
return resource_type.process_webhook_event(entity_id, entity_data, event)

landolfio/moneybird/webhooks/register.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ def create_webhook():
2929
return
3030

3131
# Convert enum values to strings if needed
32-
events = [event.value if hasattr(event, 'value') else event for event in events]
32+
events = [event.value if hasattr(event, "value") else event for event in events]
3333

3434
administration = get_moneybird_administration()
35-
response = administration.post("webhooks", data={"url": url, "enabled_events": events})
35+
response = administration.post(
36+
"webhooks", data={"url": url, "enabled_events": events}
37+
)
3638
logging.info(f"Registered webhook with id {response['id']}")
3739
return response
3840

0 commit comments

Comments
 (0)