From: Alexander Smirnov Date: Tue, 1 Apr 2025 07:57:48 +0000 (+0300) Subject: [ERP-381] force without obj creation X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=2572ac32646a14d61adb1cf07cbabbccc6fc3913;p=erp24_rep%2Fyii-erp24%2F.git [ERP-381] force without obj creation --- diff --git a/erp24/records/BouquetComposition.php b/erp24/records/BouquetComposition.php index 6927ebd8..9a70d754 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -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; }