fix: split numerator/denominator for quantity values
This commit is contained in:
parent
a5b699a52a
commit
d9ed0de775
1 changed files with 20 additions and 10 deletions
|
|
@ -23,6 +23,8 @@
|
||||||
Base views for Logs
|
Base views for Logs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import decimal
|
||||||
|
import time
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
|
|
@ -398,11 +400,12 @@ class LogMasterView(WuttaFarmMasterView):
|
||||||
units = session.get(model.Unit, new_qty["units"]["uuid"])
|
units = session.get(model.Unit, new_qty["units"]["uuid"])
|
||||||
assert units
|
assert units
|
||||||
if new_qty["uuid"].startswith("new_"):
|
if new_qty["uuid"].startswith("new_"):
|
||||||
|
num, denom = decimal.Decimal(new_qty["value"]).as_integer_ratio()
|
||||||
qty = self.app.make_true_quantity(
|
qty = self.app.make_true_quantity(
|
||||||
new_qty["quantity_type"]["drupal_id"],
|
new_qty["quantity_type"]["drupal_id"],
|
||||||
measure_id=new_qty["measure"],
|
measure_id=new_qty["measure"],
|
||||||
value_numerator=int(new_qty["value"]),
|
value_numerator=num,
|
||||||
value_denominator=1,
|
value_denominator=denom,
|
||||||
units=units,
|
units=units,
|
||||||
)
|
)
|
||||||
# nb. must ensure "typed" quantity record persists!
|
# nb. must ensure "typed" quantity record persists!
|
||||||
|
|
@ -441,18 +444,25 @@ class LogMasterView(WuttaFarmMasterView):
|
||||||
if old_mtype.uuid.hex not in desired:
|
if old_mtype.uuid.hex not in desired:
|
||||||
quantity.material_types.remove(old_mtype)
|
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
|
model = self.app.model
|
||||||
session = self.Session()
|
model_class = self.get_model_class()
|
||||||
|
|
||||||
# nb. ensure quantities have uuid keys
|
with self.app.short_session(commit=True) as session:
|
||||||
session.flush()
|
if user := session.query(model.User).filter_by(username="farmos").first():
|
||||||
|
session.info["continuum_user_id"] = user.uuid
|
||||||
|
|
||||||
for qty in log.quantities:
|
log = None
|
||||||
qty = self.app.get_true_quantity(qty)
|
while not log:
|
||||||
self.app.auto_sync_to_farmos(qty, client=client)
|
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):
|
def get_farmos_url(self, log):
|
||||||
return self.app.get_farmos_url(f"/log/{log.drupal_id}")
|
return self.app.get_farmos_url(f"/log/{log.drupal_id}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue