Class: Einvoice::Tradevan::Validator::ItemListValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/einvoice/tradevan/validator/issue_data_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribtue, value) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/einvoice/tradevan/validator/issue_data_validator.rb', line 56

def validate_each(record, attribtue, value)
  if record.itemList.map(&:itemTotal).map(&:blank?).reduce(&:|)
    record.errors[:itemList] << options[:message] || :invalid
  elsif record.itemList.map(&:taxType).map(&:blank?).reduce(&:|)
    record.errors[:itemList] << options[:message] || :invalid
  else
    # none
  end

  if %w(A H).include?(record.type)
    if record.itemList.map(&:invoiceNumber).map(&:blank?).reduce(&:|)
      record.errors[:itemList] << options[:message] || :invalid
    elsif record.itemList.map(&:invoiceDate).map(&:blank?).reduce(&:|)
      record.errors[:itemList] << options[:message] || :invalid
    elsif record.itemList.map(&:itemExclude).map(&:blank?).reduce(&:|)
      record.errors[:itemList] << options[:message] || :invalid
    else
      # none
    end
  end
end