move sorecop_cat to p_product

This commit is contained in:
Barnabé 2021-09-24 17:19:44 +02:00
parent 82fdb06254
commit 60ee0d8197
8 changed files with 33 additions and 32 deletions

View File

@ -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

View File

@ -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

View File

@ -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 => {

View File

@ -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

View File

@ -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

View File

@ -1,5 +0,0 @@
class AddSorecopCatIdToPProductRefs < ActiveRecord::Migration[6.0]
def change
add_column :p_product_refs, :sorecop_cat_id, :integer
end
end

View File

@ -0,0 +1,5 @@
class AddSorecopCatIdToPProducts < ActiveRecord::Migration[6.0]
def change
add_column :p_products, :sorecop_cat_id, :integer
end
end

View File

@ -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