From d9ed0de775a2e9d7111f5d8b520546febc1c21ab Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 22 Mar 2026 13:58:04 -0500 Subject: [PATCH] fix: split numerator/denominator for quantity values --- src/wuttafarm/web/views/logs.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/wuttafarm/web/views/logs.py b/src/wuttafarm/web/views/logs.py index 2a4e6e0..4924b31 100644 --- a/src/wuttafarm/web/views/logs.py +++ b/src/wuttafarm/web/views/logs.py @@ -23,6 +23,8 @@ Base views for Logs """ +import decimal +import time from collections import OrderedDict import colander @@ -398,11 +400,12 @@ class LogMasterView(WuttaFarmMasterView): units = session.get(model.Unit, new_qty["units"]["uuid"]) assert units if new_qty["uuid"].startswith("new_"): + num, denom = decimal.Decimal(new_qty["value"]).as_integer_ratio() qty = self.app.make_true_quantity( new_qty["quantity_type"]["drupal_id"], measure_id=new_qty["measure"], - value_numerator=int(new_qty["value"]), - value_denominator=1, + value_numerator=num, + value_denominator=denom, units=units, ) # nb. must ensure "typed" quantity record persists! @@ -441,18 +444,25 @@ class LogMasterView(WuttaFarmMasterView): if old_mtype.uuid.hex not in desired: quantity.material_types.remove(old_mtype) - def auto_sync_to_farmos(self, client, log): + def auto_sync_to_farmos(self, client, uuid): model = self.app.model - session = self.Session() + model_class = self.get_model_class() - # nb. ensure quantities have uuid keys - session.flush() + with self.app.short_session(commit=True) as session: + if user := session.query(model.User).filter_by(username="farmos").first(): + session.info["continuum_user_id"] = user.uuid - for qty in log.quantities: - qty = self.app.get_true_quantity(qty) - self.app.auto_sync_to_farmos(qty, client=client) + log = None + while not log: + log = session.get(model_class, uuid) + if not log: + time.sleep(0.1) - self.app.auto_sync_to_farmos(log, client=client) + for qty in log.quantities: + qty = self.app.get_true_quantity(qty) + self.app.auto_sync_to_farmos(qty, client=client) + + self.app.auto_sync_to_farmos(log, client=client) def get_farmos_url(self, log): return self.app.get_farmos_url(f"/log/{log.drupal_id}")