From 2572ac32646a14d61adb1cf07cbabbccc6fc3913 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 1 Apr 2025 10:57:48 +0300 Subject: [PATCH] [ERP-381] force without obj creation --- erp24/records/BouquetComposition.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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; } -- 2.39.5