qbwc_requests 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/qbwc_requests/{qbwc/request/v07/account.rb → account/v07/add.rb} +3 -3
- data/lib/qbwc_requests/account/v07/query.rb +9 -0
- data/lib/qbwc_requests/base.rb +76 -0
- data/lib/qbwc_requests/bill/v07/add.rb +11 -0
- data/lib/qbwc_requests/bill/v07/query.rb +9 -0
- data/lib/qbwc_requests/customer/v07/add.rb +39 -0
- data/lib/qbwc_requests/customer/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/estimate.rb → estimate/v07/add.rb} +5 -4
- data/lib/qbwc_requests/estimate/v07/query.rb +9 -0
- data/lib/qbwc_requests/factory.rb +32 -0
- data/lib/qbwc_requests/general_detail_report/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/invoice.rb → invoice/v07/add.rb} +5 -5
- data/lib/qbwc_requests/invoice/v07/query.rb +9 -0
- data/lib/qbwc_requests/item/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/item_discount.rb → item_discount/v07/add.rb} +5 -4
- data/lib/qbwc_requests/item_discount/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/item_group.rb → item_group/v07/add.rb} +4 -3
- data/lib/qbwc_requests/item_group/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/item_non_inventory.rb → item_non_inventory/v07/add.rb} +5 -4
- data/lib/qbwc_requests/item_non_inventory/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/item_other_charge.rb → item_other_charge/v07/add.rb} +4 -3
- data/lib/qbwc_requests/item_other_charge/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/item_payment.rb → item_payment/v07/add.rb} +4 -3
- data/lib/qbwc_requests/item_payment/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/item_service.rb → item_service/v07/add.rb} +4 -3
- data/lib/qbwc_requests/item_service/v07/query.rb +9 -0
- data/lib/qbwc_requests/{qbwc/request/v07/item_subtotal.rb → item_subtotal/v07/add.rb} +5 -4
- data/lib/qbwc_requests/item_subtotal/v07/query.rb +9 -0
- data/lib/qbwc_requests/ordered_fields.rb +81 -0
- data/lib/qbwc_requests/purchase_order/v07/add.rb +33 -0
- data/lib/qbwc_requests/{qbwc/request/v07/purchase_order.rb → purchase_order/v07/mod.rb} +10 -14
- data/lib/qbwc_requests/purchase_order/v07/query.rb +9 -0
- data/lib/qbwc_requests/sub_models/address.rb +27 -0
- data/lib/qbwc_requests/vendor/v07/add.rb +44 -0
- data/lib/qbwc_requests/vendor/v07/mod.rb +44 -0
- data/lib/qbwc_requests/vendor/v07/query.rb +9 -0
- data/lib/qbwc_requests/vendor/v13/add.rb +44 -0
- data/lib/qbwc_requests/vendor/v13/mod.rb +44 -0
- data/lib/qbwc_requests/vendor/v13/query.rb +9 -0
- data/lib/qbwc_requests/version.rb +1 -1
- data/lib/qbwc_requests/{qbwc/xml_actions.rb → xml_actions.rb} +2 -9
- data/lib/qbwc_requests.rb +51 -5
- data/qbwc_requests.gemspec +4 -2
- data/quickbook/dtd/qbxmlops60.dtd +3043 -0
- data/quickbook/dtd/qbxmlops60_2.dtd +3019 -0
- data/scripts/dtd_to_classes.rb +3 -0
- data/spec/account_qbxml_spec.rb +42 -0
- data/spec/{qbwc/request/v07/bill_spec.rb → bill_qbxml_spec.rb} +10 -5
- data/spec/customer_qbxml_spec.rb +57 -0
- data/spec/{qbwc/request/v07/estimate_spec.rb → estimate_qbxml_spec.rb} +19 -8
- data/spec/general_detail_report_qbxml_spec.rb +9 -0
- data/spec/{qbwc/request/v07/invoice_spec.rb → invoice_qbxml_spec.rb} +11 -9
- data/spec/{qbwc/request/v07/item_discount_spec.rb → item_discount_qbxml_spec.rb} +10 -8
- data/spec/{qbwc/request/v07/item_group_spec.rb → item_group_qbxml_spec.rb} +9 -7
- data/spec/{qbwc/request/v07/item_non_inventory_spec.rb → item_non_inventory_qbxml_spec.rb} +9 -7
- data/spec/{qbwc/request/v07/item_other_charge_spec.rb → item_other_charge_qbxml_spec.rb} +10 -8
- data/spec/{qbwc/request/v07/item_payment_spec.rb → item_payment_qbxml_spec.rb} +10 -7
- data/spec/item_qbxml_spec.rb +9 -0
- data/spec/{qbwc/request/v07/item_service_spec.rb → item_service_qbxml_spec.rb} +9 -7
- data/spec/{qbwc/request/v07/item_subtotal_spec.rb → item_subtotal_qbxml_spec.rb} +12 -10
- data/spec/job_report_qbxml_spec.rb +7 -0
- data/spec/{qbwc/request/v07/purchase_orders_spec.rb → purchase_order_qbxml_spec.rb} +11 -10
- data/spec/spec_helper.rb +5 -0
- data/spec/support/expectations/field_validations.rb +2 -2
- data/spec/support/expectations/xml_equal.rb +4 -2
- data/spec/support/shared_examples_for_xml_requests.rb +18 -20
- data/spec/vendor_qbxml_spec.rb +111 -0
- metadata +113 -68
- data/lib/qbwc_requests/qbwc/ordered_fields.rb +0 -35
- data/lib/qbwc_requests/qbwc/qbwc.rb +0 -2
- data/lib/qbwc_requests/qbwc/request/base.rb +0 -77
- data/lib/qbwc_requests/qbwc/request/v07/bill.rb +0 -9
- data/lib/qbwc_requests/qbwc/request/v07/customer.rb +0 -29
- data/lib/qbwc_requests/qbwc/request/v07/general_detail_report.rb +0 -11
- data/lib/qbwc_requests/qbwc/request/v07/item.rb +0 -11
- data/lib/qbwc_requests/qbwc/request/v07/job_report.rb +0 -3
- data/lib/qbwc_requests/qbwc/request/v07/vendor.rb +0 -31
- data/lib/qbwc_requests/qbwc/request/v07/vendor_address.rb +0 -17
- data/spec/qbwc/request/base_spec.rb +0 -61
- data/spec/qbwc/request/v07/account_spec.rb +0 -32
- data/spec/qbwc/request/v07/customer_spec.rb +0 -32
- data/spec/qbwc/request/v07/general_detail_report_spec.rb +0 -7
- data/spec/qbwc/request/v07/item_spec.rb +0 -7
- data/spec/qbwc/request/v07/job_report_spec.rb +0 -7
- data/spec/qbwc/request/v07/vendor_spec.rb +0 -31
- data/spec/qbwc/request/xml_actions_spec.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 55e98a7c49505aa0fe9b0fac41e7073849a55636
|
|
4
|
+
data.tar.gz: d272895bce72dfa14c73e32040ffc40773b59658
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10dc09cfdeac01e7f944bd673e54f73dc381ba63b74a8fcf6a3790ed007e9063f269e29914ad4448780669431e19a99c97e26278ea2ef02f60d9c05b41b26dc3
|
|
7
|
+
data.tar.gz: 2d30beb012534d3fe8ad7f511636315ac7f809ab6e1921bcf239575b1aa9f4172339022d7ab6e4d297a3454df1522a4260762c1a7a4743db67dc8d86e979a0a1
|
data/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
With qbwc_requests you have an easy way to create Qbxml requests.
|
|
4
4
|
|
|
5
5
|
[](https://semaphoreci.com/apotema/qbwc_requests)
|
|
6
|
+
[](https://codeclimate.com/github/apotema/qbwc_requests)
|
|
7
|
+
[](https://codeclimate.com/github/apotema/qbwc_requests/coverage)
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
@@ -29,7 +31,7 @@ Or install it yourself as:
|
|
|
29
31
|
result
|
|
30
32
|
|
|
31
33
|
```xml
|
|
32
|
-
<?xml version=
|
|
34
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
33
35
|
<?qbxml version="7.0"?>
|
|
34
36
|
<QBXML>
|
|
35
37
|
<QBXMLMsgsRq onError="stopOnError">
|
|
@@ -51,7 +53,7 @@ That will create an Account query for the qbxml version 7.0
|
|
|
51
53
|
result
|
|
52
54
|
|
|
53
55
|
```xml
|
|
54
|
-
<?xml version=
|
|
56
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
55
57
|
<?qbxml version="7.0"?>
|
|
56
58
|
<QBXML>
|
|
57
59
|
<QBXMLMsgsRq onError="stopOnError">
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
class Base
|
|
3
|
+
|
|
4
|
+
include QbwcRequests::OrderedFields
|
|
5
|
+
include QbwcRequests::XmlActions
|
|
6
|
+
|
|
7
|
+
def to_xml request_id
|
|
8
|
+
self.valid? ? xml(request_id, self.class.name.demodulize) : self
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initialize(attributes = {})
|
|
12
|
+
@attributes = compact(attributes)
|
|
13
|
+
@attributes.each do |name, value|
|
|
14
|
+
self.instance_variable_set("@#{name}", value) if value.present?
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.qbxml hash
|
|
19
|
+
Qbxml.new(:qb, "#{version.to_i}.0").to_qbxml(hash)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def class_name
|
|
23
|
+
self.class.underscore(self.class.name.split("::")[1].gsub("Qbxml",""))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.version
|
|
27
|
+
self.name.split("::")[2].gsub("V","")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def persisted?
|
|
31
|
+
false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def self.underscore string
|
|
37
|
+
string.gsub(/::/, '/').
|
|
38
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
|
39
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
|
40
|
+
tr("-", "_").
|
|
41
|
+
downcase
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def compact opts={}
|
|
45
|
+
# I pass two times to avoid {v: '1',k: {}}, gotta find a better algorithm (recursive)
|
|
46
|
+
return {} if opts.nil?
|
|
47
|
+
proc = Proc.new { |k, v| v.kind_of?(Hash) ? (v.delete_if(&proc); nil) : (v == nil || (v.respond_to?(:empty) && v.empty?)) };
|
|
48
|
+
hash = opts.delete_if(&proc)
|
|
49
|
+
hash.delete_if { |k, v| (v == nil || (v.respond_to?(:empty) && v.empty?)) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def xml request_id, action
|
|
53
|
+
req = XmlActions.header
|
|
54
|
+
if action != "Query"
|
|
55
|
+
req['qbxml']['qbxml_msgs_rq']["#{class_name}_#{action}_rq"] = {"xml_attributes"=>
|
|
56
|
+
{"requestID"=>"#{request_id}"},
|
|
57
|
+
"#{class_name}_#{action}"=> self.ordered_fields
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
req['qbxml']= {
|
|
61
|
+
'qbxml_msgs_rq' => {
|
|
62
|
+
"xml_attributes" => {
|
|
63
|
+
"onError"=>"stopOnError"
|
|
64
|
+
},
|
|
65
|
+
"#{class_name}_query_rq" => {
|
|
66
|
+
"xml_attributes" => {
|
|
67
|
+
"requestID" => "#{request_id}"}
|
|
68
|
+
}.merge(self.ordered_fields)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
end
|
|
72
|
+
self.class.qbxml(req)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module Customer
|
|
3
|
+
module V07
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
|
+
|
|
6
|
+
field :name
|
|
7
|
+
field :is_active
|
|
8
|
+
ref_to :parent, 1000
|
|
9
|
+
field :company_name
|
|
10
|
+
field :salutation
|
|
11
|
+
field :first_name
|
|
12
|
+
field :middle_name
|
|
13
|
+
field :last_name
|
|
14
|
+
field :bill_address
|
|
15
|
+
field :ship_address
|
|
16
|
+
field :phone
|
|
17
|
+
field :alt_phone
|
|
18
|
+
field :fax
|
|
19
|
+
field :email
|
|
20
|
+
field :contact
|
|
21
|
+
field :alt_contact
|
|
22
|
+
|
|
23
|
+
validates :name, presence: true, length: { maximum: 41 }
|
|
24
|
+
validates :company_name, length: { maximum: 41 }
|
|
25
|
+
validates :salutation, length: { maximum: 15 }
|
|
26
|
+
validates :first_name, length: { maximum: 25 }
|
|
27
|
+
validates :middle_name, length: { maximum: 5 }
|
|
28
|
+
validates :last_name, length: { maximum: 25 }
|
|
29
|
+
validates :phone, length: { maximum: 21 }
|
|
30
|
+
validates :alt_phone, length: { maximum: 21 }
|
|
31
|
+
validates :fax, length: { maximum: 21 }
|
|
32
|
+
validates :email, length: { maximum: 1023 }
|
|
33
|
+
validates :contact, length: { maximum: 41 }
|
|
34
|
+
validates :alt_contact, length: { maximum: 41 }
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module Estimate
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
ref_to :customer, 209
|
|
7
7
|
field :estimate_line_add
|
|
8
8
|
|
|
9
9
|
validates :customer_ref, presence: true
|
|
10
10
|
validates :estimate_line_add, presence: true
|
|
11
|
+
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module Factory
|
|
3
|
+
|
|
4
|
+
class Instantiator
|
|
5
|
+
|
|
6
|
+
def initialize module_name, klass
|
|
7
|
+
@module_name = module_name
|
|
8
|
+
@klass = klass
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def factory params = {}, version = nil
|
|
12
|
+
final_version = version || QbwcRequests.QBXML_VERSION
|
|
13
|
+
object = Object.const_get("QbwcRequests::#{@module_name}::V#{final_version}::#{@klass}")
|
|
14
|
+
object.new(params)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def name
|
|
18
|
+
@module_name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def const_missing(name)
|
|
25
|
+
if [:Mod, :Add, :Query].include?(name)
|
|
26
|
+
Instantiator.new(self.name.gsub("Qbxml",""),name)
|
|
27
|
+
else
|
|
28
|
+
raise "NameError: uninitialized constant #{name}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module Invoice
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
ref_to :customer, 209
|
|
7
7
|
field :invoice_line_add
|
|
8
8
|
|
|
9
9
|
validates :customer_ref, presence: true
|
|
10
10
|
validates :invoice_line_add, presence: true
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module ItemDiscount
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
6
|
field :name
|
|
7
7
|
field :is_active
|
|
8
|
-
|
|
8
|
+
ref_to :account, 159
|
|
9
9
|
field :discount_rate
|
|
10
10
|
|
|
11
11
|
validates :name, presence: true
|
|
12
|
+
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module ItemGroup
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
6
|
field :name
|
|
7
7
|
field :is_active
|
|
8
8
|
field :item_desc
|
|
9
9
|
|
|
10
10
|
validates :name, presence: true
|
|
11
|
+
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
data/lib/qbwc_requests/{qbwc/request/v07/item_non_inventory.rb → item_non_inventory/v07/add.rb}
RENAMED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module ItemNonInventory
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
6
|
field :name
|
|
7
7
|
field :is_active
|
|
8
8
|
field :pricetype
|
|
9
|
-
|
|
9
|
+
ref_to :parent, 1000
|
|
10
10
|
|
|
11
11
|
validates :name, presence: true
|
|
12
|
+
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
data/lib/qbwc_requests/{qbwc/request/v07/item_other_charge.rb → item_other_charge/v07/add.rb}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module ItemOtherCharge
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
6
|
field :name
|
|
7
7
|
field :is_active
|
|
@@ -10,6 +10,7 @@ module Qbwc
|
|
|
10
10
|
|
|
11
11
|
validates :sales_or_purchase, presence: true
|
|
12
12
|
validates :name, presence: true, length: { maximum: 41 }
|
|
13
|
+
|
|
13
14
|
end
|
|
14
15
|
end
|
|
15
16
|
end
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module ItemPayment
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
6
|
field :name
|
|
7
7
|
field :is_active
|
|
8
8
|
field :item_desc
|
|
9
9
|
|
|
10
10
|
validates :name, presence: true
|
|
11
|
+
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module ItemService
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
5
|
|
|
6
6
|
field :name
|
|
7
7
|
field :is_active
|
|
@@ -9,6 +9,7 @@ module Qbwc
|
|
|
9
9
|
field :sales_or_purchase
|
|
10
10
|
|
|
11
11
|
validates :name, presence: true
|
|
12
|
+
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module ItemSubtotal
|
|
3
3
|
module V07
|
|
4
|
-
class
|
|
5
|
-
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
|
+
|
|
6
6
|
field :name
|
|
7
7
|
field :is_active
|
|
8
8
|
field :item_desc
|
|
9
9
|
field :bar_code
|
|
10
10
|
|
|
11
11
|
validates :name, presence: true
|
|
12
|
+
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module OrderedFields
|
|
3
|
+
module ClassMethods
|
|
4
|
+
def field attribute_name
|
|
5
|
+
@attr_order ||= Set.new
|
|
6
|
+
@attr_order << attribute_name
|
|
7
|
+
attr_accessor attribute_name
|
|
8
|
+
end
|
|
9
|
+
def has_one attribute_name, klass
|
|
10
|
+
@attr_order ||= Set.new
|
|
11
|
+
@attr_order << attribute_name
|
|
12
|
+
attr_accessor attribute_name
|
|
13
|
+
validates_each attribute_name do |record, attribute, value|
|
|
14
|
+
if !value.blank? and value.class != klass
|
|
15
|
+
record.errors.add(attribute, "must be of type #{klass}")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
def ref_to attribute_prefix, name_length
|
|
20
|
+
attribute_name = "#{attribute_prefix}_ref".to_sym
|
|
21
|
+
@attr_order ||= Set.new
|
|
22
|
+
@attr_order << attribute_name
|
|
23
|
+
attr_accessor attribute_name
|
|
24
|
+
validates_each attribute_name do |record, attribute, value|
|
|
25
|
+
if value.present?
|
|
26
|
+
if value.is_a?(Hash)
|
|
27
|
+
if !(value[:list_id].present? ^ value[:full_name].present?)
|
|
28
|
+
record.errors.add(attribute, "Must have list_id or full_name")
|
|
29
|
+
elsif value.fetch(:full_name, "").length > name_length
|
|
30
|
+
record.errors.add(attribute, "- maximum 'full name' length is: #{name_length}")
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
record.errors.add(attribute, "Must have the format {list_id: 'value'} or {full_name: 'value'}")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
def attr_order
|
|
39
|
+
@attr_order
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class SubModelsValidator < ActiveModel::Validator
|
|
44
|
+
def validate record
|
|
45
|
+
return true if record.class.attr_order.blank?
|
|
46
|
+
for field in record.class.attr_order
|
|
47
|
+
value = record.send(field)
|
|
48
|
+
if value.respond_to?(:valid?) and value.invalid?
|
|
49
|
+
for error in value.errors
|
|
50
|
+
record.errors.add("#{field}##{error}", value.errors.messages[error] )
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.included(base)
|
|
58
|
+
base.extend(ActiveModel::Naming)
|
|
59
|
+
base.include(ActiveModel::Validations)
|
|
60
|
+
base.include(ActiveModel::Conversion)
|
|
61
|
+
base.extend(ClassMethods)
|
|
62
|
+
base.validates_with(SubModelsValidator)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def ordered_fields
|
|
66
|
+
return {} if self.class.attr_order.blank?
|
|
67
|
+
new_hash = {}
|
|
68
|
+
for attribute in self.class.attr_order
|
|
69
|
+
value = send(attribute)
|
|
70
|
+
if value.present?
|
|
71
|
+
if value.respond_to?(:ordered_fields)
|
|
72
|
+
new_hash[attribute] = value.ordered_fields
|
|
73
|
+
else
|
|
74
|
+
new_hash[attribute] = value
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
new_hash
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module QbwcRequests
|
|
2
|
+
module PurchaseOrder
|
|
3
|
+
module V07
|
|
4
|
+
class Add < QbwcRequests::Base
|
|
5
|
+
|
|
6
|
+
ref_to :vendor, 41
|
|
7
|
+
ref_to :class, 159
|
|
8
|
+
ref_to :ship_to_entity, 209
|
|
9
|
+
ref_to :template, 31
|
|
10
|
+
field :txn_date
|
|
11
|
+
field :ref_number
|
|
12
|
+
field :vendor_address
|
|
13
|
+
field :ship_address
|
|
14
|
+
ref_to :terms, 31
|
|
15
|
+
field :due_date
|
|
16
|
+
field :expected_date
|
|
17
|
+
ref_to :ship_method, 15
|
|
18
|
+
field :FOB
|
|
19
|
+
field :memo
|
|
20
|
+
field :vendor_msg
|
|
21
|
+
field :is_to_be_printed
|
|
22
|
+
field :is_to_be_emailed
|
|
23
|
+
field :is_tax_included
|
|
24
|
+
ref_to :sales_tax_code, 3
|
|
25
|
+
field :other1
|
|
26
|
+
field :other2
|
|
27
|
+
field :purchase_order_line_add
|
|
28
|
+
field :purchase_order_line_group_add
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|