From 135d27e85948b4cf2495312f1795a22629b53964 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sun, 29 Sep 2024 19:44:16 +0200 Subject: [PATCH] fix inserting bills with 0 amount, weird issue with db mapper Signed-off-by: Julien Veyssier --- lib/Service/LocalProjectService.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Service/LocalProjectService.php b/lib/Service/LocalProjectService.php index 9d1239843..28f5fdcb2 100644 --- a/lib/Service/LocalProjectService.php +++ b/lib/Service/LocalProjectService.php @@ -980,7 +980,14 @@ public function createBill( $newBill->setComment($comment); } $newBill->setTimestamp($dateTs); - $newBill->setAmount($amount); + // TODO figure out why it is problematic to insert a bill with an amount of 0 + // this does not happen when inserting a currency with a 0 exchange rate + // it is apparently related with the fact that the methods accept null (even if the db column is set to NOTNULL) + if ($amount === 0.0) { + $newBill->setAmount(1); + } else { + $newBill->setAmount($amount); + } $newBill->setPayerId($payer); $newBill->setRepeat($repeat); $newBill->setRepeatAllActive($repeatAllActive); @@ -996,6 +1003,12 @@ public function createBill( $insertedBillId = $createdBill->getId(); + // TODO remove this after figuring it out + if ($amount === 0.0) { + $createdBill->setAmount(0); + $this->billMapper->update($createdBill); + } + // insert bill owers foreach ($owerIds as $owerId) { $billOwer = new BillOwer();