diff --git a/app/controllers/admin/p_product_ref_specs_controller.rb b/app/controllers/admin/p_product_ref_specs_controller.rb index 7522ebb..9935030 100644 --- a/app/controllers/admin/p_product_ref_specs_controller.rb +++ b/app/controllers/admin/p_product_ref_specs_controller.rb @@ -33,7 +33,9 @@ class Admin::PProductRefSpecsController < ApplicationController def new @p_product_ref_spec = PProductRefSpec.new - + @p_product_ref_spec.build_p_spec_type + @p_product_ref_spec.build_p_spec_value + end def edit diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6c5880a..0812d32 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -99,6 +99,7 @@ class ApplicationController < ActionController::Base if current_admin.has_permission?("boutique") set_sub_menu :stocks, :p_product_colors, "Couleurs" set_sub_menu :stocks, :p_article_serial_nums, "Numero série" + set_sub_menu :stocks, :p_product_ref_specs, "Specs" set_sub_menu :stocks, :p_product_powers, "Types de chargeurs" set_sub_menu :stocks, :p_product_zones, "Zones produits" diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 12da04b..07926e6 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -9,10 +9,14 @@ class PProductRef < ApplicationRecord has_many :p_product_ref_price_histories belongs_to :p_product_color + has_many :p_articles has_many :p_article_serial_nums, through: :p_articles accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true + has_many :p_product_ref_specs + accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true + #validates :ct_price_ht, :presence => true @@ -67,7 +71,9 @@ class PProductRef < ApplicationRecord def ca_name - self.p_product.name if self.p_product + if self.p_product + self.p_product.name + " - " + self.ct_sub_name + end end def ca_code diff --git a/app/models/p_product_ref_spec.rb b/app/models/p_product_ref_spec.rb index 3b80fce..a036951 100644 --- a/app/models/p_product_ref_spec.rb +++ b/app/models/p_product_ref_spec.rb @@ -2,4 +2,17 @@ class PProductRefSpec < ApplicationRecord belongs_to :p_product_ref belongs_to :p_spec_type belongs_to :p_spec_value + + accepts_nested_attributes_for :p_spec_type, :p_spec_value + + acts_as_sorting :fields => { + :id => {:name => "ID"}, + :p_product_ref => {:name => "Référence produit", :reorder => true}, + :p_product_ref_id => {:name => "ID Ref produit", :reorder => true}, + :p_spec_type => {:name => "Type", :reorder => true}, + :p_spec_value => {:name => "Valeur", :reorder => true}, + + :actions => {:name => "Actions", :reorder => true} + + } end diff --git a/app/models/p_spec_type.rb b/app/models/p_spec_type.rb index 30aea9e..a656aa6 100644 --- a/app/models/p_spec_type.rb +++ b/app/models/p_spec_type.rb @@ -1,2 +1,5 @@ class PSpecType < ApplicationRecord + has_many :p_product_ref_specs + + TYPES = ["Ram", "Stockage"] end diff --git a/app/models/p_spec_value.rb b/app/models/p_spec_value.rb index 17c7684..a44875c 100644 --- a/app/models/p_spec_value.rb +++ b/app/models/p_spec_value.rb @@ -1,2 +1,5 @@ class PSpecValue < ApplicationRecord + has_many :p_product_ref_specs + + UNITS = ["Go", "Mo"] end diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index 8fd4851..aed2719 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -2,13 +2,16 @@ .content =f.inputs do - = f.input :p_product_ref, :label => f.object.label_for(:p_product_ref) - = f.input :p_spec_type, :label => f.object.label_for(:p_spec_type) - = f.input :p_spec_value, :label => f.object.label_for(:p_spec_value) + = f.input :p_product_ref, as: :select, collection: PProductRef.pluck(:cc_name, :id) ,:label => f.object.label_for(:p_product_ref) + = f.semantic_fields_for :p_spec_type do | form | + =render :partial => "admin/p_spec_types/form", :locals => {:f => form} + = f.semantic_fields_for :p_spec_value do | form | + =render :partial => "admin/p_spec_values/form", :locals => {:f => form} + / = f.input :p_spec_value, :label => f.object.label_for(:p_spec_value) .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml b/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml index e91add0..b696059 100644 --- a/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml +++ b/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml @@ -1,6 +1,21 @@ %tr#p_product_ref_spec_row{:id => p_product_ref_spec.id} -tr = {} - + -tr[:p_product_ref] = capture do + %td + = p_product_ref_spec.p_product_ref.cc_name + + -tr[:p_product_ref_id] = capture do + %td + = p_product_ref_spec.p_product_ref.id + + -tr[:p_spec_type] = capture do + %td + = p_product_ref_spec.p_spec_type.name + -tr[:p_spec_value] = capture do + %td + = p_product_ref_spec.p_spec_value.value + = p_product_ref_spec.p_spec_value.unit + -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, p_product_ref_spec], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true @@ -13,4 +28,4 @@ - \ No newline at end of file + diff --git a/app/views/admin/p_spec_types/_form.html.haml b/app/views/admin/p_spec_types/_form.html.haml index 0a8acc2..ab615d2 100644 --- a/app/views/admin/p_spec_types/_form.html.haml +++ b/app/views/admin/p_spec_types/_form.html.haml @@ -1,12 +1,2 @@ -=semantic_form_for [:admin, @p_spec_type], :remote => true do |f| - - .content - =f.inputs do - = f.input :type, :label => f.object.label_for(:type) - - - - - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file +=f.inputs do + = f.input :name, :label => "Type", as: :select, collection: PSpecType::TYPES diff --git a/app/views/admin/p_spec_values/_form.html.haml b/app/views/admin/p_spec_values/_form.html.haml index 6d0339f..d44dd69 100644 --- a/app/views/admin/p_spec_values/_form.html.haml +++ b/app/views/admin/p_spec_values/_form.html.haml @@ -1,13 +1,3 @@ -=semantic_form_for [:admin, @p_spec_value], :remote => true do |f| - - .content - =f.inputs do - = f.input :value, :label => f.object.label_for(:value) - = f.input :unit, :label => f.object.label_for(:unit) - - - - - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file +=f.inputs do + = f.input :value, :label => "Valeur" + = f.input :unit, :label => "Unité", as: :select, collection: PSpecValue::UNITS