]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-381] force without obj creation
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 1 Apr 2025 07:57:48 +0000 (10:57 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 1 Apr 2025 07:57:48 +0000 (10:57 +0300)
erp24/records/BouquetComposition.php

index 6927ebd8fdb1c31863e251ffd26b0b628b533d04..9a70d7541d097634d053ff771646d42bdb9eaef2 100644 (file)
@@ -452,15 +452,20 @@ class BouquetComposition extends ActiveRecord
     public function getCostModel($region_id, $data = null, $force = false) {
         $costModel = BouquetCompositionPrice::find()->where(['bouquet_id' => $this->id, 'region_id' => $region_id])->one();
         if (!$costModel || $force) {
-            $costModel = new BouquetCompositionPrice;
-            $costModel->bouquet_id = $this->id;
-            $costModel->region_id = $region_id;
+            if (!$costModel) {
+                $costModel = new BouquetCompositionPrice;
+                $costModel->bouquet_id = $this->id;
+                $costModel->region_id = $region_id;
+            }
             $costModel->selfcost = $this->getSelfCost($data);
             $costModel->selfcost_markup = 30;
             $costModel->selfcost_markup_price = 0.3 * $costModel->selfcost;
             $costModel->price = round(1.15 * ($costModel->selfcost_markup_price + $costModel->selfcost));
             $costModel->price_markup = $costModel->selfcost > 0 ? 100 * ($costModel->price / ($costModel->selfcost_markup_price + $costModel->selfcost) - 1): 0;
             $costModel->save();
+            if ($costModel->getErrors()) {
+                throw new Exception(Json::encode($costModel->getErrors()));
+            }
         }
         return $costModel;
     }