Sha256: e58808a0cf7b30d473a40adfb12563ea4b76b39bcd9b3d0ff3ad1c63e24c1224
Contents?: true
Size: 1.05 KB
Versions: 127
Compression:
Stored size: 1.05 KB
Contents
module Comee module Core class OrderSource < ApplicationRecord has_many :field_mappings validates :base_url, :name, presence: true validate :validate_field_mapping def validate_field_mapping return unless field_mapping mappings = field_mapping.map(&:with_indifferent_access) order_fields = %w[order_number order_date delivery_address invoice_address] item_fields = %w[customer_item_no customer_item_description unit_code quantity price delivery_date] order_dest = mappings.select { |mapping| mapping[:level] == "order" }.map { |m| m[:destination] } item_dest = mappings.select { |mapping| mapping[:level] == "item" }.map { |m| m[:destination] } order_diff = order_fields - order_dest item_diff = item_fields - item_dest errors.add(:field_mapping, "has fields #{order_diff} missing at order level.") if order_diff.count.positive? errors.add(:field_mapping, "has fields #{item_diff} missing at item level.") if item_diff.count.positive? end end end end
Version data entries
127 entries across 127 versions & 1 rubygems