diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index f8cf488..2588ad3 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -48,7 +48,7 @@ class PProductRef < ApplicationRecord :ean => {:name => "EAN"}, :ca_deee => {:name => "DEEE", :as => :currency}, :sorecop => {:name => "Sorecop", :as => :currency}, - :sorecop_comment => {:name => "Type de Sorecop"}, + :sorecop_comment => {:name => "Commentaire Sorecop"}, :actions => {:name => "Actions", :reorder => false} } @@ -156,14 +156,17 @@ class PProductRef < ApplicationRecord end def ca_sorecop + if ct_sorecop + return ct_sorecop + end if self.sorecop_cat if self.cc_sorecop return self.cc_sorecop else - if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")) - find_sorecop_tax.price + if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).empty? + "Pas de stockage" else - "Pas de spec de Stockage" + find_sorecop_tax end end else @@ -172,8 +175,13 @@ class PProductRef < ApplicationRecord end def find_sorecop_tax - storage_capacity = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first.p_spec_value.value - self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + storage_capacity = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first.p_spec_value.value.to_f + tax = self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + if tax.fixed_price + tax.price + else + tax.price * storage_capacity + end end def ca_deee