From a9a5e222513c46236d77b2aed0bb3301c6cee330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 18:19:47 +0200 Subject: [PATCH 01/13] g qis sorecop_cats --- .../admin/sorecop_cats_controller.rb | 76 +++++++++++++++++++ app/models/sorecop_cat.rb | 2 + app/views/admin/sorecop_cats/_form.html.haml | 12 +++ .../admin/sorecop_cats/_sorecop_cat.html.haml | 16 ++++ app/views/admin/sorecop_cats/create.js.erb | 2 + app/views/admin/sorecop_cats/destroy.js.erb | 1 + app/views/admin/sorecop_cats/edit.js.erb | 1 + app/views/admin/sorecop_cats/index.html.haml | 16 ++++ app/views/admin/sorecop_cats/new.js.erb | 1 + app/views/admin/sorecop_cats/show.html.haml | 10 +++ app/views/admin/sorecop_cats/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210923161914_create_sorecop_cats.rb | 9 +++ test/fixtures/sorecop_cats.yml | 7 ++ test/models/sorecop_cat_test.rb | 7 ++ 15 files changed, 173 insertions(+) create mode 100644 app/controllers/admin/sorecop_cats_controller.rb create mode 100644 app/models/sorecop_cat.rb create mode 100644 app/views/admin/sorecop_cats/_form.html.haml create mode 100644 app/views/admin/sorecop_cats/_sorecop_cat.html.haml create mode 100644 app/views/admin/sorecop_cats/create.js.erb create mode 100644 app/views/admin/sorecop_cats/destroy.js.erb create mode 100644 app/views/admin/sorecop_cats/edit.js.erb create mode 100644 app/views/admin/sorecop_cats/index.html.haml create mode 100644 app/views/admin/sorecop_cats/new.js.erb create mode 100644 app/views/admin/sorecop_cats/show.html.haml create mode 100644 app/views/admin/sorecop_cats/update.js.erb create mode 100644 db/migrate/20210923161914_create_sorecop_cats.rb create mode 100644 test/fixtures/sorecop_cats.yml create mode 100644 test/models/sorecop_cat_test.rb diff --git a/app/controllers/admin/sorecop_cats_controller.rb b/app/controllers/admin/sorecop_cats_controller.rb new file mode 100644 index 0000000..9a0803e --- /dev/null +++ b/app/controllers/admin/sorecop_cats_controller.rb @@ -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 diff --git a/app/models/sorecop_cat.rb b/app/models/sorecop_cat.rb new file mode 100644 index 0000000..be69dba --- /dev/null +++ b/app/models/sorecop_cat.rb @@ -0,0 +1,2 @@ +class SorecopCat < ApplicationRecord +end diff --git a/app/views/admin/sorecop_cats/_form.html.haml b/app/views/admin/sorecop_cats/_form.html.haml new file mode 100644 index 0000000..92adc9a --- /dev/null +++ b/app/views/admin/sorecop_cats/_form.html.haml @@ -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" + \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/_sorecop_cat.html.haml b/app/views/admin/sorecop_cats/_sorecop_cat.html.haml new file mode 100644 index 0000000..f7c3aa2 --- /dev/null +++ b/app/views/admin/sorecop_cats/_sorecop_cat.html.haml @@ -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} + + + + \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/create.js.erb b/app/views/admin/sorecop_cats/create.js.erb new file mode 100644 index 0000000..5b32752 --- /dev/null +++ b/app/views/admin/sorecop_cats/create.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_cats_rows').prepend("<%= escape_javascript(render(@sorecop_cat))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/destroy.js.erb b/app/views/admin/sorecop_cats/destroy.js.erb new file mode 100644 index 0000000..53582e6 --- /dev/null +++ b/app/views/admin/sorecop_cats/destroy.js.erb @@ -0,0 +1 @@ +$('#sorecop_cat_row_<%= @sorecop_cat.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/edit.js.erb b/app/views/admin/sorecop_cats/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_cats/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/index.html.haml b/app/views/admin/sorecop_cats/index.html.haml new file mode 100644 index 0000000..635f57b --- /dev/null +++ b/app/views/admin/sorecop_cats/index.html.haml @@ -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} + + + diff --git a/app/views/admin/sorecop_cats/new.js.erb b/app/views/admin/sorecop_cats/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_cats/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/show.html.haml b/app/views/admin/sorecop_cats/show.html.haml new file mode 100644 index 0000000..764b0b5 --- /dev/null +++ b/app/views/admin/sorecop_cats/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @sorecop_cat \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/update.js.erb b/app/views/admin/sorecop_cats/update.js.erb new file mode 100644 index 0000000..3fe7cb0 --- /dev/null +++ b/app/views/admin/sorecop_cats/update.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_cat_row_<%= @sorecop_cat.id %>').replaceWith("<%= escape_javascript(render(@sorecop_cat))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a5835ca..bb3e0c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + 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 diff --git a/db/migrate/20210923161914_create_sorecop_cats.rb b/db/migrate/20210923161914_create_sorecop_cats.rb new file mode 100644 index 0000000..4679ff6 --- /dev/null +++ b/db/migrate/20210923161914_create_sorecop_cats.rb @@ -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 diff --git a/test/fixtures/sorecop_cats.yml b/test/fixtures/sorecop_cats.yml new file mode 100644 index 0000000..7d41224 --- /dev/null +++ b/test/fixtures/sorecop_cats.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/sorecop_cat_test.rb b/test/models/sorecop_cat_test.rb new file mode 100644 index 0000000..2daceaa --- /dev/null +++ b/test/models/sorecop_cat_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SorecopCatTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 91dc7a86317643fd6314cab9290506855052149d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 18:52:52 +0200 Subject: [PATCH 02/13] g qis sorecop_taxes --- .../admin/sorecop_taxes_controller.rb | 76 +++++++++++++++++++ app/models/sorecop_tax.rb | 3 + app/views/admin/sorecop_taxes/_form.html.haml | 16 ++++ .../sorecop_taxes/_sorecop_tax.html.haml | 16 ++++ app/views/admin/sorecop_taxes/create.js.erb | 2 + app/views/admin/sorecop_taxes/destroy.js.erb | 1 + app/views/admin/sorecop_taxes/edit.js.erb | 1 + app/views/admin/sorecop_taxes/index.html.haml | 16 ++++ app/views/admin/sorecop_taxes/new.js.erb | 1 + app/views/admin/sorecop_taxes/show.html.haml | 10 +++ app/views/admin/sorecop_taxes/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210923165046_create_sorecop_taxes.rb | 13 ++++ test/fixtures/sorecop_taxes.yml | 15 ++++ test/models/sorecop_tax_test.rb | 7 ++ 15 files changed, 190 insertions(+) create mode 100644 app/controllers/admin/sorecop_taxes_controller.rb create mode 100644 app/models/sorecop_tax.rb create mode 100644 app/views/admin/sorecop_taxes/_form.html.haml create mode 100644 app/views/admin/sorecop_taxes/_sorecop_tax.html.haml create mode 100644 app/views/admin/sorecop_taxes/create.js.erb create mode 100644 app/views/admin/sorecop_taxes/destroy.js.erb create mode 100644 app/views/admin/sorecop_taxes/edit.js.erb create mode 100644 app/views/admin/sorecop_taxes/index.html.haml create mode 100644 app/views/admin/sorecop_taxes/new.js.erb create mode 100644 app/views/admin/sorecop_taxes/show.html.haml create mode 100644 app/views/admin/sorecop_taxes/update.js.erb create mode 100644 db/migrate/20210923165046_create_sorecop_taxes.rb create mode 100644 test/fixtures/sorecop_taxes.yml create mode 100644 test/models/sorecop_tax_test.rb diff --git a/app/controllers/admin/sorecop_taxes_controller.rb b/app/controllers/admin/sorecop_taxes_controller.rb new file mode 100644 index 0000000..a67105b --- /dev/null +++ b/app/controllers/admin/sorecop_taxes_controller.rb @@ -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 diff --git a/app/models/sorecop_tax.rb b/app/models/sorecop_tax.rb new file mode 100644 index 0000000..9fb2cd7 --- /dev/null +++ b/app/models/sorecop_tax.rb @@ -0,0 +1,3 @@ +class SorecopTax < ApplicationRecord + belongs_to :sorecop_cat_id +end diff --git a/app/views/admin/sorecop_taxes/_form.html.haml b/app/views/admin/sorecop_taxes/_form.html.haml new file mode 100644 index 0000000..389bbe6 --- /dev/null +++ b/app/views/admin/sorecop_taxes/_form.html.haml @@ -0,0 +1,16 @@ +=semantic_form_for [:admin, @sorecop_tax], :remote => true do |f| + + .content + =f.inputs do + = f.input :critere_min, :label => f.object.label_for(:critere_min) + = f.input :critere_max, :label => f.object.label_for(:critere_max) + = f.input :title, :label => f.object.label_for(:title) + = f.input :fixed_price, :label => f.object.label_for(:fixed_price) + = f.input :sorecop_cat_id, :label => f.object.label_for(:sorecop_cat_id) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml new file mode 100644 index 0000000..4a318ec --- /dev/null +++ b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml @@ -0,0 +1,16 @@ +%tr#sorecop_tax_row{:id => sorecop_tax.id} + -tr = {} + + -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} + + + + \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/create.js.erb b/app/views/admin/sorecop_taxes/create.js.erb new file mode 100644 index 0000000..a917ef3 --- /dev/null +++ b/app/views/admin/sorecop_taxes/create.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_taxes_rows').prepend("<%= escape_javascript(render(@sorecop_tax))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/destroy.js.erb b/app/views/admin/sorecop_taxes/destroy.js.erb new file mode 100644 index 0000000..527b1f6 --- /dev/null +++ b/app/views/admin/sorecop_taxes/destroy.js.erb @@ -0,0 +1 @@ +$('#sorecop_tax_row_<%= @sorecop_tax.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/edit.js.erb b/app/views/admin/sorecop_taxes/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_taxes/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/index.html.haml b/app/views/admin/sorecop_taxes/index.html.haml new file mode 100644 index 0000000..90d80c4 --- /dev/null +++ b/app/views/admin/sorecop_taxes/index.html.haml @@ -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} + + + diff --git a/app/views/admin/sorecop_taxes/new.js.erb b/app/views/admin/sorecop_taxes/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_taxes/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/show.html.haml b/app/views/admin/sorecop_taxes/show.html.haml new file mode 100644 index 0000000..cb114cd --- /dev/null +++ b/app/views/admin/sorecop_taxes/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @sorecop_tax \ No newline at end of file diff --git a/app/views/admin/sorecop_taxes/update.js.erb b/app/views/admin/sorecop_taxes/update.js.erb new file mode 100644 index 0000000..0d6db14 --- /dev/null +++ b/app/views/admin/sorecop_taxes/update.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_tax_row_<%= @sorecop_tax.id %>').replaceWith("<%= escape_javascript(render(@sorecop_tax))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index bb3e0c3..3543334 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ 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 diff --git a/db/migrate/20210923165046_create_sorecop_taxes.rb b/db/migrate/20210923165046_create_sorecop_taxes.rb new file mode 100644 index 0000000..c272193 --- /dev/null +++ b/db/migrate/20210923165046_create_sorecop_taxes.rb @@ -0,0 +1,13 @@ +class CreateSorecopTaxes < ActiveRecord::Migration[6.0] + def change + create_table :sorecop_taxes do |t| + t.decimal :critere_min + t.decimal :critere_max + t.string :title + t.boolean :fixed_price + t.references :sorecop_cat_id, foreign_key: true + + t.timestamps + end + end +end diff --git a/test/fixtures/sorecop_taxes.yml b/test/fixtures/sorecop_taxes.yml new file mode 100644 index 0000000..f3c9843 --- /dev/null +++ b/test/fixtures/sorecop_taxes.yml @@ -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 diff --git a/test/models/sorecop_tax_test.rb b/test/models/sorecop_tax_test.rb new file mode 100644 index 0000000..afb017b --- /dev/null +++ b/test/models/sorecop_tax_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SorecopTaxTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 07014ae159ac78012296e3bedcbd2a081c2aace2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 18:58:09 +0200 Subject: [PATCH 03/13] typo fix --- .../20210923165046_create_sorecop_taxes.rb | 8 ++++---- db/schema.rb | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/db/migrate/20210923165046_create_sorecop_taxes.rb b/db/migrate/20210923165046_create_sorecop_taxes.rb index c272193..bbeeaff 100644 --- a/db/migrate/20210923165046_create_sorecop_taxes.rb +++ b/db/migrate/20210923165046_create_sorecop_taxes.rb @@ -1,11 +1,11 @@ class CreateSorecopTaxes < ActiveRecord::Migration[6.0] def change create_table :sorecop_taxes do |t| - t.decimal :critere_min - t.decimal :critere_max + t.decimal :critere_min, :precision => 10, :scale => 2 + t.decimal :critere_max, :precision => 10, :scale => 2 t.string :title - t.boolean :fixed_price - t.references :sorecop_cat_id, foreign_key: true + t.boolean :fixed_price, default: true + t.references :sorecop_cats, foreign_key: true t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 5baae52..abb4522 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_17_124338) do +ActiveRecord::Schema.define(version: 2021_09_23_165046) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -2754,6 +2754,23 @@ 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.bigint "sorecop_cats_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["sorecop_cats_id"], name: "index_sorecop_taxes_on_sorecop_cats_id" + end + create_table "specific_preferences", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "key" t.string "value" @@ -3176,6 +3193,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", column: "sorecop_cats_id" add_foreign_key "stat_lines", "p_commercials" add_foreign_key "stat_lines", "p_customers" add_foreign_key "stat_lines", "p_product_refs" From 7a5e27685caa173b57769396a59e517b2b51dcc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 19:55:56 +0200 Subject: [PATCH 04/13] update migration --- db/migrate/20210923165046_create_sorecop_taxes.rb | 7 ++++--- ...10923170130_add_sorecop_cat_id_to_p_product_refs.rb | 5 +++++ db/schema.rb | 10 ++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb diff --git a/db/migrate/20210923165046_create_sorecop_taxes.rb b/db/migrate/20210923165046_create_sorecop_taxes.rb index bbeeaff..1bf6e8b 100644 --- a/db/migrate/20210923165046_create_sorecop_taxes.rb +++ b/db/migrate/20210923165046_create_sorecop_taxes.rb @@ -1,11 +1,12 @@ 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.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.references :sorecop_cats, foreign_key: true + t.decimal :price, precision: 10, scale: 2 + t.references :sorecop_cat, foreign_key: true t.timestamps end 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 new file mode 100644 index 0000000..b4d65a9 --- /dev/null +++ b/db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb @@ -0,0 +1,5 @@ +class AddSorecopCatIdToPProductRefs < ActiveRecord::Migration[6.0] + def change + add_column :p_product_refs, :sorecop_cat_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index abb4522..5e36bad 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_165046) do +ActiveRecord::Schema.define(version: 2021_09_23_170130) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1801,6 +1801,7 @@ ActiveRecord::Schema.define(version: 2021_09_23_165046) 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| @@ -2765,10 +2766,11 @@ ActiveRecord::Schema.define(version: 2021_09_23_165046) do t.decimal "critere_max", precision: 10, scale: 2 t.string "title" t.boolean "fixed_price", default: true - t.bigint "sorecop_cats_id" + 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_cats_id"], name: "index_sorecop_taxes_on_sorecop_cats_id" + 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| @@ -3193,7 +3195,7 @@ ActiveRecord::Schema.define(version: 2021_09_23_165046) 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", column: "sorecop_cats_id" + 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" From 0246cf966e66fc154c0f5098d01ecc5c476a97f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 19:56:51 +0200 Subject: [PATCH 05/13] menu & forms --- app/controllers/application_controller.rb | 4 +++- app/models/p_product_ref.rb | 3 ++- app/models/sorecop_cat.rb | 8 ++++++++ app/models/sorecop_tax.rb | 14 +++++++++++++- app/views/admin/sorecop_taxes/_form.html.haml | 16 +++++++++------- .../admin/sorecop_taxes/_sorecop_tax.html.haml | 7 ++++++- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ce02913..6441a74 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -126,7 +126,9 @@ 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 diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 9a7fccf..49d5d80 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -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 diff --git a/app/models/sorecop_cat.rb b/app/models/sorecop_cat.rb index be69dba..a0af0d4 100644 --- a/app/models/sorecop_cat.rb +++ b/app/models/sorecop_cat.rb @@ -1,2 +1,10 @@ class SorecopCat < ApplicationRecord + has_many :p_product_refs + 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 diff --git a/app/models/sorecop_tax.rb b/app/models/sorecop_tax.rb index 9fb2cd7..518bb01 100644 --- a/app/models/sorecop_tax.rb +++ b/app/models/sorecop_tax.rb @@ -1,3 +1,15 @@ class SorecopTax < ApplicationRecord - belongs_to :sorecop_cat_id + 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", :reorder => false}, + :price => {:name => "Prix", :reorder => false}, + :actions => {:name => "Actions", :reorder => true} + } end diff --git a/app/views/admin/sorecop_taxes/_form.html.haml b/app/views/admin/sorecop_taxes/_form.html.haml index 389bbe6..38654b8 100644 --- a/app/views/admin/sorecop_taxes/_form.html.haml +++ b/app/views/admin/sorecop_taxes/_form.html.haml @@ -2,15 +2,17 @@ .content =f.inputs do - = f.input :critere_min, :label => f.object.label_for(:critere_min) - = f.input :critere_max, :label => f.object.label_for(:critere_max) - = f.input :title, :label => f.object.label_for(:title) - = f.input :fixed_price, :label => f.object.label_for(:fixed_price) - = f.input :sorecop_cat_id, :label => f.object.label_for(:sorecop_cat_id) - + = 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" - \ No newline at end of file + diff --git a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml index 4a318ec..c35450f 100644 --- a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml +++ b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml @@ -1,5 +1,10 @@ %tr#sorecop_tax_row{:id => sorecop_tax.id} -tr = {} + + -tr[:sorecop_cat] = capture do + %td + = sorecop_tax.sorecop_cat.name + -tr[:actions] = capture do %td.actions @@ -13,4 +18,4 @@ - \ No newline at end of file + From 2e83114c3f1f3ff463f8715fe531e829c76bedd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 12:30:19 +0200 Subject: [PATCH 06/13] Update sorecop text table --- app/models/sorecop_tax.rb | 4 ++-- .../sorecop_taxes/_sorecop_tax.html.haml | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/models/sorecop_tax.rb b/app/models/sorecop_tax.rb index 518bb01..061dd00 100644 --- a/app/models/sorecop_tax.rb +++ b/app/models/sorecop_tax.rb @@ -8,8 +8,8 @@ class SorecopTax < ApplicationRecord :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", :reorder => false}, - :price => {:name => "Prix", :reorder => false}, + :sorecop_cat => {:name => "Catégorie SORECOP",member_label: :name, :reorder => false}, + :price => {:name => "Prix", :reorder => false, as: :currency}, :actions => {:name => "Actions", :reorder => true} } end diff --git a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml index c35450f..684f550 100644 --- a/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml +++ b/app/views/admin/sorecop_taxes/_sorecop_tax.html.haml @@ -1,11 +1,25 @@ %tr#sorecop_tax_row{:id => sorecop_tax.id} -tr = {} - -tr[:sorecop_cat] = capture do + -tr[:critere_min] = capture do %td - = sorecop_tax.sorecop_cat.name + = 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 From 91754a6192447358fee3c11a584d5315a3e4ea51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:11:43 +0200 Subject: [PATCH 07/13] Spec value default order --- app/controllers/admin/p_spec_values_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/p_spec_values_controller.rb b/app/controllers/admin/p_spec_values_controller.rb index 2dfd736..4ddb464 100644 --- a/app/controllers/admin/p_spec_values_controller.rb +++ b/app/controllers/admin/p_spec_values_controller.rb @@ -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{ From e8ebce23edc9588ccbd555cd09266bc3d5127165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:12:17 +0200 Subject: [PATCH 08/13] ca_sorecop for p_product_ref --- app/models/p_product_ref.rb | 22 +++++++++++++++---- .../admin/p_product_refs/_form.html.haml | 4 +++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 49d5d80..f8cf488 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -10,6 +10,7 @@ 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 +47,7 @@ class PProductRef < ApplicationRecord :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 => {:name => "Sorecop", :as => :currency}, :sorecop_comment => {:name => "Type de Sorecop"}, :actions => {:name => "Actions", :reorder => false} } @@ -155,13 +156,26 @@ class PProductRef < ApplicationRecord end def ca_sorecop - if self.cc_sorecop - return self.cc_sorecop + 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 + else + "Pas de spec de Stockage" + end + end else - "TODO Calcul sorecop" + "Pas de catégorie Sorecop" 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 + self.sorecop_cat.sorecop_taxes.where('critere_min < ? AND critere_max >= ?', storage_capacity, storage_capacity).first + end + def ca_deee if self.cc_deee return self.cc_deee diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index 4b0b755..f55ec17 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -20,10 +20,12 @@ %td =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true + %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 - =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 From 72cee7f797bc7925d02ea7cf30f00da8d39389a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:59:38 +0200 Subject: [PATCH 09/13] update sorecop calcul --- app/models/p_product_ref.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 From 82fdb06254c4134f18a699dbb18eac05d748b384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 15:59:56 +0200 Subject: [PATCH 10/13] fomr in 2 lines --- app/views/admin/p_product_refs/_form.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index f55ec17..7ce89d3 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -20,6 +20,9 @@ %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 :sorecop_cat_id, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true %td @@ -28,8 +31,6 @@ =form.input :sorecop_comment, :label => "Commentaire de Sorecop :" %td =form.input :ct_deee, :label => "DEEE personalisée :" - %td - =form.input :ean From 60ee0d819761bd33be3c7d48a082f257aa141d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 17:19:44 +0200 Subject: [PATCH 11/13] move sorecop_cat to p_product --- app/models/p_product.rb | 2 +- app/models/p_product_ref.rb | 40 ++++++++++--------- app/models/sorecop_cat.rb | 2 +- .../admin/p_product_refs/_form.html.haml | 2 - app/views/admin/p_products/_form.html.haml | 5 ++- ...30_add_sorecop_cat_id_to_p_product_refs.rb | 5 --- ...145644_add_sorecop_cat_id_to_p_products.rb | 5 +++ db/schema.rb | 4 +- 8 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 db/migrate/20210923170130_add_sorecop_cat_id_to_p_product_refs.rb create mode 100644 db/migrate/20210924145644_add_sorecop_cat_id_to_p_products.rb 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 From 4ad0ac7db520f5d6fd0be8be56e202184a0cd55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 17:52:23 +0200 Subject: [PATCH 12/13] remove qi_cache --- app/models/p_product_ref.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 5e2992c..9141d45 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -88,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] From d43fd65822b2ce86271d8b0b7d45bbf5fa140f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 17:52:37 +0200 Subject: [PATCH 13/13] rename ac_ column --- .../20210924153716_rename_ca_to_ac_for_product_refs.rb | 6 ++++++ db/schema.rb | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb diff --git a/db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb b/db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb new file mode 100644 index 0000000..304762e --- /dev/null +++ b/db/migrate/20210924153716_rename_ca_to_ac_for_product_refs.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 0c04f68..016eb45 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_24_145644) 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_24_145644) 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"