add new p_product_ref after import
This commit is contained in:
parent
1fc9e696bc
commit
296e4aef5f
@ -92,4 +92,21 @@ class Admin::ImportCsvsController < ApplicationController
|
|||||||
@import_csv.destroy
|
@import_csv.destroy
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def temp_p_product
|
||||||
|
dev_mode = false
|
||||||
|
if dev_mode
|
||||||
|
@p_product_ref = PProductRef.last #DEV mode only
|
||||||
|
@price_line = PriceLine.find(params[:price_line_id])
|
||||||
|
|
||||||
|
@p_product_ref.ct_price_ht = @price_line.ct_u_price_ht #DEV ode onmy
|
||||||
|
@p_product_ref.p_product_ref_specs.build
|
||||||
|
else
|
||||||
|
if params[:price_line_id]
|
||||||
|
@price_line = PriceLine.find(params[:price_line_id])
|
||||||
|
@p_product_ref = PProductRef.find_or_create_by(p_product: PProduct.find_by(name: "--> Selectioner un produit <--"), ct_sub_name: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht)
|
||||||
|
@p_product_ref.p_product_ref_specs.build
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
|
|
||||||
class Admin::PProductRefsController < ApplicationController
|
class Admin::PProductRefsController < ApplicationController
|
||||||
|
include ActionView::RecordIdentifier # adds `dom_id`
|
||||||
|
|
||||||
layout "admin"
|
layout "admin"
|
||||||
before_action :auth_admin
|
before_action :auth_admin
|
||||||
|
|
||||||
@ -102,12 +104,14 @@ class Admin::PProductRefsController < ApplicationController
|
|||||||
|
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
||||||
@p_product_ref = PProductRef.find(params[:id])
|
@p_product_ref = PProductRef.find(params[:id])
|
||||||
|
|
||||||
|
|
||||||
if @p_product_ref.update_attributes(params.require(:p_product_ref).permit!)
|
if @p_product_ref.update_attributes(params.require(:p_product_ref).permit!)
|
||||||
|
if params[:update_price_line_id]
|
||||||
|
@price_line = PriceLine.find(params[:update_price_line_id])
|
||||||
|
@price_line.update(p_product_ref: @p_product_ref)
|
||||||
|
end
|
||||||
|
# redirect_to admin_p_products_path(@p_product_ref.p_product, anchor: dom_id(@p_product_ref))
|
||||||
else
|
else
|
||||||
|
|
||||||
render action: "edit"
|
render action: "edit"
|
||||||
|
@ -72,9 +72,9 @@ class Admin::PProductsController < ApplicationController
|
|||||||
|
|
||||||
|
|
||||||
@p_product = PProduct.new #(:p_customer_cat_ids => [3])
|
@p_product = PProduct.new #(:p_customer_cat_ids => [3])
|
||||||
@p_product.name = params[:p_fournisseur_ref_label] if params[:p_fournisseur_ref_label]
|
|
||||||
# @p_product.p_product_refs << PProductRef.new
|
# @p_product.p_product_refs << PProductRef.new
|
||||||
@p_product_refs = @p_product.p_product_refs.build
|
fournisseur_label = params[:fournisseur_label] if params[:fournisseur_label]
|
||||||
|
@p_product_refs = @p_product.p_product_refs.build(ct_sub_name: fournisseur_label)
|
||||||
@p_product_ref_specs = @p_product_refs.p_product_ref_specs.build
|
@p_product_ref_specs = @p_product_refs.p_product_ref_specs.build
|
||||||
@p_spec_type = @p_product_ref_specs.build_p_spec_type
|
@p_spec_type = @p_product_ref_specs.build_p_spec_type
|
||||||
@p_spec_value = @p_product_ref_specs.build_p_spec_value
|
@p_spec_value = @p_product_ref_specs.build_p_spec_value
|
||||||
|
@ -33,9 +33,8 @@ class PProduct < ApplicationRecord
|
|||||||
belongs_to :p_product_cat
|
belongs_to :p_product_cat
|
||||||
belongs_to :s_brand
|
belongs_to :s_brand
|
||||||
|
|
||||||
validates :name, :presence => true
|
validates :name, :presence => true, exclusion: { in: ["--> Selectioner un produit <--"], message: "Selectioner un produit avant de valider" }
|
||||||
validates :code, :presence => true, :uniqueness => true
|
validates :code, :presence => true, :uniqueness => true, exclusion: { in: ["--> Indiquer un code produit <--"], message: "Indiquer un code produit avant de valider" }
|
||||||
|
|
||||||
|
|
||||||
has_many :tvable_tva_rates, :as => :tvable
|
has_many :tvable_tva_rates, :as => :tvable
|
||||||
has_many :tva_rates, :through => :tvable_tva_rates
|
has_many :tva_rates, :through => :tvable_tva_rates
|
||||||
|
@ -15,7 +15,7 @@ class PProductRef < ApplicationRecord
|
|||||||
accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true
|
accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true
|
||||||
|
|
||||||
has_many :p_product_ref_specs
|
has_many :p_product_ref_specs
|
||||||
accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true
|
accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true, reject_if: :all_blank
|
||||||
|
|
||||||
#validates :ct_price_ht, :presence => true
|
#validates :ct_price_ht, :presence => true
|
||||||
validate :ean, :is_integer
|
validate :ean, :is_integer
|
||||||
@ -88,7 +88,8 @@ class PProductRef < ApplicationRecord
|
|||||||
self.p_product.p_product_cat_id
|
self.p_product.p_product_cat_id
|
||||||
end
|
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)
|
||||||
|
QI_DYNAMICS = %w(name code p_product_cat_id cat_name) #sub_cat_names removed
|
||||||
|
|
||||||
eval(QI_DYNAMICS_CORE)
|
eval(QI_DYNAMICS_CORE)
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ class PProductRefSpec < ApplicationRecord
|
|||||||
|
|
||||||
accepts_nested_attributes_for :p_spec_type, :p_spec_value
|
accepts_nested_attributes_for :p_spec_type, :p_spec_value
|
||||||
|
|
||||||
|
validates :p_spec_type_id, :p_spec_value_id, presence: true
|
||||||
|
|
||||||
acts_as_sorting :fields => {
|
acts_as_sorting :fields => {
|
||||||
:id => {:name => "ID"},
|
:id => {:name => "ID"},
|
||||||
:p_product_ref => {:name => "Référence produit", :reorder => true},
|
:p_product_ref => {:name => "Référence produit", :reorder => true},
|
||||||
|
89
app/views/admin/import_csvs/_form_temp_p_product.html.haml
Normal file
89
app/views/admin/import_csvs/_form_temp_p_product.html.haml
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
=semantic_form_for [:admin, @p_product_ref], remote: true do |form|
|
||||||
|
=hidden_field_tag :update_price_line_id, @price_line.id
|
||||||
|
.content
|
||||||
|
.qi_row.field
|
||||||
|
.padding
|
||||||
|
|
||||||
|
%h1 Ajouter une références
|
||||||
|
%table.form-table
|
||||||
|
%tr
|
||||||
|
%td{colspan: 3}
|
||||||
|
%label Selectionner le produit parent
|
||||||
|
.input-group
|
||||||
|
%input.p_product_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :class => "p_product_name"}
|
||||||
|
=form.hidden_field :p_product_id, :class => "p_product_id"
|
||||||
|
|
||||||
|
=link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.ct_sub_name)
|
||||||
|
|
||||||
|
%tr
|
||||||
|
%td{:colspan => 3}
|
||||||
|
%input.form-control{type: "text", placeholder: @p_product_ref.ct_sub_name, "aria-label" => "Disabled input example", disabled: true}
|
||||||
|
=#form.input :ct_sub_name, label: "Label fournisseur", input_html: {disabled: true}
|
||||||
|
|
||||||
|
%tr
|
||||||
|
%td{:colspan => 3}
|
||||||
|
= form.input :ct_sub_name, :label => "Désignation ARCOM :"
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
= form.input :ref, :label => "Réf int. :"
|
||||||
|
|
||||||
|
%td
|
||||||
|
= form.input :ct_price_ht, :label => "Prix vente HT :"
|
||||||
|
|
||||||
|
%td
|
||||||
|
=form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true, input_html: {class: "custom-select"}
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
=form.input :ct_sorecop, :label => "Sorecop personalisée :"
|
||||||
|
%td
|
||||||
|
=form.input :sorecop_comment, :label => "Type de Sorecop :"
|
||||||
|
%td
|
||||||
|
=form.input :ct_deee, :label => "DEEE personalisée :"
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
=form.input :ean
|
||||||
|
|
||||||
|
%td{:colspan => 2}
|
||||||
|
= form.input :description, :label => "Désignation longue :" , :input_html => {rows: 1}
|
||||||
|
|
||||||
|
%tr
|
||||||
|
%td{:colspan => 3}
|
||||||
|
.qi_pannel.qi_plain.padding
|
||||||
|
.p_product_ref_specs_form
|
||||||
|
= form.semantic_fields_for :p_product_ref_specs do |f|
|
||||||
|
=render :partial => "admin/p_product_ref_specs/form", :locals => {:form => f}
|
||||||
|
%p= link_to_add_fields "Ajouter une spec", form, :p_product_ref_specs
|
||||||
|
|
||||||
|
.actions=form.submit "sauvegarder", :class => "btn btn-primary"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:javascript
|
||||||
|
$('.p_product_autocomplete_input').focus()
|
||||||
|
$( function() {
|
||||||
|
$('.p_product_autocomplete_input').autocomplete({
|
||||||
|
source: function( request, response ) {
|
||||||
|
$.ajax( {
|
||||||
|
url: "/admin/p_products/autocomplete.json",
|
||||||
|
dataType: "json",
|
||||||
|
data: {
|
||||||
|
search: request.term,
|
||||||
|
},
|
||||||
|
success: function(data){
|
||||||
|
arr = jQuery.map( data, function( item ) {
|
||||||
|
return {
|
||||||
|
label: item.name,
|
||||||
|
value: item.name,
|
||||||
|
id: item.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
response(arr)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
minLength: 2,
|
||||||
|
select: function( event, ui ) {
|
||||||
|
$(this).next(".p_product_id").val(ui.item.id)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
1
app/views/admin/import_csvs/temp_p_product.js.erb
Normal file
1
app/views/admin/import_csvs/temp_p_product.js.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
show_pane_hover("<%= escape_javascript(render(:partial => "form_temp_p_product"))%>",700,900);
|
@ -15,15 +15,15 @@
|
|||||||
%table
|
%table
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
%h4 spec :
|
%h4 Specs :
|
||||||
|
%tr
|
||||||
%td
|
%td
|
||||||
-#form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type
|
-#form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type
|
||||||
-#form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value
|
-#form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value
|
||||||
|
|
||||||
= form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType.all, :include_blank => false
|
= form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType.all, :include_blank => true,input_html: {class: "custom-select"}
|
||||||
%td
|
%td
|
||||||
= form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => false, :member_label => :member_label
|
= form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => true, :member_label => :member_label, input_html: {class: "custom-select"}
|
||||||
|
|
||||||
|
|
||||||
=#form.inputs do
|
=#form.inputs do
|
||||||
|
@ -1,2 +1,8 @@
|
|||||||
$('#p_product_ref_row_<%= @p_product_ref.id %>').replaceWith("<%= escape_javascript(render(@p_product_ref))%>");
|
$('#p_product_ref_row_<%= @p_product_ref.id %>').replaceWith("<%= escape_javascript(render(@p_product_ref))%>");
|
||||||
close_pane_hover();
|
|
||||||
|
if ($('#<%= dom_id(@price_line) %>').parents('.qi_pannel.qi_plain').find('tbody').find('tr').length === 1) {
|
||||||
|
$('#<%= dom_id(@price_line) %>').parents('.qi_pannel.qi_plain').remove()
|
||||||
|
}
|
||||||
|
$('#<%= dom_id(@price_line) %>').remove();
|
||||||
|
|
||||||
|
close_pane_hover();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"}
|
%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;", id: dom_id(form.object)}
|
||||||
|
|
||||||
|
|
||||||
%td{:style => "width: 30px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )}
|
%td{:style => "width: 30px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )}
|
||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
%td.text-center{style: "width: 80px;"}
|
%td.text-center{style: "width: 80px;"}
|
||||||
%span=link_to ic(:"plus"), new_admin_p_product_path(p_fournisseur_ref_label: form.object.title)
|
%span=link_to ic(:"plus"), temp_p_product_admin_import_csvs_path(price_line_id: form.object.id), remote: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -458,6 +458,7 @@ Rails.application.routes.draw do
|
|||||||
resources :import_csvs do
|
resources :import_csvs do
|
||||||
collection do
|
collection do
|
||||||
get :match_refs
|
get :match_refs
|
||||||
|
get :temp_p_product
|
||||||
end
|
end
|
||||||
member do
|
member do
|
||||||
get :charge
|
get :charge
|
||||||
|
Reference in New Issue
Block a user