class PartitionLine < ApplicationRecord belongs_to :partition validates :qte_from, :presence => true validates :qte_to, :presence => true validates :p_product_ref_to_id, :presence => true validates :p_product_ref_from_id, :presence => true belongs_to :p_product_ref_to, :class_name => "PProductRef" belongs_to :p_product_ref_from, :class_name => "PProductRef" def from_weight self.qte_from.to_f * self.p_product_ref_from.weight.to_f if self.p_product_ref_from end def to_weight self.qte_to.to_f * self.p_product_ref_to.weight.to_f if self.p_product_ref_to end def dif_weight self.from_weight - self.to_weight end def stock_available? if LineStock.where(:p_product_ref_id => self.p_product_ref_from_id).sum(:qte_available) >= self.qte_from true else false end end end