specify / specify7

Specify 7
https://www.specifysoftware.org/products/specify-7/
GNU General Public License v2.0
60 stars 36 forks source link

Support calculated(virtual) fields in the query builder #2359

Open maxpatiiuk opened 1 year ago

maxpatiiuk commented 1 year ago

The Sp6 query builder supports querying on calculated fields. The Sp7 query builder appears to not support them.

From @grantfitzsimmons:

Example Calculated Fields:

Preparation

Loan https://github.com/specify/specify7/issues/1193

Accession https://github.com/specify/specify7/issues/4802

Exchange Out, Disposal, Gift, and Deaccession https://github.com/specify/specify7/issues/2521

image

Reported by CSIRO

From Asana: https://app.asana.com/0/1201972579963460/1203248913489633

See also #1193

benanhalt commented 1 year ago

Probably using database views would be the most principled way of doing this. Then Specify queries and other APIs could access these fields in a consistent way as if they were normal fields. There would need to be a way to add the views to the database. Presumably this could be done using custom Django migrations. Also there would need to be some way to cause the backend to use the views when retrieving data from such tables but continue to issue updates and inserts to the underlying bare tables. MySQL does support updatable and insertable views, but I wouldn't bet on them being fit for use.

maxpatiiuk commented 9 months ago

From @grantfitzsimmons:

This includes isOnLoan and actualCountAmt

The "Is on Loan" indicator that you can see in the preparation section of a form is not currently a field option in the query builder:

image

Requested By: Dan Baker at CSIRO (Asana)