Class: QuickbooksCustomerResolver
- Inherits:
-
Object
- Object
- QuickbooksCustomerResolver
- Includes:
- QuickbooksCustomerHelper
- Defined in:
- app/resolver/quickbooks_customer_resolver.rb
Overview
QuickbooksCustomerResolver handles the creation, updating, and integration of QuickBooks customers with the application’s customer data model. It processes customer data from QuickBooks API and performs the necessary operations to maintain data consistency between systems.
This resolver is responsible for:
-
Finding existing integrated customers by external reference code
-
Finding existing customers by code and name for integration
-
Creating new customers when no match is found
-
Updating existing customers with the latest data from QuickBooks
-
Creating and managing customer hierarchy (head office, distribution center)
-
Adding integration references to track the connection between systems
Defined Under Namespace
Classes: Actions
Constant Summary collapse
- USER_NAME =
'SYSTEM'
Instance Attribute Summary collapse
-
#company_id ⇒ Object
readonly
Returns the value of attribute company_id.
-
#default_province_id ⇒ Object
readonly
Returns the value of attribute default_province_id.
-
#quickbooks_customer ⇒ Object
readonly
Returns the value of attribute quickbooks_customer.
-
#suffix_code ⇒ Object
readonly
Returns the value of attribute suffix_code.
-
#tenant_id ⇒ Object
readonly
Returns the value of attribute tenant_id.
Instance Method Summary collapse
-
#initialize(company_id:, tenant_id:, suffix_code:, default_province_id:, quickbooks_customer:) ⇒ QuickbooksCustomerResolver
constructor
Initializes a new QuickbooksCustomerResolver.
-
#resolve ⇒ Hash
Processes the QuickBooks customer data and performs the necessary actions to integrate it with the application’s customer data model.
Methods included from QuickbooksCustomerHelper
#check_and_create_member_customer, #check_and_set_customer_hierarchy, #external_reference_code, #extract_shipping_address_from_quickbooks_customer, #find_currency_id, #find_payment_term_id, #find_type, #format_known_as, #formatted_code
Methods included from CustomerHierarchyManagement
#assign_customer_hierarchy, #billing_shipping_addresses_match?, #create_dc_customer_for_shipping_address, #create_member_customer_for_shipping_address, #determine_hierarchy_attributes, #find_customer_with_same_address, #shipping_address_valid?
Methods included from AddressHelper
#canadian_postal_code?, #clean_city, #normalize_postal_code, #parse_address_line, #parse_address_parts, #us_zip_code?, #valid_city?, #valid_state?
Constructor Details
#initialize(company_id:, tenant_id:, suffix_code:, default_province_id:, quickbooks_customer:) ⇒ QuickbooksCustomerResolver
Initializes a new QuickbooksCustomerResolver
48 49 50 51 52 53 54 55 |
# File 'app/resolver/quickbooks_customer_resolver.rb', line 48 def initialize(company_id:, tenant_id:, suffix_code:, default_province_id:, quickbooks_customer:) @company_id = company_id @tenant_id = tenant_id @suffix_code = suffix_code @default_province_id = default_province_id @quickbooks_customer = quickbooks_customer.with_indifferent_access @customer_service = CustomerService.new(USER_NAME) end |
Instance Attribute Details
#company_id ⇒ Object (readonly)
Returns the value of attribute company_id.
38 39 40 |
# File 'app/resolver/quickbooks_customer_resolver.rb', line 38 def company_id @company_id end |
#default_province_id ⇒ Object (readonly)
Returns the value of attribute default_province_id.
38 39 40 |
# File 'app/resolver/quickbooks_customer_resolver.rb', line 38 def default_province_id @default_province_id end |
#quickbooks_customer ⇒ Object (readonly)
Returns the value of attribute quickbooks_customer.
38 39 40 |
# File 'app/resolver/quickbooks_customer_resolver.rb', line 38 def quickbooks_customer @quickbooks_customer end |
#suffix_code ⇒ Object (readonly)
Returns the value of attribute suffix_code.
38 39 40 |
# File 'app/resolver/quickbooks_customer_resolver.rb', line 38 def suffix_code @suffix_code end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
38 39 40 |
# File 'app/resolver/quickbooks_customer_resolver.rb', line 38 def tenant_id @tenant_id end |
Instance Method Details
#resolve ⇒ Hash
Processes the QuickBooks customer data and performs the necessary actions to integrate it with the application’s customer data model
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/resolver/quickbooks_customer_resolver.rb', line 62 def resolve ActiveRecord::Base.transaction do if find_integrated_customer update_customer check_and_create_dc_customer_if_needed { action: Actions::UPDATE, customer: @customer } elsif find_customer_to_integrate integrate_customer update_customer check_and_create_dc_customer_if_needed { action: Actions::INTEGRATE, customer: @customer } elsif create_customer integrate_customer check_and_create_dc_customer_if_needed { action: Actions::CREATE, customer: @customer } end end rescue StandardError => e Rails.logger.error "QuickBooks Customer resolve failed: #{e.}" raise e end |