lib/netsuite/records/invoice.rb in netsuite-0.0.16 vs lib/netsuite/records/invoice.rb in netsuite-0.0.17

- old
+ new

@@ -39,27 +39,35 @@ @external_id = attributes.delete(:external_id) || attributes.delete(:@external_id) initialize_from_attributes_hash(attributes) end def transaction_bill_address=(attrs) - attributes[:transaction_bill_address] = BillAddress.new(attrs) + attributes[:transaction_bill_address] = attrs.kind_of?(BillAddress) ? attrs : BillAddress.new(attrs) end + def transaction_bill_address + attributes[:transaction_bill_address] ||= BillAddress.new + end + def transaction_ship_address=(attrs) - attributes[:transaction_ship_address] = ShipAddress.new(attrs) + attributes[:transaction_ship_address] = attrs.kind_of?(ShipAddress) ? attrs : ShipAddress.new(attrs) end + def transaction_ship_address + attributes[:transaction_ship_address] ||= ShipAddress.new + end + def item_list attributes[:item_list] ||= InvoiceItemList.new end def custom_field_list attributes[:custom_field_list] ||= CustomFieldList.new end def custom_field_list=(attrs) - attributes[:custom_field_list] = CustomFieldList.new(attrs) + attributes[:custom_field_list] = attrs.kind_of?(CustomFieldList) ? attrs : CustomFieldList.new(attrs) end def self.get(options = {}) response = Actions::Get.call(self, options) if response.success? @@ -72,10 +80,10 @@ def self.initialize(customer) response = Actions::Initialize.call(customer) if response.success? new(response.body) else - raise RecordNotFound, "#{self} with ID=#{id} could not be found" + raise InitializationError, "#{self}.initialize with #{customer} failed." end end def add response = Actions::Add.call(self)