Merge branch 'sorecop' into pre-prod

This commit is contained in:
Barnabé 2021-10-05 15:44:59 +02:00
commit 19200678bd
38 changed files with 485 additions and 20 deletions

View File

@ -13,7 +13,7 @@ class Admin::PSpecValuesController < ApplicationController
def index
@p_spec_values = PSpecValue.all
@p_spec_values = sort_by_sorting(@p_spec_values, "id DESC")
@p_spec_values = sort_by_sorting(@p_spec_values, "value + 0 ASC")
respond_to do |format|
format.html{

View File

@ -0,0 +1,76 @@
# -*- encoding : utf-8 -*-
class Admin::SorecopCatsController < ApplicationController
layout "admin"
before_action :auth_admin
before_action :admin_space
def admin_space
@admin_space = "default"
end
def index
@sorecop_cats = SorecopCat.all
@sorecop_cats = sort_by_sorting(@sorecop_cats, "id DESC")
respond_to do |format|
format.html{
params[:search][:per_page] = params[:search][:per_page] || 100
per_page = params[:search][:per_page]
page = (params[:page] and params[:page] != "") ? params[:page] : 1
@sorecop_cats = @sorecop_cats.page(page).per(per_page)
}
end
end
def show
@sorecop_cat = SorecopCat.find(params[:id])
end
def new
@sorecop_cat = SorecopCat.new
end
def edit
@sorecop_cat = SorecopCat.find(params[:id])
end
def create
@sorecop_cat = SorecopCat.new(params.require(:sorecop_cat).permit!)
if @sorecop_cat.save
else
render action: "new"
end
end
def update
@sorecop_cat = SorecopCat.find(params[:id])
if @sorecop_cat.update_attributes(params.require(:sorecop_cat).permit!)
else
render action: "edit"
end
end
def destroy
@sorecop_cat = SorecopCat.find(params[:id])
@sorecop_cat.destroy
end
end

View File

@ -0,0 +1,76 @@
# -*- encoding : utf-8 -*-
class Admin::SorecopTaxesController < ApplicationController
layout "admin"
before_action :auth_admin
before_action :admin_space
def admin_space
@admin_space = "default"
end
def index
@sorecop_taxes = SorecopTax.all
@sorecop_taxes = sort_by_sorting(@sorecop_taxes, "id DESC")
respond_to do |format|
format.html{
params[:search][:per_page] = params[:search][:per_page] || 100
per_page = params[:search][:per_page]
page = (params[:page] and params[:page] != "") ? params[:page] : 1
@sorecop_taxes = @sorecop_taxes.page(page).per(per_page)
}
end
end
def show
@sorecop_tax = SorecopTax.find(params[:id])
end
def new
@sorecop_tax = SorecopTax.new
end
def edit
@sorecop_tax = SorecopTax.find(params[:id])
end
def create
@sorecop_tax = SorecopTax.new(params.require(:sorecop_tax).permit!)
if @sorecop_tax.save
else
render action: "new"
end
end
def update
@sorecop_tax = SorecopTax.find(params[:id])
if @sorecop_tax.update_attributes(params.require(:sorecop_tax).permit!)
else
render action: "edit"
end
end
def destroy
@sorecop_tax = SorecopTax.find(params[:id])
@sorecop_tax.destroy
end
end

View File

@ -126,6 +126,8 @@ class ApplicationController < ActionController::Base
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_grades, "Grades" if PGrade::ACTIVATED
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_powers, "Types de chargeurs"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_zones, "Zones produits"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_cats, "Catégories SORECOP"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_taxes, "taxe SORECOP"
end

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

@ -1,6 +1,7 @@
class PProductRef < ApplicationRecord
belongs_to :p_product
belongs_to :sorecop_cat
has_many :sorecop_taxes, through: :sorecop_cat
has_many :p_customer_cats, :through => :p_product
has_many :p_product_features
@ -44,9 +45,9 @@ 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},
:ca_sorecop => {:name => "Sorecop", :as => :currency},
:sorecop_comment => {:name => "Type de Sorecop"},
:deee => {:name => "DEEE", :as => :currency},
:sorecop => {:name => "Sorecop", :as => :currency},
:sorecop_comment => {:name => "Commentaire Sorecop"},
:actions => {:name => "Actions", :reorder => false}
}
@ -87,11 +88,11 @@ class PProductRef < ApplicationRecord
self.p_product.p_product_cat_id
end
QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name)
# QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name)
eval(QI_DYNAMICS_CORE)
# eval(QI_DYNAMICS_CORE)
before_validation :qi_dynamics_cache
# before_validation :qi_dynamics_cache
def get_price(options)
p_customer = PCustomer.find(options[:p_customer_id]) if options[:p_customer_id]
@ -154,18 +155,42 @@ class PProductRef < ApplicationRecord
end
def ca_sorecop
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
"TODO Calcul sorecop"
find_sorecop_tax
end
end
def find_sorecop_tax
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
tax.price * storage_capacity
end
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

10
app/models/sorecop_cat.rb Normal file
View File

@ -0,0 +1,10 @@
class SorecopCat < ApplicationRecord
has_many :p_products
has_many :sorecop_taxes, dependent: :destroy
acts_as_sorting :fields => {
:id => {:name => "ID"},
:name => {:name => "Catégorie", :reorder => true},
:actions => {:name => "Actions", :reorder => true}
}
end

15
app/models/sorecop_tax.rb Normal file
View File

@ -0,0 +1,15 @@
class SorecopTax < ApplicationRecord
belongs_to :sorecop_cat
acts_as_sorting :fields => {
:id => {:name => "ID"},
:title => {:name => "Désignation", :reorder => true},
:critere_min => {:name => "Critère mini (Go)", :reorder => true},
:critere_max => {:name => "Critère maxi (Go)", :reorder => true},
:fixed_price => {:name => "Prix forfaitaire", :reorder => true, :format => :boolean},
:sorecop_cat => {:name => "Catégorie SORECOP",member_label: :name, :reorder => false},
:price => {:name => "Prix", :reorder => false, as: :currency},
:actions => {:name => "Actions", :reorder => true}
}
end

View File

@ -20,14 +20,15 @@
%td
=form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true
%td
=form.input :ean
%tr
%td
=form.input :ct_sorecop, :label => "Sorecop personalisée :"
%td
=form.input :sorecop_comment, :label => "Type de Sorecop :"
=form.input :sorecop_comment, :label => "Commentaire de Sorecop :"
%td
=form.input :ct_deee, :label => "DEEE personalisée :"
%td
=form.input :ean

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

@ -0,0 +1,12 @@
=semantic_form_for [:admin, @sorecop_cat], :remote => true do |f|
.content
=f.inputs do
= f.input :name, :label => f.object.label_for(:name)
.actions=f.submit "sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,16 @@
%tr#sorecop_cat_row{:id => sorecop_cat.id}
-tr = {}
-tr[:actions] = capture do
%td.actions
= link_to i(:"trash-o"), [:admin, sorecop_cat], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
= link_to i(:pencil), edit_admin_sorecop_cat_path(sorecop_cat), :remote => true
= link_to i(:eye), admin_sorecop_cat_path(sorecop_cat), :remote => true
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => sorecop_cat}

View File

@ -0,0 +1,2 @@
$('#sorecop_cats_rows').prepend("<%= escape_javascript(render(@sorecop_cat))%>");
close_pane_hover();

View File

@ -0,0 +1 @@
$('#sorecop_cat_row_<%= @sorecop_cat.id %>').remove();

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,16 @@
.qi_header
.right= link_to ic(:plus)+' Ajouter', new_admin_sorecop_cat_path(), :class => "btn btn-primary btn-ap-add", :remote => true
%h1
=SorecopCat.human rescue ""
.qi_search_row
=form_tag "", :method => "get", :onsubmit => "" do
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @sorecop_cats}
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @sorecop_cats}

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,10 @@
.qi_header
%h1
%span
.qi_row
.qi_pannel.qi_plain.padding
=debug @sorecop_cat

View File

@ -0,0 +1,2 @@
$('#sorecop_cat_row_<%= @sorecop_cat.id %>').replaceWith("<%= escape_javascript(render(@sorecop_cat))%>");
close_pane_hover();

View File

@ -0,0 +1,18 @@
=semantic_form_for [:admin, @sorecop_tax], :remote => true do |f|
.content
=f.inputs do
= f.input :sorecop_cat_id, as: :select, collection: SorecopCat.pluck(:name, :id) ,:label => f.object.label_for(:sorecop_cat)
= f.input :title, :label => f.object.label_for(:title)
= f.input :critere_min, :label => f.object.label_for(:critere_min)
= f.input :critere_max, :label => f.object.label_for(:critere_max)
= f.input :price, :label => f.object.label_for(:price)
= f.input :fixed_price, :label => f.object.label_for(:fixed_price)
.actions=f.submit "sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,35 @@
%tr#sorecop_tax_row{:id => sorecop_tax.id}
-tr = {}
-tr[:critere_min] = capture do
%td
= sorecop_tax.critere_min
Go
-tr[:critere_max] = capture do
%td
= sorecop_tax.critere_max
Go
-tr[:fixed_price] = capture do
%td.text-center
-if sorecop_tax.fixed_price
=ic("check-square-o")
-else
=ic("square-o")
-tr[:actions] = capture do
%td.actions
= link_to i(:"trash-o"), [:admin, sorecop_tax], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
= link_to i(:pencil), edit_admin_sorecop_tax_path(sorecop_tax), :remote => true
= link_to i(:eye), admin_sorecop_tax_path(sorecop_tax), :remote => true
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => sorecop_tax}

View File

@ -0,0 +1,2 @@
$('#sorecop_taxes_rows').prepend("<%= escape_javascript(render(@sorecop_tax))%>");
close_pane_hover();

View File

@ -0,0 +1 @@
$('#sorecop_tax_row_<%= @sorecop_tax.id %>').remove();

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,16 @@
.qi_header
.right= link_to ic(:plus)+' Ajouter', new_admin_sorecop_tax_path(), :class => "btn btn-primary btn-ap-add", :remote => true
%h1
=SorecopTax.human rescue ""
.qi_search_row
=form_tag "", :method => "get", :onsubmit => "" do
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @sorecop_taxes}
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @sorecop_taxes}

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,10 @@
.qi_header
%h1
%span
.qi_row
.qi_pannel.qi_plain.padding
=debug @sorecop_tax

View File

@ -0,0 +1,2 @@
$('#sorecop_tax_row_<%= @sorecop_tax.id %>').replaceWith("<%= escape_javascript(render(@sorecop_tax))%>");
close_pane_hover();

View File

@ -1,5 +1,27 @@
Rails.application.routes.draw do
namespace :admin do
resources :sorecop_taxes do
member do
end
collection do
end
end
end
namespace :admin do
resources :sorecop_cats do
member do
end
collection do
end
end
end
namespace :admin do
resources :price_line_resp_selects do
member do

View File

@ -0,0 +1,9 @@
class CreateSorecopCats < ActiveRecord::Migration[6.0]
def change
create_table :sorecop_cats do |t|
t.string :name
t.timestamps
end
end
end

View File

@ -0,0 +1,14 @@
class CreateSorecopTaxes < ActiveRecord::Migration[6.0]
def change
create_table :sorecop_taxes do |t|
t.decimal :critere_min, precision: 10, scale: 2
t.decimal :critere_max, precision: 10, scale: 2
t.string :title
t.boolean :fixed_price, default: true
t.decimal :price, precision: 10, scale: 2
t.references :sorecop_cat, foreign_key: true
t.timestamps
end
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

@ -0,0 +1,6 @@
class RenameCaToAcForProductRefs < ActiveRecord::Migration[6.0]
def change
rename_column :p_product_refs, :ca_deee, :ac_deee
rename_column :p_product_refs, :ca_sorecop, :ac_sorecop
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_17_124338) do
ActiveRecord::Schema.define(version: 2021_09_24_153716) do
create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name"
@ -1793,10 +1793,10 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do
t.boolean "stocked", default: true
t.text "description"
t.integer "p_product_color_id"
t.decimal "ca_sorecop", precision: 10, scale: 2
t.decimal "ac_sorecop", precision: 10, scale: 2
t.decimal "cc_sorecop", precision: 10, scale: 2
t.decimal "ct_sorecop", precision: 10, scale: 2
t.decimal "ca_deee", precision: 10, scale: 2
t.decimal "ac_deee", precision: 10, scale: 2
t.decimal "cc_deee", precision: 10, scale: 2
t.decimal "ct_deee", precision: 10, scale: 2
t.string "ean"
@ -1890,6 +1890,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) 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
@ -2754,6 +2755,24 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do
t.decimal "ac_remise", precision: 14, scale: 2
end
create_table "sorecop_cats", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "sorecop_taxes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.decimal "critere_min", precision: 10, scale: 2
t.decimal "critere_max", precision: 10, scale: 2
t.string "title"
t.boolean "fixed_price", default: true
t.decimal "price", precision: 10, scale: 2
t.bigint "sorecop_cat_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["sorecop_cat_id"], name: "index_sorecop_taxes_on_sorecop_cat_id"
end
create_table "specific_preferences", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "key"
t.string "value"
@ -3176,6 +3195,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do
add_foreign_key "partition_lines", "partitions"
add_foreign_key "partitions", "admins"
add_foreign_key "s_modules", "s_modules_states"
add_foreign_key "sorecop_taxes", "sorecop_cats"
add_foreign_key "stat_lines", "p_commercials"
add_foreign_key "stat_lines", "p_customers"
add_foreign_key "stat_lines", "p_product_refs"

7
test/fixtures/sorecop_cats.yml vendored Normal file
View File

@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString

15
test/fixtures/sorecop_taxes.yml vendored Normal file
View File

@ -0,0 +1,15 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
critere_min: 9.99
critere_max: 9.99
title: MyString
fixed_price: false
sorecop_cat_id: one
two:
critere_min: 9.99
critere_max: 9.99
title: MyString
fixed_price: false
sorecop_cat_id: two

View File

@ -0,0 +1,7 @@
require 'test_helper'
class SorecopCatTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class SorecopTaxTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end