diff --git a/app/controllers/admin/p_article_serial_nums_controller.rb b/app/controllers/admin/p_article_serial_nums_controller.rb index 000d7cb..069ade6 100644 --- a/app/controllers/admin/p_article_serial_nums_controller.rb +++ b/app/controllers/admin/p_article_serial_nums_controller.rb @@ -33,7 +33,7 @@ class Admin::PArticleSerialNumsController < ApplicationController def new @p_article_serial_num = PArticleSerialNum.new - + @p_article_serial_num.build_p_serial_num_value end def edit diff --git a/app/controllers/admin/p_articles_controller.rb b/app/controllers/admin/p_articles_controller.rb index 62a2b86..03af6b9 100644 --- a/app/controllers/admin/p_articles_controller.rb +++ b/app/controllers/admin/p_articles_controller.rb @@ -33,7 +33,7 @@ class Admin::PArticlesController < ApplicationController def new @p_article = PArticle.new - + @p_article.build_p_product_ref end def edit diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f693d7e..6c5880a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -65,6 +65,7 @@ class ApplicationController < ActionController::Base if current_admin.has_permission?("products") set_sub_menu :stocks, :p_products, "Produits", admin_p_products_path set_sub_menu :stocks, :p_product_refs, "Références", admin_p_product_refs_path + set_sub_menu :stocks, :p_articles, "Articles", admin_p_articles_path set_sub_menu :stocks, :promos_p_products, "Offres spots", promos_admin_p_products_path end @@ -97,6 +98,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_powers, "Types de chargeurs" set_sub_menu :stocks, :p_product_zones, "Zones produits" diff --git a/app/models/p_article.rb b/app/models/p_article.rb index 325db1a..d2825e3 100644 --- a/app/models/p_article.rb +++ b/app/models/p_article.rb @@ -1,3 +1,18 @@ class PArticle < ApplicationRecord belongs_to :p_product_ref + has_one :p_product, through: :p_product_ref + belongs_to :p_product_color + has_many :p_article_serial_nums, dependent: :destroy + # accepts_nested_attributes_for :p_article_serial_nums + validates_presence_of :p_product_ref + + + acts_as_sorting :fields => { + :id => {:name => "id", :reorder => true}, + :p_product_ref_code => {:name => "Code ref", :reorder => true}, + :p_product_ref => {:name => "Désignation", :reorder => true}, + :color => {:name => "Couleur"}, + :p_article_serial_nums => {:name => "N° identifiants"}, + :actions => {:name => "Actions", :reorder => false}, + } end diff --git a/app/models/p_article_serial_num.rb b/app/models/p_article_serial_num.rb index c4c2da1..aae27cd 100644 --- a/app/models/p_article_serial_num.rb +++ b/app/models/p_article_serial_num.rb @@ -1,5 +1,17 @@ class PArticleSerialNum < ApplicationRecord belongs_to :p_article belongs_to :p_serial_num_type - belongs_to :p_serial_num_value + belongs_to :p_serial_num_value, inverse_of: :p_article_serial_nums + accepts_nested_attributes_for :p_serial_num_value + + acts_as_sorting :fields => { + :id => {:name => "ID"}, + :p_article => {:name => "Article", :reorder => true}, + :p_article_id => {:name => "Article ID", :reorder => true}, + :p_serial_num_type => {:name => "Type", :reorder => true}, + :p_serial_num_value => {:name => "N°", :reorder => true}, + + :actions => {:name => "Actions", :reorder => true} + + } end diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 1d77cd4..12a0795 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -5,8 +5,6 @@ class PProduct < ApplicationRecord has_many :p_product_refs, :dependent => :destroy accepts_nested_attributes_for :p_product_refs, allow_destroy: true - - has_many :p_product_ingredients, :dependent => :destroy accepts_nested_attributes_for :p_product_ingredients, allow_destroy: true @@ -17,6 +15,7 @@ class PProduct < ApplicationRecord has_many :p_product_nutris, :dependent => :destroy accepts_nested_attributes_for :p_product_nutris, allow_destroy: true + has_many :p_articles, through: :p_product_refs has_many :p_product_images diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index ae959f6..12da04b 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -9,6 +9,9 @@ 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 #validates :ct_price_ht, :presence => true diff --git a/app/models/p_serial_num_type.rb b/app/models/p_serial_num_type.rb index 62c20f6..83f5ce7 100644 --- a/app/models/p_serial_num_type.rb +++ b/app/models/p_serial_num_type.rb @@ -1,2 +1,3 @@ class PSerialNumType < ApplicationRecord + has_many :p_article_serial_nums end diff --git a/app/models/p_serial_num_value.rb b/app/models/p_serial_num_value.rb index 735a10d..12a74bd 100644 --- a/app/models/p_serial_num_value.rb +++ b/app/models/p_serial_num_value.rb @@ -1,2 +1,3 @@ class PSerialNumValue < ApplicationRecord + has_many :p_article_serial_nums, inverse_of: :p_serial_num_value end diff --git a/app/views/admin/p_article_serial_nums/_form.html.haml b/app/views/admin/p_article_serial_nums/_form.html.haml index 88c40df..caad0f5 100644 --- a/app/views/admin/p_article_serial_nums/_form.html.haml +++ b/app/views/admin/p_article_serial_nums/_form.html.haml @@ -2,13 +2,15 @@ .content =f.inputs do - = f.input :p_article, :label => f.object.label_for(:p_article) - = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) - = f.input :p_serial_num_value, :label => f.object.label_for(:p_serial_num_value) + = f.input :p_article, as: :select, collection: PArticle.pluck(:id) ,:label => f.object.label_for(:p_article) + = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) + = f.semantic_fields_for :p_serial_num_value do | form | + + =render :partial => "admin/p_serial_num_values/form", :locals => {:f => form} .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml index b6e652b..59de1cd 100644 --- a/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml +++ b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml @@ -1,6 +1,28 @@ %tr#p_article_serial_num_row{:id => p_article_serial_num.id} -tr = {} - + + -tr[:p_article_id] = capture do + %td + = p_article_serial_num.p_article.id + + -tr[:p_article] = capture do + %td + = p_article_serial_num.p_article.p_product.name + \- + = p_article_serial_num.p_article.p_product_ref.ct_sub_name + \- + = p_article_serial_num.p_article.p_product_ref.p_product_color.name + + + -tr[:p_serial_num_type] = capture do + %td + = p_article_serial_num.p_serial_num_type.name + + -tr[:p_serial_num_value] = capture do + %td + = p_article_serial_num.p_serial_num_value.value + + -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, p_article_serial_num], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true @@ -13,4 +35,4 @@ - \ No newline at end of file + diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml index 6561210..8ab680b 100644 --- a/app/views/admin/p_articles/_form.html.haml +++ b/app/views/admin/p_articles/_form.html.haml @@ -2,11 +2,11 @@ .content =f.inputs do - = f.input :p_product_ref, :label => f.object.label_for(:p_product_ref) + = f.input :p_product_ref, as: :select, collection: PProductRef.all, :label => f.object.label_for(:p_product_ref) .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/p_articles/_p_article.html.haml b/app/views/admin/p_articles/_p_article.html.haml index 171a403..13e29ca 100644 --- a/app/views/admin/p_articles/_p_article.html.haml +++ b/app/views/admin/p_articles/_p_article.html.haml @@ -1,6 +1,29 @@ %tr#p_article_row{:id => p_article.id} -tr = {} + -tr[:p_product_ref_code] = capture do + %td + = p_article.p_product_ref.code + + + -tr[:color] = capture do + %td + = p_article.p_product_ref.p_product_color.color + + -tr[:p_product_ref] = capture do + %td + = p_article.p_product_ref.p_product.name + \- + = p_article.p_product_ref.ct_sub_name + \- + = p_article.p_product_ref.p_product_color.name + + -tr[:p_article_serial_nums] = capture do + %td + - p_article.p_article_serial_nums.each do |sn| + = sn.p_serial_num_type.name + " : " + sn.p_serial_num_value.value + + -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, p_article], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true @@ -13,4 +36,4 @@ - \ No newline at end of file + diff --git a/app/views/admin/p_serial_num_values/_form.html.haml b/app/views/admin/p_serial_num_values/_form.html.haml index 7ad0960..1872e5e 100644 --- a/app/views/admin/p_serial_num_values/_form.html.haml +++ b/app/views/admin/p_serial_num_values/_form.html.haml @@ -1,12 +1,12 @@ -=semantic_form_for [:admin, @p_serial_num_value], :remote => true do |f| +/ =semantic_form_for [:admin, @p_serial_num_value], :remote => true do |f| + + +=f.inputs do + = f.input :value, :label => "Numéro" - .content - =f.inputs do - = f.input :value, :label => f.object.label_for(:value) - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + / .actions=f.submit "sauvegarder", :class => "btn btn-primary" +