senaite/senaite.sync

Field `DependentServices` of Calculations keep the old UIDs after sync

Opened this issue · 3 comments

Steps to reproduce

  • Create a new Senaite instance and setup the AS/Calculations as displayed below
  • Sync only setup items to a new/empty Senaite instance
  • Create a new AR the given Analyses in the new instance
  • Add results for Länge/Breite/Höhe

Translations

  • Länge -> Length
  • Breite -> Width
  • Höhe -> Height
  • Kantenlänge -> Edglength
  • Umfang -> Circumference
  • Grundfläche -> Area
  • Volumen -> Volume

Calculations

  • Edglength: 4 * ([laenge] + [breite] + [hoehe])
  • Circumference: 2 * ([laenge] + [breite])
  • Volume: [laenge] * [breite] * [hoehe]
  • Area: [laenge] * [breite]

Current behavior

The Calculations of the dependant services (Kantenlänge, Umfang, Grundfläche, Volumen) is not triggered

Expected behavior

The Calculations of the dependant services (Kantenlänge, Umfang, Grundfläche, Volumen) is triggered and calculated

Screenshot (optional)

The Field DependentServices is set implicitly in setFormula:
https://github.com/senaite/senaite.core/blob/master/bika/lims/content/calculation.py#L212

Existing Analyses keep a history aware version to the calculation and need to be set as well.

Probably the portal_repository need to be synced as well 🤔

The only solution I can think of the moment is to iterate through all calculations and fix them like this:

>>> from bika.lims import api

>>> catalog = api.get_tool("bika_setup_catalog")
>>> brains = catalog({"portal_type": "Calculation"})

>>> for brain in brains:
...     calc = api.get_object(brain)
...     calc.setFormula(calc.getFormula())

>>> catalog = api.get_tool("bika_analysis_catalog")
>>> brains = catalog({"portal_type": "Analysis"})

>>> for brain in brains:
...     analysis = api.get_object(brain)
...     calc = analysis.getCalculation()
...     if calc:
...         calc.setFormula(calc.getFormula())