diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 893a83c..43bab07 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -28,7 +28,7 @@ class PProduct < ApplicationRecord has_many :p_product_images belongs_to :p_customer - + belongs_to :sorecop_cat belongs_to :p_product_cat belongs_to :s_brand diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 2588ad3..5e2992c 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -10,7 +10,6 @@ class PProductRef < ApplicationRecord has_many :p_product_ref_price_histories belongs_to :p_product_color - belongs_to :sorecop_cat has_many :p_articles has_many :p_article_serial_nums, through: :p_articles @@ -46,7 +45,7 @@ class PProductRef < ApplicationRecord :ct_sub_name => {:name => "Nom référence"}, :ct_price_ht => {:name => "Prix de vente", :as => :currency}, :ean => {:name => "EAN"}, - :ca_deee => {:name => "DEEE", :as => :currency}, + :deee => {:name => "DEEE", :as => :currency}, :sorecop => {:name => "Sorecop", :as => :currency}, :sorecop_comment => {:name => "Commentaire Sorecop"}, :actions => {:name => "Actions", :reorder => false} @@ -156,27 +155,27 @@ 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")).empty? - "Pas de stockage" - else - find_sorecop_tax - end - end + return ct_sorecop if ct_sorecop + return "Pas de catégorie Sorecop" if self.p_product.sorecop_cat.blank? + + if self.cc_sorecop + return self.cc_sorecop else - "Pas de catégorie Sorecop" + find_sorecop_tax end 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.to_f - tax = self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + p_product_ref_spec = self.p_product_ref_specs.where(p_spec_type: PSpecType.find_by_name("Stockage")).first + return "Pas de stockage" if p_product_ref_spec.blank? + + storage_capacity = p_product_ref_spec.p_spec_value.value.to_f + if p_product_ref_spec.p_spec_value.unit.casecmp?("Go") + tax = self.p_product.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + elsif p_product_ref_spec.p_spec_value.unit.casecmp?("To") + tax = self.p_product.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity * 1000, storage_capacity * 1000).first + end + if tax.fixed_price tax.price else @@ -185,10 +184,13 @@ class PProductRef < ApplicationRecord end def ca_deee + if ct_deee + return ct_deee + end if self.cc_deee return self.cc_deee else - "TODO Calcul DEEE" + "DEEE à renseigner" end end diff --git a/app/models/sorecop_cat.rb b/app/models/sorecop_cat.rb index a0af0d4..ebb0575 100644 --- a/app/models/sorecop_cat.rb +++ b/app/models/sorecop_cat.rb @@ -1,5 +1,5 @@ class SorecopCat < ApplicationRecord - has_many :p_product_refs + has_many :p_products has_many :sorecop_taxes, dependent: :destroy acts_as_sorting :fields => { diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index 7ce89d3..89561b6 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -23,8 +23,6 @@ %td =form.input :ean %tr - %td - =form.input :sorecop_cat_id, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true %td =form.input :ct_sorecop, :label => "Sorecop personalisée :" %td diff --git a/app/views/admin/p_products/_form.html.haml b/app/views/admin/p_products/_form.html.haml index dcc5078..d298195 100755 --- a/app/views/admin/p_products/_form.html.haml +++ b/app/views/admin/p_products/_form.html.haml @@ -19,7 +19,8 @@ =# f.input :stocked, :label => "Suivi de stock ?" - + .col-sm-2 + =f.input :sorecop_cat, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true @@ -112,4 +113,4 @@ - \ No newline at end of file + diff --git a/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb b/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb deleted file mode 100644 index b4d65a9..0000000 --- a/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddSorecopCatIdToPProductRefs < ActiveRecord::Migration[6.0] - def change - add_column :p_product_refs, :sorecop_cat_id, :integer - end -end diff --git a/db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb b/db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb new file mode 100644 index 0000000..6091257 --- /dev/null +++ b/db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb @@ -0,0 +1,5 @@ +class AddSorecopCatIdToPProducts < ActiveRecord::Migration[6.0] + def change + add_column :p_products, :sorecop_cat_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 5e36bad..0c04f68 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_23_170130) do +ActiveRecord::Schema.define(version: 2021_09_24_145644) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1801,7 +1801,6 @@ ActiveRecord::Schema.define(version: 2021_09_23_170130) do t.decimal "ct_deee", precision: 10, scale: 2 t.string "ean" t.string "sorecop_comment" - t.integer "sorecop_cat_id" end create_table "p_product_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| @@ -1891,6 +1890,7 @@ ActiveRecord::Schema.define(version: 2021_09_23_170130) do t.decimal "finesse_max", precision: 6, scale: 2 t.boolean "conserve_proportion", default: false t.boolean "frontpage", default: true + t.integer "sorecop_cat_id" t.index ["p_product_cat_id"], name: "index_p_products_on_p_product_cat_id" t.index ["s_brand_id"], name: "index_p_products_on_s_brand_id" end