agris 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +21 -0
  6. data/README.md +36 -0
  7. data/Rakefile +6 -0
  8. data/agris.gemspec +30 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/agris.rb +61 -0
  12. data/lib/agris/api.rb +21 -0
  13. data/lib/agris/api/accounts_payables.rb +30 -0
  14. data/lib/agris/api/accounts_receivables.rb +11 -0
  15. data/lib/agris/api/accounts_receivables/invoice.rb +166 -0
  16. data/lib/agris/api/accounts_receivables/invoices.rb +29 -0
  17. data/lib/agris/api/accounts_receivables/specific_invoice_extract.rb +17 -0
  18. data/lib/agris/api/document_query_response.rb +59 -0
  19. data/lib/agris/api/grain.rb +12 -0
  20. data/lib/agris/api/grain/new_ticket.rb +118 -0
  21. data/lib/agris/api/grain/new_ticket_application.rb +34 -0
  22. data/lib/agris/api/grain/new_ticket_remark.rb +23 -0
  23. data/lib/agris/api/grain/tickets.rb +17 -0
  24. data/lib/agris/api/inventory.rb +16 -0
  25. data/lib/agris/api/inventory/delivery_ticket.rb +84 -0
  26. data/lib/agris/api/inventory/delivery_ticket_line_item.rb +59 -0
  27. data/lib/agris/api/inventory/delivery_tickets.rb +30 -0
  28. data/lib/agris/api/inventory/orders.rb +51 -0
  29. data/lib/agris/api/inventory/specific_delivery_ticket_extract.rb +17 -0
  30. data/lib/agris/api/inventory/specific_order_extract.rb +18 -0
  31. data/lib/agris/api/messages.rb +25 -0
  32. data/lib/agris/api/messages/import.rb +40 -0
  33. data/lib/agris/api/messages/message_base.rb +42 -0
  34. data/lib/agris/api/messages/query_base.rb +37 -0
  35. data/lib/agris/api/messages/query_changed_delivery_tickets.rb +41 -0
  36. data/lib/agris/api/messages/query_changed_invoices.rb +48 -0
  37. data/lib/agris/api/messages/query_changed_orders.rb +41 -0
  38. data/lib/agris/api/messages/query_delivery_ticket_documents.rb +35 -0
  39. data/lib/agris/api/messages/query_invoice_documents.rb +40 -0
  40. data/lib/agris/api/messages/query_order_documents.rb +35 -0
  41. data/lib/agris/api/new_order.rb +86 -0
  42. data/lib/agris/api/new_order_remark.rb +22 -0
  43. data/lib/agris/api/new_voucher.rb +113 -0
  44. data/lib/agris/api/order.rb +63 -0
  45. data/lib/agris/api/order_line.rb +32 -0
  46. data/lib/agris/api/post_result.rb +24 -0
  47. data/lib/agris/api/remark.rb +16 -0
  48. data/lib/agris/api/support.rb +77 -0
  49. data/lib/agris/api/tran_code.rb +17 -0
  50. data/lib/agris/client.rb +39 -0
  51. data/lib/agris/context.rb +6 -0
  52. data/lib/agris/credentials.rb +7 -0
  53. data/lib/agris/credentials/anonymous.rb +11 -0
  54. data/lib/agris/credentials/basic_auth.rb +15 -0
  55. data/lib/agris/process_message_response.rb +58 -0
  56. data/lib/agris/resources/post_sales_order.xml +93 -0
  57. data/lib/agris/resources/post_sales_order_response.xml +21 -0
  58. data/lib/agris/savon_request.rb +73 -0
  59. data/lib/agris/user_agent.rb +7 -0
  60. data/lib/agris/version.rb +3 -0
  61. data/lib/agris/xml_model.rb +62 -0
  62. metadata +188 -0
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module AccountsReceivables
5
+ module Invoices
6
+ def invoice(invoice_location, invoice_number)
7
+ extract = Agris::Api::AccountsReceivables::SpecificInvoiceExtract
8
+ .new(invoice_location, invoice_number)
9
+
10
+ invoices([extract])
11
+ end
12
+
13
+ def invoices(extracts)
14
+ extract_documents(
15
+ Messages::QueryInvoiceDocuments.new(extracts),
16
+ Agris::Api::AccountsReceivables::Invoice
17
+ )
18
+ end
19
+
20
+ def invoices_changed_since(datetime, detail = false)
21
+ extract_documents(
22
+ Messages::QueryChangedInvoices.new(datetime, detail),
23
+ Agris::Api::AccountsReceivables::Invoice
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module AccountsReceivables
5
+ class SpecificInvoiceExtract
6
+ include ::Agris::XmlModel
7
+
8
+ attr_accessor :invoice_location, :invoice_no
9
+
10
+ def initialize(invoice_location, invoice_number)
11
+ @invoice_location = invoice_location
12
+ @invoice_no = invoice_number
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ # rubocop:disable Rails/TimeZone
3
+ module Agris
4
+ module Api
5
+ class DocumentQueryResponse
6
+ def initialize(output_hash, resource_type = nil)
7
+ @output_hash = output_hash
8
+ @objects = nil
9
+ @resource_type = resource_type if resource_type
10
+ end
11
+
12
+ def last_request_date_time
13
+ DateTime.parse(
14
+ @output_hash["#{resource_name}s"]['system']['lastrequestdatetime']
15
+ )
16
+ end
17
+
18
+ def documents
19
+ @objects ||= parse
20
+ end
21
+
22
+ protected
23
+
24
+ def parse
25
+ resources
26
+ .map do |order_hash|
27
+ resource_type.from_xml_hash(order_hash)
28
+ end
29
+ end
30
+
31
+ def resource_name
32
+ @resource_name ||= resource_type
33
+ .name
34
+ .split('::')
35
+ .last
36
+ .downcase
37
+ end
38
+
39
+ def resource_type
40
+ @resource_type ||= Object.const_get(
41
+ self
42
+ .class
43
+ .name
44
+ .split('::')
45
+ .last
46
+ .chomp('ExtractResponse')
47
+ )
48
+ end
49
+
50
+ def resources
51
+ # Wrap and flatten for single responses
52
+ [@output_hash["#{resource_name}s"][resource_name]]
53
+ .compact
54
+ .flatten
55
+ end
56
+ end
57
+ end
58
+ end
59
+ # rubocop:enable Rails/TimeZone
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Grain
5
+ autoload :NewTicket, 'agris/api/grain/new_ticket'
6
+ autoload :NewTicketApplication, 'agris/api/grain/new_ticket_application'
7
+ autoload :NewTicketRemark, 'agris/api/grain/new_ticket_remark'
8
+ autoload :Tickets,
9
+ 'agris/api/grain/tickets'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Grain
5
+ class NewTicket
6
+ include XmlModel
7
+
8
+ ATTRIBUTE_NAMES = %w(
9
+ in_out_code
10
+ ticket_location
11
+ ticket_number
12
+ type
13
+ shipment_date
14
+ entry_date
15
+ ship_to_from_id
16
+ commodity
17
+ variety_class
18
+ storage_bin
19
+ transport_mode
20
+ shipper_id
21
+ vehicle_id
22
+ other_ref
23
+ trancode_4
24
+ trancode_5
25
+ weight_base
26
+ grade_base
27
+ freight_status
28
+ disc_tables
29
+ net_quantity
30
+ gross_weight
31
+ tare_weight
32
+ freight_weight
33
+ freight_rate
34
+ additional_freight
35
+ cash_price
36
+ cash_basis
37
+ gross_date
38
+ gross_time
39
+ gross_entry_method
40
+ tare_date
41
+ tare_time
42
+ tare_entry_method
43
+ driver_id
44
+ car_set_date
45
+ notify_date
46
+ days_allowed
47
+ short_sample_number
48
+ add_update_reverse_option
49
+ adjust_inventory
50
+ freight_tax_percent
51
+ shipment_id
52
+ update_field_selection
53
+ grade_agency_id
54
+ grade_certificate_date
55
+ grade_certificate_number
56
+ weight_agency_id
57
+ weight_certificate_date
58
+ weight_certificate_number
59
+ hauler_id
60
+ weight_uom
61
+ quantity_uom
62
+ freight_currency
63
+ exchange_rate
64
+ exchange_rate_date
65
+ their_invoice_number
66
+ exec_id
67
+ reverse_instruction
68
+ first_4_discount_tables
69
+ sample_number
70
+ last_4_discount_tables
71
+ split_group
72
+ producer_id
73
+ farm
74
+ field
75
+ ).freeze
76
+
77
+ attr_reader :record_type
78
+ attr_accessor(*ATTRIBUTE_NAMES)
79
+
80
+ def initialize(hash = {})
81
+ super
82
+
83
+ @record_type = 'GRNT0'
84
+ end
85
+
86
+ def add_application(application)
87
+ @applications ||= []
88
+ @applications << application
89
+
90
+ self
91
+ end
92
+
93
+ def add_remark(remark)
94
+ @remarks ||= []
95
+ @remarks << remark
96
+
97
+ self
98
+ end
99
+
100
+ def applications
101
+ @applications || []
102
+ end
103
+
104
+ def records
105
+ [self] + applications + remarks
106
+ end
107
+
108
+ def remarks
109
+ @remarks || []
110
+ end
111
+
112
+ def xml_ignore_attributes
113
+ %i(applications remarks)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Grain
5
+ class NewTicketApplication
6
+ include XmlModel
7
+
8
+ ATTRIBUTE_NAMES = %w(
9
+ apply_type
10
+ expected_apply_type
11
+ apply_name_id
12
+ apply_location
13
+ apply_reference
14
+ apply_reference_pricing
15
+ gross_quantity
16
+ net_quantity
17
+ position_quantity
18
+ apply_date
19
+ contract_variety_class
20
+ recalculate_discounts
21
+ ).freeze
22
+
23
+ attr_reader :record_type
24
+ attr_accessor(*ATTRIBUTE_NAMES)
25
+
26
+ def initialize(hash = {})
27
+ super
28
+
29
+ @record_type = 'GRNT1'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Grain
5
+ class NewTicketRemark
6
+ include XmlModel
7
+
8
+ ATTRIBUTE_NAMES = %w(
9
+ number
10
+ value
11
+ ).freeze
12
+
13
+ attr_reader :record_type
14
+
15
+ def initialize(hash = {})
16
+ super
17
+
18
+ @record_type = 'GRNT2'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Grain
5
+ module Tickets
6
+ # Create a new Grain ticket in Agris.
7
+ #
8
+ # In future I don't think we'll need a method per type of thing we want
9
+ # to create in Agris, but rather have a single import method that we
10
+ # just pass in the New*** model we want to create.
11
+ def create_ticket(ticket)
12
+ import(ticket)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Inventory
5
+ autoload :DeliveryTicket, 'agris/api/inventory/delivery_ticket'
6
+ autoload :DeliveryTicketLineItem,
7
+ 'agris/api/inventory/delivery_ticket_line_item'
8
+ autoload :DeliveryTickets, 'agris/api/inventory/delivery_tickets'
9
+ autoload :Orders, 'agris/api/inventory/orders'
10
+ autoload :SpecificDeliveryTicketExtract,
11
+ 'agris/api/inventory/specific_delivery_ticket_extract'
12
+ autoload :SpecificOrderExtract,
13
+ 'agris/api/inventory/specific_order_extract'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Inventory
5
+ class DeliveryTicket
6
+ include XmlModel
7
+
8
+ ATTRIBUTE_NAMES = %w(
9
+ ticket_status
10
+ ticket_status_description
11
+ ticket_location
12
+ ticket_location_description
13
+ ticket_number
14
+ pickup_delivery
15
+ shipment_date
16
+ void_date
17
+ bill_to_id
18
+ bill_to_description
19
+ state_county
20
+ state_county_description
21
+ user_order_field_1
22
+ user_order_field_2
23
+ external_order_number
24
+ ship_to_id
25
+ ship_to_description
26
+ shipper_id
27
+ shipper_description
28
+ broker_id
29
+ broker_description
30
+ invoice_terms
31
+ terms_description
32
+ entry_date
33
+ delete
34
+ last_change_date_time
35
+ last_change_user_id
36
+ last_change_user_name
37
+ unique_id
38
+ ).freeze
39
+
40
+ attr_reader(*(%w(line_items remarks tran_codes) + ATTRIBUTE_NAMES))
41
+
42
+ def self.from_xml_hash(hash)
43
+ super.tap do |delivery_ticket|
44
+ if hash['lineitems']
45
+ delivery_ticket.line_items.concat(
46
+ [hash['lineitems']['lineitem']]
47
+ .flatten
48
+ .map do |lineitem|
49
+ DeliveryTicketLineItem.from_xml_hash(lineitem)
50
+ end
51
+ )
52
+ end
53
+ if hash['remarks']
54
+ delivery_ticket.remarks.concat(
55
+ [hash['remarks']['remark']]
56
+ .flatten
57
+ .map do |remark|
58
+ Agris::Api::Remark.from_xml_hash(remark)
59
+ end
60
+ )
61
+ end
62
+ if hash['trancodes']
63
+ delivery_ticket.tran_codes.concat(
64
+ [hash['trancodes']['trancode']]
65
+ .flatten
66
+ .map do |trancode|
67
+ Agris::Api::TranCode.from_xml_hash(trancode)
68
+ end
69
+ )
70
+ end
71
+ end
72
+ end
73
+
74
+ def initialize(hash = {})
75
+ super
76
+
77
+ @line_items = []
78
+ @remarks = []
79
+ @tran_codes = []
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module Inventory
5
+ class DeliveryTicketLineItem
6
+ include XmlModel
7
+
8
+ ATTRIBUTE_NAMES = %w(
9
+ line_item_number
10
+ activity_location
11
+ activity_location_description
12
+ inventory_location
13
+ inventory_location_description
14
+ inventory_item
15
+ inventory_item_description
16
+ sub_item_1
17
+ sub_item_1_description
18
+ sub_item_2
19
+ product_category
20
+ category_description
21
+ individual_charge_id
22
+ individual_charge_description
23
+ order_location
24
+ order_location_description
25
+ order_number
26
+ weight_uom
27
+ weight_uom_description
28
+ quantity_uom
29
+ quantity_uom_description
30
+ price_uom
31
+ price_uom_description
32
+ other_reference
33
+ execution_id
34
+ execution_id_description
35
+ quantity
36
+ unit_price
37
+ total_price
38
+ unit_cost
39
+ total_cost
40
+ gross_weight
41
+ tare_weight
42
+ net_weight
43
+ invoice_number
44
+ invoice_location
45
+ invoice_location_description
46
+ in_blend
47
+ blend_number
48
+ formula_no
49
+ source_type
50
+ restricted_product
51
+ change_type
52
+ change_type_description
53
+ ).freeze
54
+
55
+ attr_reader(*ATTRIBUTE_NAMES)
56
+ end
57
+ end
58
+ end
59
+ end