Skip to content

Commit

Permalink
Update Estimate fields/record_refs for 2021.2 (NetSweet#496)
Browse files Browse the repository at this point in the history
A couple were missing for my use case, so I updated them based on 2021.2

This effectively removes the `balance` and `bill_is_residential` fields.
Best I can tell going back to 2014.1, they were never fields. Perhaps
this was a bad copy-paste when first introducing `Estimate` using
another  record as a starting point?

`is_multi_ship_to` was also removed as it's technically a field of
`TransactionSearchRowBasic`, not `Estimate`. It never could have been
set, and at best it only could have been read after a search. Ideally
it'd be reintroduced in the future as an expansion on the work in NetSweet#483,
extracting a common module to represent the fields from
`TransactionSearchRowBasic`.

`bill_address` was also removed as it last appeared in 2014.1. Now it's a
field of `TransactionSearchRowBasic`, so it could be re-introduced
later, like above.

`billing_schedule` was corrected to be a `record_ref`.

`accountingBookDetailList`, `partnersList`, `salesTeamList`,
`shipGroupList`, and `taxDetailsList` are still missing as `record_refs`
as their corresponding classes haven't been implemented yet.

I improved the `have_field` matcher to optionally take a class argument
for testing the fields that are represented by special classes.

I deviated from the standard style of multiple-fields-per-line-wrapped
for a single-field-per-line style. I found the old style hard to read,
particularly when the fields fell out of alphabetical order, when
scanning to see either what fields were available, or what fields were
already supported. I'd imagine this'll make for cleaner git diffs in the
future too.
  • Loading branch information
cgunther authored Oct 21, 2021
1 parent f0e46a0 commit 7264a51
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 35 deletions.
4 changes: 2 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Added

*
* Update Estimate record fields/record refs for 2021.2. `balance`, `bill_address`, `bill_is_residential`, and `is_multi_ship_to` were all removed as fields as either being incorrect, outdated, or a search-only field. (#496)
*

### Fixed
Expand All @@ -29,4 +29,4 @@
* Fix accessing custom field values returned in advanced search results (#480)
* Fixing bug where single-selection custom multi select fields would incorrectly be parsed 3377c971d0cb727d81f4b4bc6e30edfbdfaccfd1
* Fixed some field definitions on serialized assembly item
* Properly extract external_id from advanced search results (#478)
* Properly extract external_id from advanced search results (#478)
109 changes: 95 additions & 14 deletions lib/netsuite/records/estimate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,105 @@ class Estimate

actions :get, :get_list, :add, :initialize, :delete, :update, :upsert, :search

fields :alt_handling_cost, :alt_sales_total, :alt_shipping_cost, :balance,
:bill_address, :billing_schedule, :bill_is_residential,
:created_date, :currency_name, :discount_rate, :email, :end_date,
:est_gross_profit, :exchange_rate, :handling_cost, :handling_tax1_rate, :is_taxable,
:last_modified_date, :memo, :message, :other_ref_num, :ship_date, :shipping_cost,
:shipping_tax1_rate, :source, :start_date, :status, :sync_partner_teams, :sync_sales_teams,
:to_be_emailed, :to_be_faxed, :to_be_printed, :total_cost_estimate, :tran_date, :tran_id,
:linked_tracking_numbers, :is_multi_ship_to
fields :alt_handling_cost,
:alt_sales_total,
:alt_shipping_cost,
:can_have_stackable,
:contrib_pct,
:created_date,
:currency_name,
:discount_rate,
:discount_total,
:due_date,
:email,
:end_date,
:est_gross_profit,
:est_gross_profit_percent,
:exchange_rate,
:expected_close_date,
:fax,
:fob,
:handling_cost,
:handling_tax1_rate,
:handling_tax2_rate,
:include_in_forecast,
:is_taxable,
:last_modified_date,
:linked_tracking_numbers,
:memo,
:message,
:one_time,
:other_ref_num,
:probability,
:recur_annually,
:recur_monthly,
:recur_quarterly,
:recur_weekly,
:ship_date,
:ship_is_residential,
:shipping_cost,
:shipping_tax1_rate,
:shipping_tax2_rate,
:source,
:start_date,
:status,
:sub_total,
:sync_partner_teams,
:sync_sales_teams,
:tax2_total,
:tax_details_override,
:tax_point_date,
:tax_rate,
:tax_reg_override,
:tax_total,
:title,
:to_be_emailed,
:to_be_faxed,
:to_be_printed,
:total,
:total_cost_estimate,
:tracking_numbers,
:tran_date,
:tran_id,
:vat_reg_num,
:visible_to_customer

field :shipping_address, Address
field :billing_address, Address

field :item_list, EstimateItemList
field :custom_field_list, CustomFieldList
field :item_list, EstimateItemList
field :promotions_list, PromotionsList
field :shipping_address, Address

record_refs :bill_address_list, :created_from, :currency, :custom_form, :department, :discount_item, :entity,
:handling_tax_code, :job, :klass, :lead_source, :location, :message_sel, :opportunity, :partner,
:promo_code, :sales_group, :sales_rep, :ship_method, :shipping_tax_code, :subsidiary, :terms
record_refs :bill_address_list,
:billing_schedule,
:klass,
:created_from,
:currency,
:custom_form,
:department,
:discount_item,
:entity,
:entity_status,
:entity_tax_reg_num,
:forecast_type,
:handling_tax_code,
:job,
:lead_source,
:location,
:message_sel,
:nexus,
:opportunity,
:partner,
:promo_code,
:sales_group,
:sales_rep,
:ship_address_list,
:ship_method,
:shipping_tax_code,
:subsidiary,
:subsidiary_tax_reg_num,
:tax_item,
:terms

attr_reader :internal_id
attr_accessor :external_id
Expand Down
116 changes: 103 additions & 13 deletions spec/netsuite/records/estimate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,117 @@

it 'has all the right fields' do
[
:alt_handling_cost, :alt_shipping_cost,
:balance, :bill_address, :created_date, :currency_name,
:discount_rate, :email, :end_date, :est_gross_profit,
:alt_handling_cost,
:alt_sales_total,
:alt_shipping_cost,
:can_have_stackable,
:contrib_pct,
:created_date,
:currency_name,
:discount_rate,
:discount_total,
:due_date,
:email,
:end_date,
:est_gross_profit,
:est_gross_profit_percent,
:exchange_rate,
:handling_cost, :handling_tax1_rate, :is_taxable,
:last_modified_date, :memo, :message, :other_ref_num,
:shipping_cost, :shipping_tax1_rate,
:source, :start_date, :status, :sync_partner_teams,
:sync_sales_teams, :to_be_emailed, :to_be_faxed, :to_be_printed,
:total_cost_estimate, :tran_date, :tran_id
:expected_close_date,
:fax,
:fob,
:handling_cost,
:handling_tax1_rate,
:handling_tax2_rate,
:include_in_forecast,
:is_taxable,
:last_modified_date,
:linked_tracking_numbers,
:memo,
:message,
:one_time,
:other_ref_num,
:probability,
:recur_annually,
:recur_monthly,
:recur_quarterly,
:recur_weekly,
:ship_date,
:ship_is_residential,
:shipping_cost,
:shipping_tax1_rate,
:shipping_tax2_rate,
:source,
:start_date,
:status,
:sub_total,
:sync_partner_teams,
:sync_sales_teams,
:tax2_total,
:tax_details_override,
:tax_point_date,
:tax_rate,
:tax_reg_override,
:tax_total,
:title,
:to_be_emailed,
:to_be_faxed,
:to_be_printed,
:total,
:total_cost_estimate,
:tracking_numbers,
:tran_date,
:tran_id,
:vat_reg_num,
:visible_to_customer,
].each do |field|
expect(estimate).to have_field(field)
end
end

it 'has all the right fields with specific classes' do
{
billing_address: NetSuite::Records::Address,
custom_field_list: NetSuite::Records::CustomFieldList,
item_list: NetSuite::Records::EstimateItemList,
promotions_list: NetSuite::Records::PromotionsList,
shipping_address: NetSuite::Records::Address,
}.each do |field, klass|
expect(estimate).to have_field(field, klass)
end
end

it 'has all the right record refs' do
[
:bill_address_list, :created_from, :currency, :custom_form, :department, :discount_item,
:entity, :handling_tax_code, :job, :klass, :lead_source, :location, :message_sel,
:opportunity, :partner, :promo_code, :sales_group, :sales_rep,
:ship_method, :shipping_tax_code, :subsidiary
:bill_address_list,
:billing_schedule,
:klass,
:created_from,
:currency,
:custom_form,
:department,
:discount_item,
:entity,
:entity_status,
:entity_tax_reg_num,
:forecast_type,
:handling_tax_code,
:job,
:lead_source,
:location,
:message_sel,
:nexus,
:opportunity,
:partner,
:promo_code,
:sales_group,
:sales_rep,
:ship_address_list,
:ship_method,
:shipping_tax_code,
:subsidiary,
:subsidiary_tax_reg_num,
:tax_item,
:terms,
].each do |record_ref|
expect(estimate).to have_record_ref(record_ref)
end
Expand Down
14 changes: 8 additions & 6 deletions spec/support/field_matcher.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
RSpec::Matchers.define :have_field do |attribute|
RSpec::Matchers.define :have_field do |attribute, klass|

match do |model|
field_can_be_set_and_retrieved?(model, attribute) && field_can_be_set_on_instantiation?(model, attribute)
klass = klass || Object

field_can_be_set_and_retrieved?(model, attribute, klass) && field_can_be_set_on_instantiation?(model, attribute, klass)
end

def field_can_be_set_and_retrieved?(model, attribute)
obj = Object.new
def field_can_be_set_and_retrieved?(model, attribute, klass)
obj = klass.new
model.send("#{attribute}=".to_sym, obj)
model.send(attribute) == obj
end

def field_can_be_set_on_instantiation?(model, attribute)
obj = Object.new
def field_can_be_set_on_instantiation?(model, attribute, klass)
obj = klass.new
new_model = model.class.new(attribute => obj)
new_model.send(attribute) == obj
end
Expand Down

0 comments on commit 7264a51

Please sign in to comment.