This repository has been archived on 2021-11-24. You can view files and clone it, but cannot push or open issues or pull requests.
phone_app/app/models/partition_line.rb
2021-08-23 10:26:02 +02:00

37 lines
864 B
Ruby

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