From ebb2b9c6f03987de23814e28451c6e22304f688b Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Wed, 28 Aug 2024 14:45:23 +0200 Subject: [PATCH] add enum type for tax codes that are applicable on whole invoice when serializing to graphql --- .../types/invoices/applied_taxes/object.rb | 5 +++++ .../whole_invoice_applicable_tax_code_enum.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 app/graphql/types/invoices/applied_taxes/whole_invoice_applicable_tax_code_enum.rb diff --git a/app/graphql/types/invoices/applied_taxes/object.rb b/app/graphql/types/invoices/applied_taxes/object.rb index 9b29a7954076..adffac1c941e 100644 --- a/app/graphql/types/invoices/applied_taxes/object.rb +++ b/app/graphql/types/invoices/applied_taxes/object.rb @@ -8,8 +8,13 @@ class Object < Types::BaseObject implements Types::Taxes::AppliedTax field :applied_on_whole_invoice, GraphQL::Types::Boolean, null: false, method: :applied_on_whole_invoice? + field :enumed_tax_code, Types::Invoices::AppliedTaxes::WholeInvoiceApplicableTaxCodeEnum, required: false field :fees_amount_cents, GraphQL::Types::BigInt, null: false field :invoice, Types::Invoices::Object, null: false + + def enumed_tax_code + object.tax_code if object.applied_on_whole_invoice? + end end end end diff --git a/app/graphql/types/invoices/applied_taxes/whole_invoice_applicable_tax_code_enum.rb b/app/graphql/types/invoices/applied_taxes/whole_invoice_applicable_tax_code_enum.rb new file mode 100644 index 000000000000..10c77c9200d1 --- /dev/null +++ b/app/graphql/types/invoices/applied_taxes/whole_invoice_applicable_tax_code_enum.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Types + module Invoices + module AppliedTaxes + class WholeInvoiceApplicableTaxCodeEnum < Types::BaseEnum + graphql_name 'InvoiceAppliedTaxOnWholeInvoiceCodeEnum' + + Invoice::AppliedTax::TAX_CODES_APPLICABLE_ON_WHOLE_INVOICE.each do |type| + value type + end + end + end + end +end