Added the main record update to the product splitting. Block edit of the product code if the product is splitted.

Thu, 09 Jun 2022 11:16:00 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 09 Jun 2022 11:16:00 +0200
changeset 271
f56c0dff0a3d
parent 270
a0f72d7ace1f
child 272
4f0281b7b0bb

Added the main record update to the product splitting. Block edit of the product code if the product is splitted.

src/EditProductExport.cpp file | annotate | diff | comparison | revisions
src/EditProductTab1.cpp file | annotate | diff | comparison | revisions
--- a/src/EditProductExport.cpp	Wed Jun 08 20:20:57 2022 +0200
+++ b/src/EditProductExport.cpp	Thu Jun 09 11:16:00 2022 +0200
@@ -887,12 +887,11 @@
 
     if (! doit)
 	return;
-    qInfo() << "split starts now";
     for (int i = 0; i < product->splits.size(); i++) {
 	Product *sp = new Product;
 	if (DB_product::load(sp, this, product->record)) {
 	    double factor = round((product->splits.at(i).size / vol_availEdit->value()) * 1000.0) / 1000.0;
-	    qDebug() << "split prep" << i + 1 << product->splits.at(i).code << "factor" << factor;
+	    qInfo() << "Split create part" << i + 1 << "code" << product->splits.at(i).code << "factor" << factor;
 	    sp->record = -1;
 	    sp->uuid = "";
 	    sp->name = product->splits.at(i).name;
@@ -942,13 +941,73 @@
                 sp->mashs[j].step_volume = round(sp->mashs.at(j).step_volume * factor * 100) / 100;
 		sp->mashs[j].step_infuse_amount = round(sp->mashs.at(j).step_infuse_amount * factor * 100) / 100;
             }
-	    DB_product::save(sp, this);
+	    doit = DB_product::save(sp, this);
+	}
+	delete sp;
+	if (! doit)
+	    break;	// If errors
+    }
+
+    if (doit) {	// Still ok?
+	Product *sp = new Product;
+        if (DB_product::load(sp, this, product->record)) {
+            double factor = round((vol_leftEdit->value() / vol_availEdit->value()) * 1000.0) / 1000.0;
+            qInfo() << "Split update main" << sp->code << "factor" << factor;
+	    sp->divide_type = product->divide_type;
+            sp->divide_size = vol_leftEdit->value();
+            sp->divide_factor = factor;
+            sp->divide_parts = product->splits.size();
+            sp->divide_part = 0;
+            /* Now adjust the volumes */
+            sp->brew_sparge_est = sp->brew_sparge_est * factor;
+            sp->brew_preboil_volume = sp->brew_preboil_volume * factor;
+            sp->brew_aboil_volume = sp->brew_aboil_volume * factor;
+            sp->brew_fermenter_volume = sp->brew_fermenter_volume * factor;
+            sp->brew_fermenter_extrawater = sp->brew_fermenter_extrawater * factor;
+            sp->brew_fermenter_tcloss = sp->brew_fermenter_tcloss * factor;
+            sp->package_volume = sp->package_volume * factor;
+            sp->package_infuse_amount = sp->package_infuse_amount * factor;
+            sp->bottle_amount = sp->bottle_amount * factor;
+            sp->bottle_priming_water = sp->bottle_priming_water * factor;
+            sp->keg_amount = sp->keg_amount * factor;
+            sp->keg_priming_water = sp->keg_priming_water * factor;
+            sp->batch_size = sp->batch_size * factor;
+            sp->boil_size = sp->boil_size * factor;
+            sp->sparge_volume = sp->sparge_volume * factor;
+            sp->sparge_acid_amount = sp->sparge_acid_amount * factor;
+            sp->w1_amount = sp->w1_amount * factor;
+            sp->w2_amount = sp->w2_amount * factor;
+            sp->wg_amount = sp->wg_amount * factor;
+            sp->prop_volume[0] = sp->prop_volume[0] * factor;
+            sp->prop_volume[1] = sp->prop_volume[1] * factor;
+            sp->prop_volume[2] = sp->prop_volume[2] * factor;
+            sp->prop_volume[3] = sp->prop_volume[3] * factor;
+	    for (int j = 0; j < sp->fermentables.size(); j++) {
+                sp->fermentables[j].f_amount = round(sp->fermentables.at(j).f_amount * factor * 100000) / 100000;
+            }
+            for (int j = 0; j < sp->hops.size(); j++) {
+                sp->hops[j].h_amount = round(sp->hops.at(j).h_amount * factor * 100000) / 100000;
+            }
+            for (int j = 0; j < sp->miscs.size(); j++) {
+                sp->miscs[j].m_amount = round(sp->miscs.at(j).m_amount * factor * 100000) / 100000;
+            }
+            for (int j = 0; j < sp->yeasts.size(); j++) {
+                sp->yeasts[j].y_amount = round(sp->yeasts.at(j).y_amount * factor * 100000) / 100000;
+            }
+            for (int j = 0; j < sp->mashs.size(); j++) {
+                sp->mashs[j].step_volume = round(sp->mashs.at(j).step_volume * factor * 100) / 100;
+                sp->mashs[j].step_infuse_amount = round(sp->mashs.at(j).step_infuse_amount * factor * 100) / 100;
+            }
+            doit = DB_product::save(sp, this);
 	}
 	delete sp;
     }
+    if (doit)
+	qInfo() << "Split is finished and ok";
+    else
+	qWarning() << "Split errors were found";
 
     /* Make sure the product editor is closed after splitting */
-    qInfo() << "split ready, destroy windows";
     this->close();
     this->setResult(1);
 }
--- a/src/EditProductTab1.cpp	Wed Jun 08 20:20:57 2022 +0200
+++ b/src/EditProductTab1.cpp	Thu Jun 09 11:16:00 2022 +0200
@@ -235,7 +235,7 @@
     ui->ibu_methodEdit->setDisabled(locked);
     ui->beerstyleEdit->setDisabled(stage > PROD_STAGE_WAIT);
     ui->nameEdit->setReadOnly(stage > PROD_STAGE_WAIT);
-    ui->codeEdit->setReadOnly(stage > PROD_STAGE_WAIT);
+    ui->codeEdit->setReadOnly(stage > PROD_STAGE_WAIT || product->divide_type);	/* Never change this in a splitted product. */
     ui->notesEdit->setReadOnly(locked);
     ui->batch_sizeEdit->setReadOnly(stage > PROD_STAGE_WAIT);
     ui->batch_sizeEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
@@ -247,6 +247,10 @@
     ui->efficiencyEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
     ui->est_ogEdit->setReadOnly(stage > PROD_STAGE_WAIT);
     ui->est_ogEdit->setButtonSymbols((stage > PROD_STAGE_WAIT) ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    /*
+     * The next two items are displayed on the same location.
+     * But they are not needed at the same time.
+     */
     if (stage > PROD_STAGE_PACKAGE) {
 	ui->ok_pmptLabel->hide();
 	ui->ok_pmptIcon->hide();

mercurial