module Logistics module Core class DemurrageRate < ApplicationRecord belongs_to :demurrage_rate_period belongs_to :unit_of_charge def self.generate_demurage_rate(rate_period_id) unit_of_charges = UnitOfCharge.all unit_of_charges.each { |unit_of_charge| uoc = DemurrageRate.where('unit_of_charge_id' => unit_of_charge.id, 'demurage_rate_period_id' => rate_period_id) if uoc.count == 0 DemurrageRate.create('unit_of_charge_id' => unit_of_charge.id, 'demurage_rate_period_id' => rate_period_id, 'rate' => 0) end } end end end end