update sorecop calcul

This commit is contained in:
Barnabé 2021-09-24 15:59:38 +02:00
parent e8ebce23ed
commit 72cee7f797

View File

@ -48,7 +48,7 @@ class PProductRef < ApplicationRecord
:ean => {:name => "EAN"}, :ean => {:name => "EAN"},
:ca_deee => {:name => "DEEE", :as => :currency}, :ca_deee => {:name => "DEEE", :as => :currency},
:sorecop => {:name => "Sorecop", :as => :currency}, :sorecop => {:name => "Sorecop", :as => :currency},
:sorecop_comment => {:name => "Type de Sorecop"}, :sorecop_comment => {:name => "Commentaire Sorecop"},
:actions => {:name => "Actions", :reorder => false} :actions => {:name => "Actions", :reorder => false}
} }
@ -156,14 +156,17 @@ class PProductRef < ApplicationRecord
end end
def ca_sorecop def ca_sorecop
if ct_sorecop
return ct_sorecop
end
if self.sorecop_cat if self.sorecop_cat
if self.cc_sorecop if self.cc_sorecop
return self.cc_sorecop return self.cc_sorecop
else else
if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")) if self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).empty?
find_sorecop_tax.price "Pas de stockage"
else else
"Pas de spec de Stockage" find_sorecop_tax
end end
end end
else else
@ -172,8 +175,13 @@ class PProductRef < ApplicationRecord
end end
def find_sorecop_tax 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 storage_capacity = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first.p_spec_value.value.to_f
self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first 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 end
def ca_deee def ca_deee