comee_core 0.1.56 → 0.1.58

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ead330a4756361db4ef55e9a2716c50fc103c78c17cc18a197e42b1363ce4d4a
4
- data.tar.gz: 4f88d44825eccafe77978ae5e71906af4afe657955fc20ead6cde17e035eab8c
3
+ metadata.gz: 5c1ab21501ec9e7dc8a68ab5bde8797d3cf224c5ffcc18777e9e8fdea9fc20f6
4
+ data.tar.gz: ab88ed5fa5e8905c6a4d00cb4b0b2104b3c56844bb5994bf339a19de39627372
5
5
  SHA512:
6
- metadata.gz: 9a217c3a5f68e644bde348dff1821170f087f24a4b652f28e840de2ed1c52dd4daf581d837e2e359b014f75842652078146087ad10fcd41beead9896e42f34ca
7
- data.tar.gz: 713f0e53ba812000b184a81c55c04e8b83b3977397906718c8adc8970de5463c0706a4884942ec95357353f6edac3bc7a431f4bea81a099851aca1ff39730ad2
6
+ metadata.gz: e14a39305accdef097595d2cc9dd9173d7a355cb094e4f3332d9e28091be587e25eb6463646cd298ac3fff3fb018838e7fbfafb880fa5f724c022e0537dcbbda
7
+ data.tar.gz: 810bf9d239709215543739222b4555ded5a008109c6373f1320a912b81e14ab738f0e3995fb6ed7219f4f05533b80ecfceb290fad43b97b12f01f89d1a886b69
@@ -3,6 +3,22 @@ module Comee
3
3
  class OrderSource < ApplicationRecord
4
4
  has_many :field_mappings
5
5
  validates :base_url, :name, presence: true
6
+ validate :validate_field_mapping
7
+
8
+ def validate_field_mapping
9
+ return unless field_mapping
10
+
11
+ mappings = field_mapping.map(&:with_indifferent_access)
12
+ order_fields = %w[order_number order_date delivery_address invoice_address]
13
+ item_fields = %w[product_code product_name unit_code quantity price delivery_date]
14
+ order_dest = mappings.select { |mapping| mapping[:level] == "order" }.map { |m| m[:destination] }
15
+ item_dest = mappings.select { |mapping| mapping[:level] == "item" }.map { |m| m[:destination] }
16
+ order_diff = order_fields - order_dest
17
+ item_diff = item_fields - item_dest
18
+ errors.add(:field_mapping, "has fields #{order_diff} missing at order level.") if order_diff.count.positive?
19
+
20
+ errors.add(:field_mapping, "has fields #{item_diff} missing at item level.") if item_diff.count.positive?
21
+ end
6
22
  end
7
23
  end
8
24
  end
@@ -3,6 +3,7 @@ class CreateComeeCoreOrderSources < ActiveRecord::Migration[7.0]
3
3
  create_table :comee_core_order_sources do |t|
4
4
  t.string :base_url, null: false
5
5
  t.string :name, null: false
6
+ t.jsonb :field_mapping, null: false
6
7
 
7
8
  t.timestamps
8
9
  end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.56".freeze
3
+ VERSION = "0.1.58".freeze
4
4
  end
5
5
  end
@@ -2,5 +2,19 @@ FactoryBot.define do
2
2
  factory :order_source, class: "Comee::Core::OrderSource" do
3
3
  base_url { Faker::Internet.url }
4
4
  name { Faker::Name.name }
5
+ field_mapping do
6
+ [
7
+ {source: "order_number", destination: "order_number", level: :order},
8
+ {source: "order_date", destination: "order_date", level: :order},
9
+ {source: "delivery_address", destination: "delivery_address", level: :order},
10
+ {source: "invoice_address", destination: "invoice_address", level: :order},
11
+ {source: "product_code", destination: "product_code", level: :item},
12
+ {source: "product_name", destination: "product_name", level: :item},
13
+ {source: "unit_code", destination: "unit_code", level: :item},
14
+ {source: "quantity", destination: "quantity", level: :item},
15
+ {source: "price", destination: "price", level: :item},
16
+ {source: "delivery_date", destination: "delivery_date", level: :item}
17
+ ]
18
+ end
5
19
  end
6
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.56
4
+ version: 0.1.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-17 00:00:00.000000000 Z
11
+ date: 2023-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -319,7 +319,6 @@ files:
319
319
  - app/models/comee/core/customs_detail.rb
320
320
  - app/models/comee/core/edi_order.rb
321
321
  - app/models/comee/core/external_rfq.rb
322
- - app/models/comee/core/field_mapping.rb
323
322
  - app/models/comee/core/fulfillment_center.rb
324
323
  - app/models/comee/core/inventory.rb
325
324
  - app/models/comee/core/invoice.rb
@@ -401,7 +400,6 @@ files:
401
400
  - db/migrate/20230915205522_create_comee_core_invoices.rb
402
401
  - db/migrate/20230915205648_create_comee_core_invoice_items.rb
403
402
  - db/migrate/20230929115336_create_comee_core_order_sources.rb
404
- - db/migrate/20230929120051_create_comee_core_field_mappings.rb
405
403
  - db/migrate/20230929130910_create_comee_core_client_orders.rb
406
404
  - db/migrate/20231003073316_create_comee_core_inventories.rb
407
405
  - db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb
@@ -432,7 +430,6 @@ files:
432
430
  - spec/factories/comee/core/customs_details.rb
433
431
  - spec/factories/comee/core/edi_orders.rb
434
432
  - spec/factories/comee/core/external_rfqs.rb
435
- - spec/factories/comee/core/field_mappings.rb
436
433
  - spec/factories/comee/core/fulfillment_centers.rb
437
434
  - spec/factories/comee/core/inventories.rb
438
435
  - spec/factories/comee/core/invoice_items.rb
@@ -1,9 +0,0 @@
1
- module Comee
2
- module Core
3
- class FieldMapping < ApplicationRecord
4
- enum :level, {client_order: 0, client_item: 1}
5
- belongs_to :order_source
6
- validates :source, :destination, :level, :order_source, presence: true
7
- end
8
- end
9
- end
@@ -1,15 +0,0 @@
1
- class CreateComeeCoreFieldMappings < ActiveRecord::Migration[7.0]
2
- def change
3
- create_table :comee_core_field_mappings do |t|
4
- t.string :source, null: false
5
- t.string :destination, null: false
6
- t.integer :level, null: false, default: 0
7
- t.references :order_source,
8
- null: false,
9
- index: {name: "order_source_on_cfm_indx"},
10
- foreign_key: {to_table: :comee_core_order_sources}
11
-
12
- t.timestamps
13
- end
14
- end
15
- end
@@ -1,8 +0,0 @@
1
- FactoryBot.define do
2
- factory :field_mapping, class: "Comee::Core::FieldMapping" do
3
- source { Faker::Lorem.word }
4
- destination { Faker::Lorem.word }
5
- level { Comee::Core::FieldMapping.levels[:client_item] }
6
- order_source
7
- end
8
- end