fixing available_p_articles method
This commit is contained in:
parent
0e093fac3d
commit
43e26cabf2
@ -62,14 +62,29 @@ class PArticle < ApplicationRecord
|
|||||||
"#{self.p_product_ref.cc_name} #{self.p_article_serial_nums.map{|x| "#{x.p_serial_num_type.name}: #{x.value}"}.join(' / ')}"
|
"#{self.p_product_ref.cc_name} #{self.p_article_serial_nums.map{|x| "#{x.p_serial_num_type.name}: #{x.value}"}.join(' / ')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def self.available_articles
|
||||||
|
# p_articles = PArticle.joins(:line_stocks).where("qte_available > ?", 0)
|
||||||
|
# p_articles.each do |p_article|
|
||||||
|
# if LineStockUsage.where(p_article_id: p_article.id).empty?
|
||||||
|
# p_articles.drop(p_article.id)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# return p_articles
|
||||||
|
# end
|
||||||
|
|
||||||
def self.available_articles
|
def self.available_articles
|
||||||
p_articles = PArticle.joins(:line_stocks).where("qte_available > ?", 0)
|
p_articles = PArticle.joins(:line_stocks).where("qte_available > ?", 0)
|
||||||
|
used_p_articles_ids = LineStockUsage.where.not(p_article_id: nil).pluck(:p_article_id)#.map{|ls| ls.p_article_id}
|
||||||
|
available_p_articles_ids =[]
|
||||||
p_articles.each do |p_article|
|
p_articles.each do |p_article|
|
||||||
if LineStockUsage.where(p_article_id: p_article.id).empty?
|
#puts used_p_articles_ids.include?(p_article.id)
|
||||||
p_articles.drop(p_article.id)
|
if !used_p_articles_ids.include?(p_article.id)
|
||||||
|
available_p_articles_ids << p_article.id
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
return p_articles
|
|
||||||
|
return PArticle.where(id: available_p_articles_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user