From 4112797a6191c8cc0204482babdececd10bc9e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Semp=C3=A9?= Date: Fri, 30 Aug 2024 14:48:43 +0200 Subject: [PATCH] feat(dunning): Add hasOverdueInvoices field to customer resolver --- app/graphql/types/customers/object.rb | 5 +++++ schema.graphql | 5 +++++ schema.json | 18 ++++++++++++++++++ spec/graphql/types/customers/object_spec.rb | 1 + 4 files changed, 29 insertions(+) diff --git a/app/graphql/types/customers/object.rb b/app/graphql/types/customers/object.rb index 0f9438c4cc4..14b273d31d9 100644 --- a/app/graphql/types/customers/object.rb +++ b/app/graphql/types/customers/object.rb @@ -73,6 +73,7 @@ class Object < Types::BaseObject description: 'Number of available credits from credit notes per customer' field :has_active_wallet, Boolean, null: false, description: 'Define if a customer has an active wallet' field :has_credit_notes, Boolean, null: false, description: 'Define if a customer has any credit note' + field :has_overdue_invoices, Boolean, null: false, description: 'Define if a customer has overdue invoices' field :can_edit_attributes, Boolean, null: false, method: :editable? do description 'Check if customer attributes are editable' @@ -98,6 +99,10 @@ def has_credit_notes object.credit_notes.finalized.any? end + def has_overdue_invoices + object.invoices.payment_overdue.any? + end + def active_subscriptions_count object.active_subscriptions.count end diff --git a/schema.graphql b/schema.graphql index 6f9d1c6b09a..6235b169bea 100644 --- a/schema.graphql +++ b/schema.graphql @@ -3082,6 +3082,11 @@ type Customer { Define if a customer has any credit note """ hasCreditNotes: Boolean! + + """ + Define if a customer has overdue invoices + """ + hasOverdueInvoices: Boolean! id: ID! invoiceGracePeriod: Int invoices: [Invoice!] diff --git a/schema.json b/schema.json index 8af525e9702..34e64fbabde 100644 --- a/schema.json +++ b/schema.json @@ -12208,6 +12208,24 @@ ] }, + { + "name": "hasOverdueInvoices", + "description": "Define if a customer has overdue invoices", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, { "name": "id", "description": null, diff --git a/spec/graphql/types/customers/object_spec.rb b/spec/graphql/types/customers/object_spec.rb index d933ff5d8f1..66076548956 100644 --- a/spec/graphql/types/customers/object_spec.rb +++ b/spec/graphql/types/customers/object_spec.rb @@ -64,6 +64,7 @@ it { is_expected.to have_field(:credit_notes_credits_available_count).of_type('Int!') } it { is_expected.to have_field(:has_active_wallet).of_type('Boolean!') } it { is_expected.to have_field(:has_credit_notes).of_type('Boolean!') } + it { is_expected.to have_field(:has_overdue_invoices).of_type('Boolean!') } it { is_expected.to have_field(:can_edit_attributes).of_type('Boolean!') } end