p_product_ref_match
This commit is contained in:
parent
97f0ae99c5
commit
5a3cd4163b
@ -31,13 +31,20 @@ class Admin::ImportCsvsController < ApplicationController
|
||||
|
||||
end
|
||||
|
||||
def match_refs
|
||||
@price_documents = PriceDocument.joins(price_line_block: :price_lines).where({price_line_block: {price_lines: {p_product_ref: nil}}}).distinct
|
||||
redirect_to :action => :index if @price_documents.empty?
|
||||
end
|
||||
|
||||
def charge
|
||||
@import_csv = ImportCsv.find(params[:id])
|
||||
@import_csv.load
|
||||
|
||||
redirect_to :action => :index
|
||||
# redirect_to :action => :index
|
||||
redirect_to match_refs_admin_import_csvs_path
|
||||
end
|
||||
|
||||
|
||||
def new
|
||||
@import_csv = ImportCsv.new(:parent_id => params[:parent_id])
|
||||
if @import_csv.parent
|
||||
|
@ -72,7 +72,7 @@ class Admin::PProductsController < ApplicationController
|
||||
|
||||
|
||||
@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_refs = @p_product.p_product_refs.build
|
||||
@p_product_ref_specs = @p_product_refs.p_product_ref_specs.build
|
||||
|
@ -360,6 +360,8 @@ class Admin::PriceDocumentsController < ApplicationController
|
||||
redirect_to [:admin, PriceDocument.find(@price_document.doc_ref_id)]
|
||||
elsif @price_document.ref_element
|
||||
redirect_to [:admin, @price_document.ref_element]
|
||||
elsif @price_document.label == "Catalogue fournisseur"
|
||||
redirect_to match_refs_admin_import_csvs_path
|
||||
else
|
||||
redirect_to [:admin, @price_document]
|
||||
end
|
||||
|
@ -127,6 +127,7 @@ class ApplicationController < ActionController::Base
|
||||
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, :import_csvs, "Import Excel"
|
||||
set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csv_match_refs, "Rapprochement références", match_refs_admin_import_csvs_path
|
||||
end
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@ class PProductRef < ApplicationRecord
|
||||
|
||||
has_many :p_customer_product_prices, :dependent => :destroy
|
||||
accepts_nested_attributes_for :p_customer_product_prices, allow_destroy: true
|
||||
has_many :p_fournisseur_refs
|
||||
|
||||
scope :enableds, -> {where(:enabled => true)}
|
||||
|
||||
|
@ -14,6 +14,7 @@ class PriceLine < ApplicationRecord
|
||||
default_scope { order('position ASC') }
|
||||
|
||||
validates :p_product_ref_id, :presence => true, :if => :p_product_ref_needed?
|
||||
validates :p_product_id, :presence => true, :if => :p_product_needed?
|
||||
validates :qte, :presence => true
|
||||
|
||||
|
||||
@ -21,6 +22,7 @@ class PriceLine < ApplicationRecord
|
||||
|
||||
has_many :line_stocks
|
||||
|
||||
after_update :memorize_p_fournisseur_ref, if: :p_fournisseur_ref_is_memorizable?
|
||||
|
||||
acts_as_sorting :fields => {
|
||||
:ref => {:name => "Ref", :reorder => true},
|
||||
@ -171,6 +173,12 @@ class PriceLine < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def p_product_needed?
|
||||
if !self.ct_title? and !self.imported
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def personalised_archive
|
||||
|
||||
end
|
||||
@ -617,6 +625,12 @@ class PriceLine < ApplicationRecord
|
||||
return [asap, non_asap]
|
||||
end
|
||||
|
||||
def p_fournisseur_ref_is_memorizable?
|
||||
self.p_product_ref.present? && self.imported? && PFournisseurRef.where(p_fournisseur: self.p_fournisseur, ref: self.ct_ref, label: self.ct_title).empty?
|
||||
end
|
||||
|
||||
def memorize_p_fournisseur_ref
|
||||
PFournisseurRef.create(p_fournisseur: self.p_fournisseur, p_product_ref: self.p_product_ref, ref: self.ct_ref, label: self.ct_title)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -23,7 +23,7 @@ class PriceLineBlock < ApplicationRecord
|
||||
|
||||
belongs_to :p_payment_type
|
||||
|
||||
PURCHASE_BLOCKS = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat"]
|
||||
PURCHASE_BLOCKS = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat", "Catalogue fournisseur"]
|
||||
|
||||
SALE_BLOCKS = ["Demande de commande", "Bon de commande", "Devis", "Bon de livraison", "Facture", "Avoir"]
|
||||
|
||||
|
26
app/views/admin/import_csvs/match_refs.html.haml
Normal file
26
app/views/admin/import_csvs/match_refs.html.haml
Normal file
@ -0,0 +1,26 @@
|
||||
:javascript
|
||||
var p_product_refs_url = "#{admin_p_product_refs_path(:manager => true)}"
|
||||
.qi_row
|
||||
%h1 Rapprochement de références produits
|
||||
|
||||
-@price_documents.each do |price_document|
|
||||
%br
|
||||
.qi_pannel.qi_plain.padding.mt-4
|
||||
=semantic_form_for [:admin, price_document] do |f|
|
||||
=f.semantic_fields_for :price_line_block do |f|
|
||||
%h2= "Import catalogue : " + f.object.p_fournisseur.name
|
||||
%div{:style=>"padding:0 30px;"}
|
||||
.row.qi_field_wrapper
|
||||
%table{:style => "width:100%;border-collapse:separate;"}
|
||||
%thead
|
||||
%tr
|
||||
%th
|
||||
%th Référence Produit Arcom
|
||||
%th Créer une référence
|
||||
%th Référence fournisseur
|
||||
%th
|
||||
%tbody.price_lines_form
|
||||
=f.semantic_fields_for :price_lines do |form|
|
||||
-if form.object.p_product_ref.nil?
|
||||
=render :partial => "admin/price_lines/form_match_refs", :locals => {:form => form}
|
||||
=f.submit "Valider", class: "btn btn-primary mt-3"
|
93
app/views/admin/price_lines/_form_match_refs.html.haml
Normal file
93
app/views/admin/price_lines/_form_match_refs.html.haml
Normal file
@ -0,0 +1,93 @@
|
||||
%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"}
|
||||
|
||||
|
||||
%td{:style => "width: 30px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )}
|
||||
.take.text-center.px-2
|
||||
=ic :arrows
|
||||
%td{:style => "white-space: nowrap; width: 400px;"}
|
||||
|
||||
|
||||
|
||||
.input-group
|
||||
%input.p_product_ref_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.member_label}" if form.object.p_product_ref), :class => "p_product_ref_name"}
|
||||
=form.hidden_field :p_product_ref_id, :class => "p_product_ref_id"
|
||||
|
||||
|
||||
|
||||
|
||||
.input-group-append
|
||||
=link_to "#", class: "btn btn-dark",:onclick => "key=genRanHex(12);select_product_from_manager(key);$(this).closest('tr').find('.p_product_ref_id').attr('id', 'p_product_ref_id_'+key);$(this).closest('tr').find('.p_product_ref_name').attr('id', 'p_product_ref_name_'+key);$(this).closest('tr').find('.p_product_ref_qte').attr('id', 'p_product_ref_qte_'+key);return false;" do
|
||||
=ic(:search)
|
||||
|
||||
|
||||
%td.text-center{style: "width: 80px;"}
|
||||
%span=link_to ic(:"plus"), new_admin_p_product_path(p_fournisseur_ref_label: form.object.title)
|
||||
|
||||
|
||||
|
||||
%td.pl-2
|
||||
=form.object.title
|
||||
%td.text-center{style: "width: 30px;"}
|
||||
%span.destroy=link_to_remove_fields ic(:"trash-o"), form
|
||||
|
||||
|
||||
=qi_js_field(form, :price_line, :tva_account_value, :hidden => true)
|
||||
|
||||
= form.hidden_field :position, :class => "price_line_position_input"
|
||||
|
||||
|
||||
:javascript
|
||||
$('.p_product_ref_autocomplete_input').focus()
|
||||
$( function() {
|
||||
$('.p_product_ref_autocomplete_input').autocomplete({
|
||||
source: function( request, response ) {
|
||||
$.ajax( {
|
||||
url: "/admin/p_product_refs/autocomplete.json",
|
||||
dataType: "json",
|
||||
data: {
|
||||
search: request.term,
|
||||
p_customer_id: $(".p_customer_id").val()
|
||||
},
|
||||
success: function(data){
|
||||
arr = jQuery.map( data, function( item ) {
|
||||
return {
|
||||
label: item.member_label,
|
||||
value: item.member_label,
|
||||
id: item.id
|
||||
}
|
||||
});
|
||||
response(arr)
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 2,
|
||||
select: function( event, ui ) {
|
||||
$(this).next(".p_product_ref_id").val(ui.item.id)
|
||||
form = $(this).closest(".price_line_form")
|
||||
$.ajax( {
|
||||
url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json",
|
||||
dataType: "json",
|
||||
data: {
|
||||
type: "price",
|
||||
qte: form.find(".input_price_line_qte").val(),
|
||||
p_customer_id: $(".p_customer_id").val()
|
||||
},
|
||||
success: function (data) {
|
||||
form.find(".input_price_line_price_u_ht").val(data.price);
|
||||
form.find(".input_price_line_tva_account_id").val(data.tva_account_id);
|
||||
form.find(".input_price_line_tva_account_value").val(data.tva_account_value);
|
||||
form.find(".input_price_line_weight_u").val(data.weight);
|
||||
}
|
||||
});
|
||||
//return false
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
:scss
|
||||
.price_line_form{
|
||||
.form-group{
|
||||
margin-bottom:0;}
|
||||
|
||||
}
|
@ -456,6 +456,9 @@ Rails.application.routes.draw do
|
||||
|
||||
namespace :admin do
|
||||
resources :import_csvs do
|
||||
collection do
|
||||
get :match_refs
|
||||
end
|
||||
member do
|
||||
get :charge
|
||||
end
|
||||
|
Reference in New Issue
Block a user