diff --git a/app/models/customer.rb b/app/models/customer.rb index 5ea0e18d66b..d1e44b1d71a 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -128,17 +128,6 @@ def shipping_address } end - def same_billing_and_shipping_address? - return true if shipping_address.values.all?(&:blank?) - - address_line1 == shipping_address_line1 && - address_line2 == shipping_address_line2 && - city == shipping_city && - zipcode == shipping_zipcode && - state == shipping_state && - country == shipping_country - end - private def ensure_slug diff --git a/app/services/integrations/aggregator/contacts/payloads/netsuite.rb b/app/services/integrations/aggregator/contacts/payloads/netsuite.rb index f3d4372d81b..f667ed35d09 100644 --- a/app/services/integrations/aggregator/contacts/payloads/netsuite.rb +++ b/app/services/integrations/aggregator/contacts/payloads/netsuite.rb @@ -8,7 +8,7 @@ class Netsuite < BasePayload def create_body { 'type' => 'customer', # Fixed value - 'isDynamic' => true, # Fixed value + 'isDynamic' => false, # Fixed value 'columns' => { 'companyname' => customer.name, 'subsidiary' => subsidiary_id, @@ -21,8 +21,7 @@ def create_body }, 'options' => { 'ignoreMandatoryFields' => false # Fixed value - }, - 'lines' => lines + } } end @@ -47,65 +46,6 @@ def update_body private - def lines - if customer.same_billing_and_shipping_address? - [ - { - 'lineItems' => [ - { - 'defaultshipping' => true, - 'defaultbilling' => true, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.address_line1, - 'addr2' => customer.address_line2, - 'city' => customer.city, - 'zip' => customer.zipcode, - 'state' => customer.state, - 'country' => customer.country - } - } - ], - 'sublistId' => 'addressbook' - } - ] - else - [ - { - 'lineItems' => [ - { - 'defaultshipping' => false, - 'defaultbilling' => true, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.address_line1, - 'addr2' => customer.address_line2, - 'city' => customer.city, - 'zip' => customer.zipcode, - 'state' => customer.state, - 'country' => customer.country - } - }, - { - 'defaultshipping' => true, - 'defaultbilling' => false, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.shipping_address_line1, - 'addr2' => customer.shipping_address_line2, - 'city' => customer.shipping_city, - 'zip' => customer.shipping_zipcode, - 'state' => customer.shipping_state, - 'country' => customer.shipping_country - } - } - ], - 'sublistId' => 'addressbook' - } - ] - end - end - def customer_url url = ENV["LAGO_FRONT_URL"].presence || "https://app.getlago.com" diff --git a/spec/factories/customers.rb b/spec/factories/customers.rb index c5f341b38cc..01988f9abdf 100644 --- a/spec/factories/customers.rb +++ b/spec/factories/customers.rb @@ -18,23 +18,5 @@ legal_name { Faker::Company.name } legal_number { Faker::Company.duns_number } currency { 'EUR' } - - trait :with_shipping_address do - shipping_address_line1 { Faker::Address.street_address } - shipping_address_line2 { Faker::Address.secondary_address } - shipping_city { Faker::Address.city } - shipping_zipcode { Faker::Address.zip_code } - shipping_state { Faker::Address.state } - shipping_country { Faker::Address.country_code } - end - - trait :with_same_billing_and_shipping_address do - shipping_address_line1 { address_line1 } - shipping_address_line2 { address_line2 } - shipping_city { city } - shipping_zipcode { zipcode } - shipping_state { state } - shipping_country { country } - end end end diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 3e74b2eabf6..3a2738b4863 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -290,34 +290,4 @@ end end end - - describe '#same_billing_and_shipping_address?' do - subject(:method_call) { customer.same_billing_and_shipping_address? } - - context 'when shipping address is present' do - context 'when shipping address is not the same as billing address' do - let(:customer) { build_stubbed(:customer, :with_shipping_address) } - - it 'returns false' do - expect(subject).to eq(false) - end - end - - context 'when shipping address is the same as billing address' do - let(:customer) { build_stubbed(:customer, :with_same_billing_and_shipping_address) } - - it 'returns true' do - expect(subject).to eq(true) - end - end - end - - context 'when shipping address is not present' do - let(:customer) { build_stubbed(:customer) } - - it 'returns true' do - expect(subject).to eq(true) - end - end - end end diff --git a/spec/services/integrations/aggregator/contacts/create_service_spec.rb b/spec/services/integrations/aggregator/contacts/create_service_spec.rb index 54da602d54c..4d184f4d936 100644 --- a/spec/services/integrations/aggregator/contacts/create_service_spec.rb +++ b/spec/services/integrations/aggregator/contacts/create_service_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Integrations::Aggregator::Contacts::CreateService do subject(:service_call) { described_class.call(integration:, customer:, subsidiary_id:) } - let(:customer) { create(:customer, :with_same_billing_and_shipping_address, organization:) } + let(:customer) { create(:customer, organization:) } let(:subsidiary_id) { '1' } let(:organization) { create(:organization) } let(:lago_client) { instance_double(LagoHttpClient::Client) } @@ -46,7 +46,7 @@ let(:params) do { 'type' => 'customer', - 'isDynamic' => true, + 'isDynamic' => false, 'columns' => { 'companyname' => customer.name, 'subsidiary' => subsidiary_id, @@ -59,27 +59,7 @@ }, 'options' => { 'ignoreMandatoryFields' => false - }, - 'lines' => [ - { - 'lineItems' => [ - { - 'defaultshipping' => true, - 'defaultbilling' => true, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.address_line1, - 'addr2' => customer.address_line2, - 'city' => customer.city, - 'zip' => customer.zipcode, - 'state' => customer.state, - 'country' => customer.country - } - } - ], - 'sublistId' => 'addressbook' - } - ] + } } end @@ -179,7 +159,7 @@ let(:params) do { 'type' => 'customer', - 'isDynamic' => true, + 'isDynamic' => false, 'columns' => { 'companyname' => customer.name, 'subsidiary' => subsidiary_id, @@ -192,27 +172,7 @@ }, 'options' => { 'ignoreMandatoryFields' => false - }, - 'lines' => [ - { - 'lineItems' => [ - { - 'defaultshipping' => true, - 'defaultbilling' => true, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.address_line1, - 'addr2' => customer.address_line2, - 'city' => customer.city, - 'zip' => customer.zipcode, - 'state' => customer.state, - 'country' => customer.country - } - } - ], - 'sublistId' => 'addressbook' - } - ] + } } end diff --git a/spec/services/integrations/aggregator/contacts/payloads/netsuite_spec.rb b/spec/services/integrations/aggregator/contacts/payloads/netsuite_spec.rb index 2d736c7dfc5..741a11af258 100644 --- a/spec/services/integrations/aggregator/contacts/payloads/netsuite_spec.rb +++ b/spec/services/integrations/aggregator/contacts/payloads/netsuite_spec.rb @@ -4,8 +4,8 @@ RSpec.describe Integrations::Aggregator::Contacts::Payloads::Netsuite do let(:integration) { integration_customer.integration } - let(:integration_customer) { FactoryBot.create(:netsuite_customer, customer:) } - let(:customer) { create(:customer) } + let(:customer) { integration_customer.customer } + let(:integration_customer) { FactoryBot.create(:netsuite_customer) } let(:subsidiary_id) { Faker::Number.number(digits: 2) } let(:payload) { described_class.new(integration:, customer:, integration_customer:, subsidiary_id:) } let(:customer_link) { payload.__send__(:customer_url) } @@ -16,7 +16,7 @@ let(:payload_body) do { 'type' => 'customer', - 'isDynamic' => true, + 'isDynamic' => false, 'columns' => { 'companyname' => customer.name, 'subsidiary' => subsidiary_id, @@ -29,117 +29,12 @@ }, 'options' => { 'ignoreMandatoryFields' => false - }, - 'lines' => lines + } } end - context 'when shipping address is present' do - context 'when shipping address is not the same as billing address' do - let(:customer) { create(:customer, :with_shipping_address) } - - let(:lines) do - [ - { - 'lineItems' => [ - { - 'defaultshipping' => false, - 'defaultbilling' => true, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.address_line1, - 'addr2' => customer.address_line2, - 'city' => customer.city, - 'zip' => customer.zipcode, - 'state' => customer.state, - 'country' => customer.country - } - }, - { - 'defaultshipping' => true, - 'defaultbilling' => false, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.shipping_address_line1, - 'addr2' => customer.shipping_address_line2, - 'city' => customer.shipping_city, - 'zip' => customer.shipping_zipcode, - 'state' => customer.shipping_state, - 'country' => customer.shipping_country - } - } - ], - 'sublistId' => 'addressbook' - } - ] - end - - it 'returns the payload body' do - expect(subject).to eq payload_body - end - end - - context 'when shipping address is the same as billing address' do - let(:customer) { create(:customer, :with_same_billing_and_shipping_address) } - - let(:lines) do - [ - { - 'lineItems' => [ - { - 'defaultshipping' => true, - 'defaultbilling' => true, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.address_line1, - 'addr2' => customer.address_line2, - 'city' => customer.city, - 'zip' => customer.zipcode, - 'state' => customer.state, - 'country' => customer.country - } - } - ], - 'sublistId' => 'addressbook' - } - ] - end - - it 'returns the payload body' do - expect(subject).to eq payload_body - end - end - end - - context 'when shipping address is not present' do - let(:customer) { create(:customer) } - - let(:lines) do - [ - { - 'lineItems' => [ - { - 'defaultshipping' => true, - 'defaultbilling' => true, - 'subObjectId' => 'addressbookaddress', - 'subObject' => { - 'addr1' => customer.address_line1, - 'addr2' => customer.address_line2, - 'city' => customer.city, - 'zip' => customer.zipcode, - 'state' => customer.state, - 'country' => customer.country - } - } - ], - 'sublistId' => 'addressbook' - } - ] - end - - it 'returns the payload body' do - expect(subject).to eq payload_body - end + it "returns the payload body" do + expect(subject).to eq payload_body end end