From 8863ac7047ec648b879d17aeabc3cbd207bcf3a5 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Fri, 6 Jan 2023 10:31:20 +0100 Subject: [PATCH] (bug) no main item on some invoices --- CHANGELOG.md | 1 + app/models/invoice.rb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7a778036..e3098e34d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog Fab-manager +- Fix a bug: no main item on some invoices - Fix a bug: unable to build accounting lines if no invoices - Fix a bug: unable to apply rounding correction on accounting lines - Fix a bug: empty object for some invoice item diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 1e31cf7ab..a0ef80aec 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -132,7 +132,12 @@ class Invoice < PaymentDocument end def main_item - invoice_items.where(main: true).first + main = invoice_items.where(main: true).first + if main.nil? + main = invoice_items.order(id: :asc).first + main&.update(main: true) + end + main end def other_items