-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathpreferences.rb
73 lines (64 loc) · 2.68 KB
/
preferences.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module Quickbooks
module Model
class Preferences < BaseModel
XML_COLLECTION_NODE = "Preferences"
XML_NODE = "Preferences"
REST_RESOURCE = 'preferences'
xml_name XML_NODE
def self.create_preference_class(*attrs, &block)
::Class.new(BaseModel) do
attrs.each do |a|
xml_reader(a.underscore, :from => a.gsub("?", ""))
end
instance_eval(&block) if block_given?
end
end
PREFERENCE_SECTIONS = {
:accounting_info => %w(TrackDepartments DepartmentTerminology ClassTrackingPerTxnLine? ClassTrackingPerTxn? CustomerTerminology),
:product_and_services => %w(ForSales? ForPurchase? QuantityWithPriceAndRate? QuantityOnHand?),
:vendor_and_purchase => %w(TrackingByCustomer? BillableExpenseTracking? DefaultTerms? DefaultMarkup? POCustomField),
:time_tracking => %w(UseServices? BillCustomers? ShowBillRateToAll WorkWeekStartDate MarkTimeEntiresBillable?),
:tax => %w(UsingSalesTax? PartnerTaxEnabled?),
:currency => %w(MultiCurrencyEnabled? HomeCurrency),
:report => %w(ReportBasis)
}
xml_reader :sales_forms, :from => "SalesFormsPrefs", :as => create_preference_class(*%w(
AllowDeposit?
AllowDiscount?
AllowEstimates?
AllowServiceDate?
AllowShipping?
AutoApplyCredit?
CustomField?
CustomTxnNumbers?
DefaultCustomerMessage
DefaultDiscountAccount?
DefaultShippingAccount?
DefaultTerms
EmailCopyToCompany?
EstimateMessage
ETransactionAttachPDF?
ETransactionEnabledStatus
ETransactionPaymentEnabled?
IPNSupportEnabled?
SalesEmailBcc
SalesEmailCc
UsingPriceLevels?
UsingProgressInvoicing?
)) {
xml_reader :custom_fields, :as => [CustomField], :from => 'CustomField', in: 'CustomField'
}
PREFERENCE_SECTIONS.each do |section_name, fields|
xml_reader section_name, :from => "#{section_name}_prefs".camelize, :as => create_preference_class(*fields)
end
EmailMessage = create_preference_class("Subject", "Message")
EmailMessageContainer = create_preference_class do
%w(InvoiceMessage EstimateMessage SalesReceiptMessage StatementMessage).each do |msg|
xml_reader msg.underscore, :from => msg, :as => EmailMessage
end
end
xml_reader :email_messages, :from => "EmailMessagesPrefs", as: EmailMessageContainer
xml_reader :other_prefs, :from => "OtherPrefs/NameValue", :as => { :key => "Name", :value => "Value" }
end
end
end