preserve carbs

This commit is contained in:
AdrianLxM 2018-07-22 13:42:21 +02:00 committed by AdrianLxM
parent 2e1d473243
commit b435c09771

View file

@ -256,6 +256,12 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
// another treatment exists. Update it with the treatment coming from the pump
log.debug("TREATMENT: Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
long oldDate = existingTreatment.date;
//preserve carbs
if(existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0){
treatment.carbs = existingTreatment.carbs;
}
getDao().delete(existingTreatment); // need to delete/create because date may change too
existingTreatment.copyBasics(treatment);
getDao().create(existingTreatment);
@ -273,6 +279,12 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
boolean sameSource = existingTreatment.source == treatment.source;
long oldDate = existingTreatment.date;
log.debug("TREATMENT: Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
//preserve carbs
if(existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0){
treatment.carbs = existingTreatment.carbs;
}
getDao().delete(existingTreatment); // need to delete/create because date may change too
existingTreatment.copyFrom(treatment);
getDao().create(existingTreatment);