msupply-foundation / open-msupply

Open mSupply represents our most recent advancement in the Logistics Management Information System (LMIS), expanding on more than two decades of development inherited from the well-established legacy of the original mSupply.
https://msupply.foundation/open-msupply/
Other
23 stars 14 forks source link

Importing a fridge tag fails if an import has happened in another store #4755

Open mark-prins opened 2 months ago

mark-prins commented 2 months ago

What went wrong? šŸ˜²

Given:

Then: any fridge tag import will fail

The issue is that this call to check matching sensor config (berlinger.rs, line 204)

let result = get_matching_sensor_breach_config(
        connection,
        &sensor_row.store_id,
        temperature_breach_config,
        &breach_row_type,
    )?;

    if !result.is_empty() {
        return Ok(());
    };

is checking for a config based on store_id, duration_milliseconds, minimum_temperature, maximum_temperature and type. However, the constraint on the table is for a unique description and this does not include the store_id, so the insert following the code above will fail.

Expected behaviour šŸ¤”

Able to import the fridge tag data for a new store.

How to Reproduce šŸ”Ø

Steps to reproduce the behaviour:

  1. Go to Cold chain / monitoring
  2. Import a fridge tag
  3. Switch to another store and repeat
  4. See error

Your environment šŸŒ±

lache-melvin commented 2 months ago

Setting as normal as I don't believe there are any deployed multi-store sites, but you should be able to do this!

adrianwb commented 2 months ago

Yes, you shouldn't be able to import the same fridgetag into a different store (you'd need to move it to the new store first), but you should definitely be able to import a different fridgetag

lache-melvin commented 1 month ago

See PR for needs refinement context šŸ™

jmbrunskill commented 1 month ago

Refinement:

If you import a fridge tag and you're logged into a store, other than the one already associated with the sensor, throw error. Duplicated configs for different stores is ok...

adamdewey commented 3 weeks ago

Yes, you shouldn't be able to import the same fridgetag into a different store (you'd need to move it to the new store first), but you should definitely be able to import a different fridgetag

How do you move a Fridge-tag to a different store?

adrianwb commented 3 weeks ago

Yes, you shouldn't be able to import the same fridgetag into a different store (you'd need to move it to the new store first), but you should definitely be able to import a different fridgetag

How do you move a Fridge-tag to a different store?

Hmm, I was thinking of the "Set location" button when viewing a sensor on desktop mSupply, but just realised that locations are specific to a store, and you can only see sensors associated with the store you're logged into => you can only ever move it to another location in the same store!

You can un-assign a sensor location though, and that blanks out the sensor's location, but doesn't change its store => if we changed vaccineShowSensor to include sensors with a blank location, then it would show up if you login to a different store and then you could assign a location in the new store (and that would change the sensor's store as well)?

The other issue if you move store is that you'd still want to be able to see the original temperature logs and breaches in the original store. vaccineShowTemperatureBreach filters the breaches by store, so that's fine. vaccineShowLogs filters temperature logs by store, so that's also fine, but it also filters sensors by store, so that would need tweaked so that it filters by locations which belong to the current store instead.

I'd imagine that something similar is also possible in omSupply?

adamdewey commented 3 weeks ago

Hmm, I was thinking of the "Set location" button when viewing a sensor on desktop mSupply, but just realised that locations are specific to a store, and you can only see sensors associated with the store you're logged into => you can only ever move it to another location in the same store!

Ah, I wonder if this is also what happened for me on the oms demo server.

I had sensors (not Fridge-tag) associated with a store, then switched them to a new store on the same site.

The Chart page shows the data ok, but the sensors don't appear in the Sensors page

image

image

image