fix: improve behavior when deleting a Standard Quantity

This commit is contained in:
Lance Edgar 2026-03-08 16:01:12 -05:00
parent 1d5499686f
commit 6bc5f06f7a
2 changed files with 16 additions and 4 deletions

View file

@ -204,7 +204,12 @@ class QuantityMixin:
@declared_attr
def quantity(cls):
return orm.relationship(Quantity)
return orm.relationship(
Quantity,
single_parent=True,
cascade="all, delete-orphan",
cascade_backrefs=False,
)
def render_as_text(self, config=None):
return self.quantity.render_as_text(config)

View file

@ -26,6 +26,7 @@ View for farmOS Quantity Types
import datetime
import colander
import requests
from wuttaweb.forms.schema import WuttaDateTime
from wuttaweb.forms.widgets import WuttaDateTimeWidget
@ -204,9 +205,15 @@ class QuantityMasterView(FarmOSMasterView):
return qty["value"]["decimal"]
def get_instance(self):
quantity = self.farmos_client.resource.get_id(
"quantity", self.farmos_quantity_type, self.request.matchdict["uuid"]
)
# TODO: this pattern should be repeated for other views
try:
quantity = self.farmos_client.resource.get_id(
"quantity", self.farmos_quantity_type, self.request.matchdict["uuid"]
)
except requests.HTTPError as exc:
if exc.response.status_code == 404:
raise self.notfound()
self.raw_json = quantity
data = self.normalize_quantity(quantity["data"])